-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathbuild.ts
169 lines (141 loc) · 6.22 KB
/
build.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, AndroidAppBundleMessages } from "../constants";
import { ValidatePlatformCommandBase } from "./command-base";
export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
constructor($options: IOptions,
protected $errors: IErrors,
$projectData: IProjectData,
$platformsData: IPlatformsData,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
$platformService: IPlatformService,
private $bundleValidatorHelper: IBundleValidatorHelper,
protected $logger: ILogger,
protected $workflowService: IWorkflowService) {
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
}
public async executeCore(args: string[]): Promise<string> {
await this.$workflowService.handleLegacyWorkflow({ projectDir: this.$projectData.projectDir, settings: this.$options, skipWarnings: true });
const platform = args[0].toLowerCase();
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
bundle: !!this.$options.bundle,
release: this.$options.release,
useHotModuleReload: this.$options.hmr
};
const platformInfo: IPreparePlatformInfo = {
platform,
appFilesUpdaterOptions,
platformTemplate: this.$options.platformTemplate,
projectData: this.$projectData,
config: this.$options,
env: this.$options.env
};
await this.$platformService.preparePlatform(platformInfo);
const buildConfig: IBuildConfig = {
buildForDevice: this.$options.forDevice,
iCloudContainerEnvironment: this.$options.iCloudContainerEnvironment,
projectDir: this.$options.path,
clean: this.$options.clean,
teamId: this.$options.teamId,
device: this.$options.device,
provision: this.$options.provision,
release: this.$options.release,
keyStoreAlias: this.$options.keyStoreAlias,
keyStorePath: this.$options.keyStorePath,
keyStoreAliasPassword: this.$options.keyStoreAliasPassword,
keyStorePassword: this.$options.keyStorePassword,
androidBundle: this.$options.aab
};
const outputPath = await this.$platformService.buildPlatform(platform, buildConfig, this.$projectData);
if (this.$options.copyTo) {
this.$platformService.copyLastOutput(platform, this.$options.copyTo, buildConfig, this.$projectData);
} else {
this.$logger.info(`The build result is located at: ${outputPath}`);
}
return outputPath;
}
protected validatePlatform(platform: string): void {
if (!this.$platformService.isPlatformSupportedForOS(platform, this.$projectData)) {
this.$errors.fail(`Applications for platform ${platform} can not be built on this OS`);
}
this.$bundleValidatorHelper.validate(this.$projectData);
}
protected async validateArgs(args: string[], platform: string): Promise<ICanExecuteCommandOutput> {
const canExecute = await this.validateArgsCore(args, platform);
return {
canExecute,
suppressCommandHelp: false
};
}
private async validateArgsCore(args: string[], platform: string): Promise<boolean> {
if (args.length !== 0) {
return false;
}
const result = await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
return result;
}
}
export class BuildIosCommand extends BuildCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [];
constructor(protected $options: IOptions,
$errors: IErrors,
$projectData: IProjectData,
$platformsData: IPlatformsData,
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
$platformService: IPlatformService,
$bundleValidatorHelper: IBundleValidatorHelper,
$logger: ILogger,
$workflowService: IWorkflowService) {
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger, $workflowService);
}
public async execute(args: string[]): Promise<void> {
await this.executeCore([this.$platformsData.availablePlatforms.iOS]);
}
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
const platform = this.$devicePlatformsConstants.iOS;
super.validatePlatform(platform);
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
if (result.canExecute) {
result = await super.validateArgs(args, platform);
}
return result;
}
}
$injector.registerCommand("build|ios", BuildIosCommand);
export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [];
constructor(protected $options: IOptions,
protected $errors: IErrors,
$projectData: IProjectData,
$platformsData: IPlatformsData,
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
$platformService: IPlatformService,
$bundleValidatorHelper: IBundleValidatorHelper,
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
protected $logger: ILogger,
$workflowService: IWorkflowService) {
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger, $workflowService);
}
public async execute(args: string[]): Promise<void> {
await this.executeCore([this.$platformsData.availablePlatforms.Android]);
if (this.$options.aab) {
this.$logger.info(AndroidAppBundleMessages.ANDROID_APP_BUNDLE_DOCS_MESSAGE);
if (this.$options.release) {
this.$logger.info(AndroidAppBundleMessages.ANDROID_APP_BUNDLE_PUBLISH_DOCS_MESSAGE);
}
}
}
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
const platform = this.$devicePlatformsConstants.Android;
super.validatePlatform(platform);
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
if (result.canExecute) {
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
}
result = await super.validateArgs(args, platform);
}
return result;
}
}
$injector.registerCommand("build|android", BuildAndroidCommand);