Skip to content

Commit ca1d334

Browse files
author
Dimitar Tachev
authored
Merge pull request #4848 from NativeScript/tachev/skip-migration-on-force
feat: skip migration check based on --force
2 parents eedfd5e + fd1ed04 commit ca1d334

File tree

9 files changed

+49
-10
lines changed

9 files changed

+49
-10
lines changed

lib/commands/build.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
7474

7575
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
7676
const platform = this.$devicePlatformsConstants.iOS;
77-
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
77+
if (!this.$options.force) {
78+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
79+
}
7880

7981
super.validatePlatform(platform);
8082

@@ -120,7 +122,9 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
120122

121123
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
122124
const platform = this.$devicePlatformsConstants.Android;
123-
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
125+
if (!this.$options.force) {
126+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
127+
}
124128
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
125129
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
126130
if (result.canExecute) {

lib/commands/debug.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ 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, platforms: [this.platform] });
56+
if (!this.$options.force) {
57+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [this.platform] });
58+
}
5759

5860
this.$androidBundleValidatorHelper.validateNoAab();
5961

lib/commands/prepare.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
3333
const platform = args[0];
3434
const result = await this.$platformCommandParameter.validate(platform) &&
3535
await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
36-
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
36+
37+
if (!this.$options.force) {
38+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
39+
}
40+
3741
if (!result) {
3842
return false;
3943
}

lib/commands/preview.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ 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, platforms: [] });
44+
if (!this.$options.force) {
45+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [] });
46+
}
4547

4648
await this.$networkConnectivityValidator.validate();
4749
return true;

lib/commands/run.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class RunCommandBase implements ICommand {
1414
private $hostInfo: IHostInfo,
1515
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
1616
private $migrateController: IMigrateController,
17+
private $options: IOptions,
1718
private $projectData: IProjectData
1819
) { }
1920

@@ -36,7 +37,11 @@ export class RunCommandBase implements ICommand {
3637
this.$androidBundleValidatorHelper.validateNoAab();
3738
this.$projectData.initializeProjectData();
3839
const platforms = this.platform ? [this.platform] : [this.$devicePlatformsConstants.Android, this.$devicePlatformsConstants.iOS];
39-
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms });
40+
41+
if (!this.$options.force) {
42+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms });
43+
}
44+
4045
await this.$liveSyncCommandHelper.validatePlatform(this.platform);
4146

4247
return true;

lib/commands/test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ abstract class TestCommandBase {
4949
}
5050

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

5456
this.$projectData.initializeProjectData();
5557
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);

lib/controllers/migrate-controller.ts

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
2626
private $addPlatformService: IAddPlatformService,
2727
private $pluginsService: IPluginsService,
2828
private $projectDataService: IProjectDataService,
29+
private $platformValidationService: IPlatformValidationService,
2930
private $resources: IResourceLoader) {
3031
super($fs, $platformCommandHelper, $platformsDataService, $packageInstallationManager, $packageManager, $pacoteService);
3132
}
@@ -159,6 +160,9 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
159160

160161
for (let platform of platforms) {
161162
platform = platform && platform.toLowerCase();
163+
if (!this.$platformValidationService.isValidPlatform(platform, projectData)) {
164+
continue;
165+
}
162166

163167
const hasRuntimeDependency = this.hasRuntimeDependency({ platform, projectData });
164168
if (hasRuntimeDependency && await this.shouldUpdateRuntimeVersion(this.verifiedPlatformVersions[platform.toLowerCase()], platform, projectData, allowInvalidVersions)) {

lib/declarations.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,11 @@ interface IPlatformValidationService {
10211021
*/
10221022
validatePlatform(platform: string, projectData: IProjectData): void;
10231023

1024+
/**
1025+
* Returns whether the passed platform is a valid one (from the supported ones)
1026+
*/
1027+
isValidPlatform(platform: string, projectData: IProjectData): boolean;
1028+
10241029
/**
10251030
* Gets first chance to validate the options provided as command line arguments.
10261031
* If no platform is provided or a falsy (null, undefined, "", false...) platform is provided,

lib/services/platform/platform-validation-service.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,25 @@ export class PlatformValidationService implements IPlatformValidationService {
1111
private $platformsDataService: IPlatformsDataService
1212
) { }
1313

14-
public validatePlatform(platform: string, projectData: IProjectData): void {
14+
public isValidPlatform(platform: string, projectData: IProjectData): boolean {
1515
if (!platform) {
16-
this.$errors.fail("No platform specified.");
16+
return false;
1717
}
1818

1919
platform = platform.split("@")[0].toLowerCase();
20-
2120
if (!this.$platformsDataService.getPlatformData(platform, projectData)) {
21+
return false;
22+
}
23+
24+
return true;
25+
}
26+
27+
public validatePlatform(platform: string, projectData: IProjectData): void {
28+
if (!platform) {
29+
this.$errors.fail("No platform specified.");
30+
}
31+
32+
if (!this.isValidPlatform(platform, projectData)) {
2233
const platformNames = helpers.formatListOfNames(this.$mobileHelper.platformNames);
2334
this.$errors.fail(`Invalid platform ${platform}. Valid platforms are ${platformNames}.`);
2435
}

0 commit comments

Comments
 (0)