forked from NativeScript/nativescript-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.ts
132 lines (103 loc) · 5.02 KB
/
run.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
import { ERROR_NO_VALID_SUBCOMMAND_FORMAT } from "../common/constants";
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
import { cache } from "../common/decorators";
export class RunCommandBase implements ICommand {
private liveSyncCommandHelperAdditionalOptions: ILiveSyncCommandHelperAdditionalOptions = <ILiveSyncCommandHelperAdditionalOptions>{};
public platform: string;
constructor(
private $analyticsService: IAnalyticsService,
private $projectData: IProjectData,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $errors: IErrors,
private $hostInfo: IHostInfo,
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) { }
public allowedParameters: ICommandParameter[] = [];
public async execute(args: string[]): Promise<void> {
await this.$analyticsService.trackPreviewAppData(this.platform, this.$projectData.projectDir);
return this.$liveSyncCommandHelper.executeCommandLiveSync(this.platform, this.liveSyncCommandHelperAdditionalOptions);
}
public async canExecute(args: string[]): Promise<boolean> {
if (args.length) {
this.$errors.fail(ERROR_NO_VALID_SUBCOMMAND_FORMAT, "run");
}
this.$androidBundleValidatorHelper.validateNoAab();
this.$projectData.initializeProjectData();
this.platform = args[0] || this.platform;
if (!this.platform && !this.$hostInfo.isDarwin) {
this.platform = this.$devicePlatformsConstants.Android;
}
const validatePlatformOutput = await this.$liveSyncCommandHelper.validatePlatform(this.platform);
if (this.platform && validatePlatformOutput && validatePlatformOutput[this.platform.toLowerCase()]) {
const checkEnvironmentRequirementsOutput = validatePlatformOutput[this.platform.toLowerCase()].checkEnvironmentRequirementsOutput;
this.liveSyncCommandHelperAdditionalOptions.syncToPreviewApp = checkEnvironmentRequirementsOutput && checkEnvironmentRequirementsOutput.selectedOption === "Sync to Playground";
}
return true;
}
}
$injector.registerCommand("run|*all", RunCommandBase);
export class RunIosCommand implements ICommand {
@cache()
private get runCommand(): RunCommandBase {
const runCommand = this.$injector.resolve<RunCommandBase>(RunCommandBase);
runCommand.platform = this.platform;
return runCommand;
}
public allowedParameters: ICommandParameter[] = [];
public get platform(): string {
return this.$devicePlatformsConstants.iOS;
}
constructor(private $platformsData: IPlatformsData,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $errors: IErrors,
private $injector: IInjector,
private $platformService: IPlatformService,
private $projectDataService: IProjectDataService,
private $options: IOptions) {
}
public async execute(args: string[]): Promise<void> {
return this.runCommand.execute(args);
}
public async canExecute(args: string[]): Promise<boolean> {
const projectData = this.$projectDataService.getProjectData();
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, projectData)) {
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
}
const result = await this.runCommand.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, projectData, this.$platformsData.availablePlatforms.iOS);
return result;
}
}
$injector.registerCommand("run|ios", RunIosCommand);
export class RunAndroidCommand implements ICommand {
@cache()
private get runCommand(): RunCommandBase {
const runCommand = this.$injector.resolve<RunCommandBase>(RunCommandBase);
runCommand.platform = this.platform;
return runCommand;
}
public allowedParameters: ICommandParameter[] = [];
public get platform(): string {
return this.$devicePlatformsConstants.Android;
}
constructor(private $platformsData: IPlatformsData,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $errors: IErrors,
private $injector: IInjector,
private $platformService: IPlatformService,
private $projectData: IProjectData,
private $options: IOptions) { }
public execute(args: string[]): Promise<void> {
return this.runCommand.execute(args);
}
public async canExecute(args: string[]): Promise<boolean> {
await this.runCommand.canExecute(args);
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.Android, this.$projectData)) {
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.Android} can not be built on this OS`);
}
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
}
return this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.Android);
}
}
$injector.registerCommand("run|android", RunAndroidCommand);