Skip to content

feat: skip migration check based on --force #4848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {

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

super.validatePlatform(platform);

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

public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
const platform = this.$devicePlatformsConstants.Android;
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
if (!this.$options.force) {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
}
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
if (result.canExecute) {
Expand Down
4 changes: 3 additions & 1 deletion lib/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
}

public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [this.platform] });
if (!this.$options.force) {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [this.platform] });
}

this.$androidBundleValidatorHelper.validateNoAab();

Expand Down
6 changes: 5 additions & 1 deletion lib/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
const platform = args[0];
const result = await this.$platformCommandParameter.validate(platform) &&
await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });

if (!this.$options.force) {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
}

if (!result) {
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export class PreviewCommand implements ICommand {
this.$errors.fail(`The arguments '${args.join(" ")}' are not valid for the preview command.`);
}

await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [] });
if (!this.$options.force) {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [] });
}

await this.$networkConnectivityValidator.validate();
return true;
Expand Down
7 changes: 6 additions & 1 deletion lib/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class RunCommandBase implements ICommand {
private $hostInfo: IHostInfo,
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
private $migrateController: IMigrateController,
private $options: IOptions,
private $projectData: IProjectData
) { }

Expand All @@ -36,7 +37,11 @@ export class RunCommandBase implements ICommand {
this.$androidBundleValidatorHelper.validateNoAab();
this.$projectData.initializeProjectData();
const platforms = this.platform ? [this.platform] : [this.$devicePlatformsConstants.Android, this.$devicePlatformsConstants.iOS];
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms });

if (!this.$options.force) {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms });
}

await this.$liveSyncCommandHelper.validatePlatform(this.platform);

return true;
Expand Down
4 changes: 3 additions & 1 deletion lib/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ abstract class TestCommandBase {
}

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

this.$projectData.initializeProjectData();
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
Expand Down
4 changes: 4 additions & 0 deletions lib/controllers/migrate-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
private $addPlatformService: IAddPlatformService,
private $pluginsService: IPluginsService,
private $projectDataService: IProjectDataService,
private $platformValidationService: IPlatformValidationService,
private $resources: IResourceLoader) {
super($fs, $platformCommandHelper, $platformsDataService, $packageInstallationManager, $packageManager, $pacoteService);
}
Expand Down Expand Up @@ -159,6 +160,9 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;

for (let platform of platforms) {
platform = platform && platform.toLowerCase();
if (!this.$platformValidationService.isValidPlatform(platform, projectData)) {
continue;
}

const hasRuntimeDependency = this.hasRuntimeDependency({ platform, projectData });
if (hasRuntimeDependency && await this.shouldUpdateRuntimeVersion(this.verifiedPlatformVersions[platform.toLowerCase()], platform, projectData, allowInvalidVersions)) {
Expand Down
5 changes: 5 additions & 0 deletions lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,11 @@ interface IPlatformValidationService {
*/
validatePlatform(platform: string, projectData: IProjectData): void;

/**
* Returns whether the passed platform is a valid one (from the supported ones)
*/
isValidPlatform(platform: string, projectData: IProjectData): boolean;

/**
* Gets first chance to validate the options provided as command line arguments.
* If no platform is provided or a falsy (null, undefined, "", false...) platform is provided,
Expand Down
17 changes: 14 additions & 3 deletions lib/services/platform/platform-validation-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,25 @@ export class PlatformValidationService implements IPlatformValidationService {
private $platformsDataService: IPlatformsDataService
) { }

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

platform = platform.split("@")[0].toLowerCase();

if (!this.$platformsDataService.getPlatformData(platform, projectData)) {
return false;
}

return true;
}

public validatePlatform(platform: string, projectData: IProjectData): void {
if (!platform) {
this.$errors.fail("No platform specified.");
}

if (!this.isValidPlatform(platform, projectData)) {
const platformNames = helpers.formatListOfNames(this.$mobileHelper.platformNames);
this.$errors.fail(`Invalid platform ${platform}. Valid platforms are ${platformNames}.`);
}
Expand Down