-
-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathrun.ts
More file actions
292 lines (252 loc) · 8.19 KB
/
run.ts
File metadata and controls
292 lines (252 loc) · 8.19 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import { ERROR_NO_VALID_SUBCOMMAND_FORMAT } from "../common/constants";
import { IErrors, IHostInfo } from "../common/declarations";
import { cache } from "../common/decorators";
import { ICommand, ICommandParameter } from "../common/definitions/commands";
import {
IKeyCommandHelper,
IKeyCommandPlatform,
} from "../common/definitions/key-commands";
import { IInjector } from "../common/definitions/yok";
import { hasValidAndroidSigning } from "../common/helpers";
import { injector } from "../common/yok";
import {
ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE,
ANDROID_RELEASE_BUILD_ERROR_MESSAGE,
} from "../constants";
import {
IOpener,
IOptions,
IPlatformValidationService,
} from "../declarations";
import { IMigrateController } from "../definitions/migrate";
import { IProjectData, IProjectDataService } from "../definitions/project";
import { IBuildController, IBuildDataService } from "../definitions/build";
export class RunCommandBase implements ICommand {
private liveSyncCommandHelperAdditionalOptions: ILiveSyncCommandHelperAdditionalOptions =
<ILiveSyncCommandHelperAdditionalOptions>{};
public platform: string;
constructor(
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $errors: IErrors,
private $hostInfo: IHostInfo,
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
private $migrateController: IMigrateController,
private $options: IOptions,
private $projectData: IProjectData,
private $keyCommandHelper: IKeyCommandHelper
) {}
public allowedParameters: ICommandParameter[] = [];
public async execute(args: string[]): Promise<void> {
await this.$liveSyncCommandHelper.executeCommandLiveSync(
this.platform,
this.liveSyncCommandHelperAdditionalOptions
);
if (process.env.NS_IS_INTERACTIVE) {
this.$keyCommandHelper.attachKeyCommands(
this.platform as IKeyCommandPlatform,
"run"
);
}
}
public async canExecute(args: string[]): Promise<boolean> {
if (args.length) {
this.$errors.failWithHelp(ERROR_NO_VALID_SUBCOMMAND_FORMAT, "run");
}
this.platform = args[0] || this.platform;
if (!this.platform && !this.$hostInfo.isDarwin) {
this.platform = this.$devicePlatformsConstants.Android;
}
this.$projectData.initializeProjectData();
const platforms = this.platform
? [this.platform]
: [
this.$devicePlatformsConstants.Android,
this.$devicePlatformsConstants.iOS,
];
if (!this.$options.force) {
await this.$migrateController.validate({
projectDir: this.$projectData.projectDir,
platforms,
});
}
await this.$liveSyncCommandHelper.validatePlatform(this.platform);
return true;
}
}
injector.registerCommand("run|*all", RunCommandBase);
export class RunIosCommand implements ICommand {
@cache()
protected 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(
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $errors: IErrors,
protected $injector: IInjector,
protected $options: IOptions,
protected $platformValidationService: IPlatformValidationService,
protected $projectDataService: IProjectDataService
) {}
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.$platformValidationService.isPlatformSupportedForOS(
this.platform,
projectData
)
) {
this.$errors.fail(
`Applications for platform ${this.platform} can not be built on this OS`
);
}
const result =
(await this.runCommand.canExecute(args)) &&
(await this.$platformValidationService.validateOptions(
this.$options.provision,
this.$options.teamId,
projectData,
this.platform.toLowerCase()
));
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 $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $errors: IErrors,
private $injector: IInjector,
private $options: IOptions,
private $platformValidationService: IPlatformValidationService,
private $projectData: IProjectData
) {}
public async execute(args: string[]): Promise<void> {
return this.runCommand.execute(args);
}
public async canExecute(args: string[]): Promise<boolean> {
await this.runCommand.canExecute(args);
if (
!this.$platformValidationService.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.aab) &&
!hasValidAndroidSigning(this.$options)
) {
if (this.$options.release) {
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
} else {
this.$errors.failWithHelp(ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE);
}
}
return this.$platformValidationService.validateOptions(
this.$options.provision,
this.$options.teamId,
this.$projectData,
this.$devicePlatformsConstants.Android.toLowerCase()
);
}
}
injector.registerCommand("run|android", RunAndroidCommand);
export class RunVisionOSCommand extends RunIosCommand {
public get platform(): string {
return this.$devicePlatformsConstants.visionOS;
}
constructor(
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $errors: IErrors,
protected $injector: IInjector,
protected $options: IOptions,
protected $platformValidationService: IPlatformValidationService,
protected $projectDataService: IProjectDataService
) {
super(
$devicePlatformsConstants,
$errors,
$injector,
$options,
$platformValidationService,
$projectDataService
);
}
}
injector.registerCommand("run|vision", RunVisionOSCommand);
injector.registerCommand("run|visionos", RunVisionOSCommand);
export class RunMacOSCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];
public get platform(): string {
return this.$devicePlatformsConstants.macOS || "macOS";
}
constructor(
private $buildController: IBuildController,
private $buildDataService: IBuildDataService,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $errors: IErrors,
private $migrateController: IMigrateController,
private $opener: IOpener,
private $options: IOptions,
private $platformValidationService: IPlatformValidationService,
private $projectDataService: IProjectDataService,
) {}
public async execute(args: string[]): Promise<void> {
const projectData = this.$projectDataService.getProjectData();
const buildData = this.$buildDataService.getBuildData(
projectData.projectDir,
this.platform.toLowerCase(),
this.$options,
);
const outputPath = await this.$buildController.prepareAndBuild(buildData);
await this.$opener.open(outputPath, projectData.projectName);
}
public async canExecute(args: string[]): Promise<boolean> {
const projectData = this.$projectDataService.getProjectData();
if (
!this.$platformValidationService.isPlatformSupportedForOS(
this.platform,
projectData,
)
) {
this.$errors.fail(
`Applications for platform ${this.platform} can not be built on this OS`,
);
}
if (!this.$options.force) {
await this.$migrateController.validate({
projectDir: projectData.projectDir,
platforms: [this.platform],
});
}
return this.$platformValidationService.validateOptions(
this.$options.provision,
this.$options.teamId,
projectData,
this.platform.toLowerCase(),
);
}
}
injector.registerCommand("run|macos", RunMacOSCommand);