Skip to content

Commit fb47b68

Browse files
committed
refactor: refactor platform add, platform prepare and platform build workflows
1 parent 89c5f6c commit fb47b68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2639
-2593
lines changed

.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"program": "${workspaceRoot}/lib/nativescript-cli.js",
1616

1717
// example commands
18-
"args": [ "run", "ios", "--path", "${workspaceRoot}/scratch/webpackApp", "--bundle"]
18+
"args": [ "build", "ios", "--path", "${workspaceRoot}/scratch/webpackApp", "--bundle"]
1919
// "args": [ "test", "android", "--justlaunch"]
2020
// "args": [ "platform", "add", "android@1.3.0", "--path", "cliapp"]
2121
// "args": [ "platform", "remove", "android", "--path", "cliapp"]

lib/bootstrap.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,18 @@ $injector.require("tnsModulesService", "./services/tns-modules-service");
3434

3535
$injector.require("platformsData", "./platforms-data");
3636
$injector.require("platformService", "./services/platform-service");
37-
$injector.require("preparePlatformJSService", "./services/prepare-platform-js-service");
38-
$injector.require("preparePlatformNativeService", "./services/prepare-platform-native-service");
37+
$injector.require("platformJSService", "./services/prepare-platform-js-service");
38+
$injector.require("platformNativeService", "./services/prepare-platform-native-service");
39+
$injector.require("platformAddService", "./services/platform/platform-add-service");
40+
$injector.require("platformBuildService", "./services/platform/platform-build-service");
41+
$injector.require("platformValidationService", "./services/platform/platform-validation-service");
42+
$injector.require("platformCommandsService", "./services/platform/platform-commands-service");
43+
44+
$injector.require("platformWorkflowService", "./services/workflow/platform-workflow-service");
45+
46+
$injector.require("platformWorkflowDataFactory", "./factory/platform-workflow-data-factory");
47+
48+
$injector.require("buildArtefactsService", "./services/build-artefacts-service");
3949

4050
$injector.require("debugDataService", "./services/debug-data-service");
4151
$injector.requirePublicClass("debugService", "./services/debug-service");
@@ -47,8 +57,6 @@ $injector.requirePublic("analyticsSettingsService", "./services/analytics-settin
4757
$injector.require("analyticsService", "./services/analytics/analytics-service");
4858
$injector.require("googleAnalyticsProvider", "./services/analytics/google-analytics-provider");
4959

50-
$injector.require("emulatorSettingsService", "./services/emulator-settings-service");
51-
5260
$injector.require("platformCommandParameter", "./platform-command-param");
5361
$injector.requireCommand("create", "./commands/create-project");
5462
$injector.requireCommand("generate", "./commands/generate");
@@ -66,8 +74,6 @@ $injector.requireCommand("debug|ios", "./commands/debug");
6674
$injector.requireCommand("debug|android", "./commands/debug");
6775

6876
$injector.requireCommand("prepare", "./commands/prepare");
69-
$injector.requireCommand("clean-app|ios", "./commands/clean-app");
70-
$injector.requireCommand("clean-app|android", "./commands/clean-app");
7177
$injector.requireCommand("build|ios", "./commands/build");
7278
$injector.requireCommand("build|android", "./commands/build");
7379
$injector.requireCommand("deploy", "./commands/deploy");

lib/commands/add-platform.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ export class AddPlatformCommand extends ValidatePlatformCommandBase implements I
44
public allowedParameters: ICommandParameter[] = [];
55

66
constructor($options: IOptions,
7-
$platformService: IPlatformService,
7+
private $platformCommandsService: IPlatformCommandsService,
8+
$platformValidationService: IPlatformValidationService,
89
$projectData: IProjectData,
910
$platformsData: IPlatformsData,
1011
private $errors: IErrors) {
11-
super($options, $platformsData, $platformService, $projectData);
12+
super($options, $platformsData, $platformValidationService, $projectData);
1213
this.$projectData.initializeProjectData();
1314
}
1415

1516
public async execute(args: string[]): Promise<void> {
16-
await this.$platformService.addPlatforms(args, this.$projectData, this.$options, this.$options.frameworkPath);
17+
await this.$platformCommandsService.addPlatforms(args, this.$projectData, this.$options.frameworkPath);
1718
}
1819

1920
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
@@ -23,9 +24,9 @@ export class AddPlatformCommand extends ValidatePlatformCommandBase implements I
2324

2425
let canExecute = true;
2526
for (const arg of args) {
26-
this.$platformService.validatePlatform(arg, this.$projectData);
27+
this.$platformValidationService.validatePlatform(arg, this.$projectData);
2728

28-
if (!this.$platformService.isPlatformSupportedForOS(arg, this.$projectData)) {
29+
if (!this.$platformValidationService.isPlatformSupportedForOS(arg, this.$projectData)) {
2930
this.$errors.fail(`Applications for platform ${arg} can not be built on this OS`);
3031
}
3132

lib/commands/appstore-list.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ export class ListiOSApps implements ICommand {
99
private $logger: ILogger,
1010
private $projectData: IProjectData,
1111
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
12-
private $platformService: IPlatformService,
12+
private $platformValidationService: IPlatformValidationService,
1313
private $errors: IErrors,
1414
private $prompter: IPrompter) {
1515
this.$projectData.initializeProjectData();
1616
}
1717

1818
public async execute(args: string[]): Promise<void> {
19-
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
19+
if (!this.$platformValidationService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
2020
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
2121
}
2222

lib/commands/appstore-upload.ts

+12-23
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export class PublishIOS implements ICommand {
1313
private $options: IOptions,
1414
private $prompter: IPrompter,
1515
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
16+
private $platformValidationService: IPlatformValidationService,
17+
private $platformBuildService: IPlatformBuildService,
1618
private $xcodebuildService: IXcodebuildService) {
1719
this.$projectData.initializeProjectData();
1820
}
@@ -55,21 +57,10 @@ export class PublishIOS implements ICommand {
5557
if (!ipaFilePath) {
5658
const platform = this.$devicePlatformsConstants.iOS;
5759
// No .ipa path provided, build .ipa on out own.
58-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
59-
bundle: !!this.$options.bundle,
60+
const preparePlatformData: IPreparePlatformData = {
6061
release: this.$options.release,
61-
useHotModuleReload: false
62-
};
63-
const platformInfo: IPreparePlatformInfo = {
64-
platform,
65-
appFilesUpdaterOptions,
66-
projectData: this.$projectData,
67-
config: this.$options,
62+
useHotModuleReload: false,
6863
env: this.$options.env,
69-
webpackCompilerConfig: {
70-
watch: false,
71-
env: this.$options.env
72-
}
7364
};
7465
const buildConfig: IBuildConfig = {
7566
projectDir: this.$options.path,
@@ -83,22 +74,20 @@ export class PublishIOS implements ICommand {
8374
codeSignIdentity
8475
};
8576

77+
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
78+
8679
if (mobileProvisionIdentifier || codeSignIdentity) {
8780
this.$logger.info("Building .ipa with the selected mobile provision and/or certificate.");
8881
// This is not very correct as if we build multiple targets we will try to sign all of them using the signing identity here.
89-
await this.$platformService.preparePlatform(platformInfo);
90-
await this.$platformService.buildPlatform(platform, buildConfig, this.$projectData);
82+
await this.$platformService.preparePlatform(platformData, this.$projectData, preparePlatformData);
83+
await this.$platformBuildService.buildPlatform(platformData, this.$projectData, buildConfig);
9184
ipaFilePath = this.$platformService.lastOutputPath(platform, buildConfig, this.$projectData);
9285
} else {
9386
this.$logger.info("No .ipa, mobile provision or certificate set. Perfect! Now we'll build .xcarchive and let Xcode pick the distribution certificate and provisioning profile for you when exporting .ipa for AppStore submission.");
94-
await this.$platformService.preparePlatform(platformInfo);
95-
96-
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
97-
98-
const exportPath = await this.$xcodebuildService.buildForAppStore(platformData, this.$projectData, buildConfig);
99-
this.$logger.info("Export at: " + exportPath);
87+
await this.$platformService.preparePlatform(platformData, this.$projectData, preparePlatformData);
10088

101-
ipaFilePath = exportPath;
89+
ipaFilePath = await this.$xcodebuildService.buildForAppStore(platformData, this.$projectData, buildConfig);
90+
this.$logger.info(`Export at: ${ipaFilePath}`);
10291
}
10392
}
10493

@@ -111,7 +100,7 @@ export class PublishIOS implements ICommand {
111100
}
112101

113102
public async canExecute(args: string[]): Promise<boolean> {
114-
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
103+
if (!this.$platformValidationService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
115104
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
116105
}
117106

lib/commands/build.ts

+17-32
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,18 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
77
$projectData: IProjectData,
88
$platformsData: IPlatformsData,
99
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
10-
$platformService: IPlatformService,
10+
protected $platformWorkflowDataFactory: IPlatformWorkflowDataFactory,
11+
private $platformWorkflowService: IPlatformWorkflowService,
12+
$platformValidationService: IPlatformValidationService,
1113
private $bundleValidatorHelper: IBundleValidatorHelper,
1214
protected $logger: ILogger) {
13-
super($options, $platformsData, $platformService, $projectData);
15+
super($options, $platformsData, $platformValidationService, $projectData);
1416
this.$projectData.initializeProjectData();
1517
}
1618

1719
public async executeCore(args: string[]): Promise<string> {
1820
const platform = args[0].toLowerCase();
19-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
20-
bundle: !!this.$options.bundle,
21-
release: this.$options.release,
22-
useHotModuleReload: this.$options.hmr
23-
};
24-
const platformInfo: IPreparePlatformInfo = {
25-
platform,
26-
appFilesUpdaterOptions,
27-
projectData: this.$projectData,
28-
config: this.$options,
29-
env: this.$options.env,
30-
webpackCompilerConfig: {
31-
watch: false,
32-
env: this.$options.env
33-
}
34-
};
3521

36-
await this.$platformService.preparePlatform(platformInfo);
3722
const buildConfig: IBuildConfig = {
3823
buildForDevice: this.$options.forDevice,
3924
iCloudContainerEnvironment: this.$options.iCloudContainerEnvironment,
@@ -50,19 +35,15 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
5035
androidBundle: this.$options.aab
5136
};
5237

53-
const outputPath = await this.$platformService.buildPlatform(platform, buildConfig, this.$projectData);
54-
55-
if (this.$options.copyTo) {
56-
this.$platformService.copyLastOutput(platform, this.$options.copyTo, buildConfig, this.$projectData);
57-
} else {
58-
this.$logger.info(`The build result is located at: ${outputPath}`);
59-
}
38+
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
39+
const workflowData = this.$platformWorkflowDataFactory.createPlatformWorkflowData(platform, this.$options);
40+
const outputPath = await this.$platformWorkflowService.buildPlatform(platformData, this.$projectData, workflowData, buildConfig);
6041

6142
return outputPath;
6243
}
6344

6445
protected validatePlatform(platform: string): void {
65-
if (!this.$platformService.isPlatformSupportedForOS(platform, this.$projectData)) {
46+
if (!this.$platformValidationService.isPlatformSupportedForOS(platform, this.$projectData)) {
6647
this.$errors.fail(`Applications for platform ${platform} can not be built on this OS`);
6748
}
6849

@@ -82,7 +63,7 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
8263
return false;
8364
}
8465

85-
const result = await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
66+
const result = await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
8667
return result;
8768
}
8869
}
@@ -95,10 +76,12 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
9576
$projectData: IProjectData,
9677
$platformsData: IPlatformsData,
9778
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
98-
$platformService: IPlatformService,
79+
$platformWorkflowDataFactory: IPlatformWorkflowDataFactory,
80+
$platformWorkflowService: IPlatformWorkflowService,
81+
$platformValidationService: IPlatformValidationService,
9982
$bundleValidatorHelper: IBundleValidatorHelper,
10083
$logger: ILogger) {
101-
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger);
84+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformWorkflowDataFactory, $platformWorkflowService, $platformValidationService, $bundleValidatorHelper, $logger);
10285
}
10386

10487
public async execute(args: string[]): Promise<void> {
@@ -129,11 +112,13 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
129112
$projectData: IProjectData,
130113
$platformsData: IPlatformsData,
131114
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
132-
$platformService: IPlatformService,
115+
$platformWorkflowDataFactory: IPlatformWorkflowDataFactory,
116+
$platformWorkflowService: IPlatformWorkflowService,
117+
$platformValidationService: IPlatformValidationService,
133118
$bundleValidatorHelper: IBundleValidatorHelper,
134119
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
135120
protected $logger: ILogger) {
136-
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger);
121+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformWorkflowDataFactory, $platformWorkflowService, $platformValidationService, $bundleValidatorHelper, $logger);
137122
}
138123

139124
public async execute(args: string[]): Promise<void> {

lib/commands/clean-app.ts

-81
This file was deleted.

lib/commands/command-base.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export abstract class ValidatePlatformCommandBase {
22
constructor(protected $options: IOptions,
33
protected $platformsData: IPlatformsData,
4-
protected $platformService: IPlatformService,
4+
protected $platformValidationService: IPlatformValidationService,
55
protected $projectData: IProjectData) { }
66

77
abstract allowedParameters: ICommandParameter[];
@@ -14,7 +14,7 @@ export abstract class ValidatePlatformCommandBase {
1414
let result = { canExecute, suppressCommandHelp: !canExecute };
1515

1616
if (canExecute && options.validateOptions) {
17-
const validateOptionsOutput = await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
17+
const validateOptionsOutput = await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
1818
result = { canExecute: validateOptionsOutput, suppressCommandHelp: false };
1919
}
2020

0 commit comments

Comments
 (0)