forked from NativeScript/nativescript-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-assets.ts
106 lines (96 loc) · 2.58 KB
/
generate-assets.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { IProjectData } from "../definitions/project";
import { IOptions, IAssetsGenerationService } from "../declarations";
import {
ICommand,
ICommandParameter,
IStringParameterBuilder,
} from "../common/definitions/commands";
import { IInjector } from "../common/definitions/yok";
import { injector } from "../common/yok";
export abstract class GenerateCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [
this.$stringParameterBuilder.createMandatoryParameter(
"You have to provide path to image to generate other images based on it."
),
];
constructor(
protected $options: IOptions,
protected $injector: IInjector,
protected $projectData: IProjectData,
protected $stringParameterBuilder: IStringParameterBuilder,
protected $assetsGenerationService: IAssetsGenerationService
) {
this.$projectData.initializeProjectData();
}
public async execute(args: string[]): Promise<void> {
const [imagePath] = args;
await this.generate(imagePath, this.$options.background);
}
protected abstract generate(
imagePath: string,
background?: string
): Promise<void>;
}
export class GenerateIconsCommand
extends GenerateCommandBase
implements ICommand {
constructor(
protected $options: IOptions,
$injector: IInjector,
protected $projectData: IProjectData,
protected $stringParameterBuilder: IStringParameterBuilder,
$assetsGenerationService: IAssetsGenerationService
) {
super(
$options,
$injector,
$projectData,
$stringParameterBuilder,
$assetsGenerationService
);
}
protected async generate(
imagePath: string,
background?: string
): Promise<void> {
await this.$assetsGenerationService.generateIcons({
imagePath,
background,
projectDir: this.$projectData.projectDir,
});
}
}
injector.registerCommand("resources|generate|icons", GenerateIconsCommand);
export class GenerateSplashScreensCommand
extends GenerateCommandBase
implements ICommand {
constructor(
protected $options: IOptions,
$injector: IInjector,
protected $projectData: IProjectData,
protected $stringParameterBuilder: IStringParameterBuilder,
$assetsGenerationService: IAssetsGenerationService
) {
super(
$options,
$injector,
$projectData,
$stringParameterBuilder,
$assetsGenerationService
);
}
protected async generate(
imagePath: string,
background?: string
): Promise<void> {
await this.$assetsGenerationService.generateSplashScreens({
imagePath,
background,
projectDir: this.$projectData.projectDir,
});
}
}
injector.registerCommand(
"resources|generate|splashes",
GenerateSplashScreensCommand
);