Skip to content

Commit 3358280

Browse files
committed
fix: validate the migration per platform
1 parent 94c63ae commit 3358280

File tree

11 files changed

+54
-35
lines changed

11 files changed

+54
-35
lines changed

lib/commands/build.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
1111
$platformValidationService: IPlatformValidationService,
1212
private $buildDataService: IBuildDataService,
1313
protected $logger: ILogger) {
14-
super($options, $platformsDataService, $platformValidationService, $projectData);
15-
this.$projectData.initializeProjectData();
14+
super($options, $platformsDataService, $platformValidationService, $projectData);
15+
this.$projectData.initializeProjectData();
1616
}
1717

1818
public dashedOptions = {
@@ -65,16 +65,16 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
6565
$logger: ILogger,
6666
$buildDataService: IBuildDataService,
6767
private $migrateController: IMigrateController) {
68-
super($options, $errors, $projectData, $platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
68+
super($options, $errors, $projectData, $platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
6969
}
7070

7171
public async execute(args: string[]): Promise<void> {
7272
await this.executeCore([this.$devicePlatformsConstants.iOS.toLowerCase()]);
7373
}
7474

7575
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
76-
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
7776
const platform = this.$devicePlatformsConstants.iOS;
77+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
7878

7979
super.validatePlatform(platform);
8080

@@ -103,7 +103,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
103103
$buildDataService: IBuildDataService,
104104
protected $logger: ILogger,
105105
private $migrateController: IMigrateController) {
106-
super($options, $errors, $projectData, platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
106+
super($options, $errors, $projectData, platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
107107
}
108108

109109
public async execute(args: string[]): Promise<void> {
@@ -119,8 +119,8 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
119119
}
120120

121121
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
122-
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
123122
const platform = this.$devicePlatformsConstants.Android;
123+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
124124
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
125125
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
126126
if (result.canExecute) {

lib/commands/debug.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
5353
}
5454

5555
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
56-
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
56+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [this.platform] });
5757

5858
this.$androidBundleValidatorHelper.validateNoAab();
5959

lib/commands/migrate.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@ export class MigrateCommand implements ICommand {
22
public allowedParameters: ICommandParameter[] = [];
33

44
constructor(
5+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
56
private $migrateController: IMigrateController,
67
private $projectData: IProjectData,
78
private $errors: IErrors) {
89
this.$projectData.initializeProjectData();
910
}
1011

1112
public async execute(args: string[]): Promise<void> {
12-
await this.$migrateController.migrate({ projectDir: this.$projectData.projectDir });
13+
await this.$migrateController.migrate({
14+
projectDir: this.$projectData.projectDir,
15+
platforms: [this.$devicePlatformsConstants.Android, this.$devicePlatformsConstants.iOS]
16+
});
1317
}
1418

1519
public async canExecute(args: string[]): Promise<boolean> {
16-
const shouldMigrateResult = await this.$migrateController.shouldMigrate({ projectDir: this.$projectData.projectDir });
20+
const shouldMigrateResult = await this.$migrateController.shouldMigrate({
21+
projectDir: this.$projectData.projectDir,
22+
platforms: [this.$devicePlatformsConstants.Android, this.$devicePlatformsConstants.iOS]
23+
});
1724

1825
if (!shouldMigrateResult) {
1926
this.$errors.failWithoutHelp('Project is compatible with NativeScript "v6.0.0". To get the latest NativesScript packages execute "tns update".');

lib/commands/prepare.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
1818
$platformsDataService: IPlatformsDataService,
1919
private $prepareDataService: PrepareDataService,
2020
private $migrateController: IMigrateController) {
21-
super($options, $platformsDataService, $platformValidationService, $projectData);
22-
this.$projectData.initializeProjectData();
21+
super($options, $platformsDataService, $platformValidationService, $projectData);
22+
this.$projectData.initializeProjectData();
2323
}
2424

2525
public async execute(args: string[]): Promise<void> {
@@ -30,10 +30,10 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
3030
}
3131

3232
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
33-
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
3433
const platform = args[0];
3534
const result = await this.$platformCommandParameter.validate(platform) &&
3635
await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
36+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
3737
if (!result) {
3838
return false;
3939
}

lib/commands/preview.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class PreviewCommand implements ICommand {
4141
this.$errors.fail(`The arguments '${args.join(" ")}' are not valid for the preview command.`);
4242
}
4343

44-
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
44+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [] });
4545

4646
await this.$networkConnectivityValidator.validate();
4747
return true;

lib/commands/run.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@ export class RunCommandBase implements ICommand {
2828
this.$errors.fail(ERROR_NO_VALID_SUBCOMMAND_FORMAT, "run");
2929
}
3030

31-
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
32-
33-
this.$androidBundleValidatorHelper.validateNoAab();
34-
35-
this.$projectData.initializeProjectData();
3631
this.platform = args[0] || this.platform;
37-
3832
if (!this.platform && !this.$hostInfo.isDarwin) {
3933
this.platform = this.$devicePlatformsConstants.Android;
4034
}
4135

36+
this.$androidBundleValidatorHelper.validateNoAab();
37+
this.$projectData.initializeProjectData();
38+
const platforms = this.platform ? [this.platform] : [this.$devicePlatformsConstants.Android, this.$devicePlatformsConstants.iOS];
39+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms });
4240
await this.$liveSyncCommandHelper.validatePlatform(this.platform);
4341

4442
return true;

lib/commands/test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ abstract class TestCommandBase {
3535
devices = await this.$liveSyncCommandHelper.getDeviceInstances(this.platform);
3636
}
3737

38-
if (!this.$options.env) { this.$options.env = { }; }
38+
if (!this.$options.env) { this.$options.env = {}; }
3939
this.$options.env.unitTesting = true;
4040

4141
const liveSyncInfo = this.$liveSyncCommandHelper.getLiveSyncData(this.$projectData.projectDir);
@@ -49,7 +49,7 @@ abstract class TestCommandBase {
4949
}
5050

5151
async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
52-
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
52+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [this.platform] });
5353

5454
this.$projectData.initializeProjectData();
5555
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);

lib/commands/update.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export class UpdateCommand implements ICommand {
44
public static readonly PROJECT_UP_TO_DATE_MESSAGE = 'This project is up to date.';
55

66
constructor(
7+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
78
private $updateController: IUpdateController,
89
private $migrateController: IMigrateController,
910
private $options: IOptions,
@@ -13,15 +14,20 @@ export class UpdateCommand implements ICommand {
1314
}
1415

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

1920
public async canExecute(args: string[]): Promise<boolean> {
20-
if (await this.$migrateController.shouldMigrate({projectDir: this.$projectData.projectDir})) {
21+
const shouldMigrate = await this.$migrateController.shouldMigrate({
22+
projectDir: this.$projectData.projectDir,
23+
platforms: [this.$devicePlatformsConstants.Android, this.$devicePlatformsConstants.iOS]
24+
});
25+
26+
if (shouldMigrate) {
2127
this.$errors.failWithoutHelp(UpdateCommand.SHOULD_MIGRATE_PROJECT_MESSAGE);
2228
}
2329

24-
if (!await this.$updateController.shouldUpdate({projectDir:this.$projectData.projectDir, version: args[0]})) {
30+
if (!await this.$updateController.shouldUpdate({ projectDir: this.$projectData.projectDir, version: args[0] })) {
2531
this.$errors.failWithoutHelp(UpdateCommand.PROJECT_UP_TO_DATE_MESSAGE);
2632
}
2733

lib/controllers/migrate-controller.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
9595
};
9696
}
9797

98-
public async migrate({ projectDir }: { projectDir: string }): Promise<void> {
98+
public async migrate({ projectDir, platforms }: IMigrationData): Promise<void> {
9999
const projectData = this.$projectDataService.getProjectData(projectDir);
100100
const backupDir = path.join(projectDir, MigrateController.backupFolder);
101101

@@ -121,7 +121,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
121121

122122
try {
123123
await this.cleanUpProject(projectData);
124-
await this.migrateDependencies(projectData);
124+
await this.migrateDependencies(projectData, platforms);
125125
} catch (error) {
126126
this.restoreBackup(MigrateController.folders, backupDir, projectData.projectDir);
127127
this.$errors.failWithoutHelp(`${MigrateController.migrateFailMessage} The error is: ${error}`);
@@ -130,7 +130,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
130130
this.$logger.info(MigrateController.MIGRATE_FINISH_MESSAGE);
131131
}
132132

133-
public async shouldMigrate({ projectDir }: IProjectDir): Promise<boolean> {
133+
public async shouldMigrate({ projectDir, platforms }: IMigrationData): Promise<boolean> {
134134
const projectData = this.$projectDataService.getProjectData(projectDir);
135135
const shouldMigrateCommonMessage = "The app is not compatible with this CLI version and it should be migrated. Reason: ";
136136

@@ -159,7 +159,9 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
159159
}
160160
}
161161

162-
for (const platform in this.$devicePlatformsConstants) {
162+
for (let platform of platforms) {
163+
platform = platform && platform.toLowerCase();
164+
163165
const hasRuntimeDependency = this.hasRuntimeDependency({ platform, projectData });
164166
if (hasRuntimeDependency && await this.shouldUpdateRuntimeVersion({ targetVersion: this.verifiedPlatformVersions[platform.toLowerCase()], platform, projectData })) {
165167
this.$logger.trace(`${shouldMigrateCommonMessage}Platform '${platform}' should be updated.`);
@@ -168,8 +170,8 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
168170
}
169171
}
170172

171-
public async validate({ projectDir }: IProjectDir): Promise<void> {
172-
const shouldMigrate = await this.shouldMigrate({ projectDir });
173+
public async validate({ projectDir, platforms }: IMigrationData): Promise<void> {
174+
const shouldMigrate = await this.shouldMigrate({ projectDir, platforms });
173175
if (shouldMigrate) {
174176
this.$errors.failWithoutHelp(MigrateController.UNABLE_TO_MIGRATE_APP_ERROR);
175177
}
@@ -273,7 +275,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
273275
return autoGeneratedFiles;
274276
}
275277

276-
private async migrateDependencies(projectData: IProjectData): Promise<void> {
278+
private async migrateDependencies(projectData: IProjectData, platforms: string[]): Promise<void> {
277279
this.$logger.info("Start dependencies migration.");
278280
for (let i = 0; i < this.migrationDependencies.length; i++) {
279281
const dependency = this.migrationDependencies[i];
@@ -289,7 +291,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
289291
await this.migrateDependency(dependency, projectData);
290292
}
291293

292-
for (const platform in this.$devicePlatformsConstants) {
294+
for (const platform of platforms) {
293295
const lowercasePlatform = platform.toLowerCase();
294296
const hasRuntimeDependency = this.hasRuntimeDependency({ platform, projectData });
295297
if (hasRuntimeDependency && await this.shouldUpdateRuntimeVersion({ targetVersion: this.verifiedPlatformVersions[lowercasePlatform], platform, projectData })) {

lib/definitions/migrate.d.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
interface IMigrateController {
2-
migrate(migrateData: IProjectDir): Promise<void>;
3-
shouldMigrate(data: IProjectDir): Promise<boolean>;
4-
validate(data: IProjectDir): Promise<void>;
2+
migrate(data: IMigrationData): Promise<void>;
3+
shouldMigrate(data: IMigrationData): Promise<boolean>;
4+
validate(data: IMigrationData): Promise<void>;
5+
}
6+
7+
interface IMigrationData extends IProjectDir {
8+
platforms: string[];
59
}
610

711
interface IDependency {

test/update.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { assert } from "chai";
55
import { Options } from "../lib/options";
66
import { StaticConfig } from "../lib/config";
77
import { SettingsService } from "../lib/common/test/unit-tests/stubs";
8+
import { DevicePlatformsConstants } from "../lib/common/mobile/device-platforms-constants";
89
const projectFolder = "test";
910

1011
function createTestInjector(
@@ -26,6 +27,7 @@ function createTestInjector(
2627
dependencies: {}
2728
});
2829
testInjector.register("settingsService", SettingsService);
30+
testInjector.register("devicePlatformsConstants", DevicePlatformsConstants);
2931
testInjector.register("migrateController", {
3032
shouldMigrate: () => { return false; },
3133
});

0 commit comments

Comments
 (0)