Skip to content

Commit d1607c8

Browse files
committed
feat: show error when the project is not migrated and is not compatible for CLI 6.0
1 parent 9e61ab7 commit d1607c8

File tree

10 files changed

+51
-17
lines changed

10 files changed

+51
-17
lines changed

lib/commands/build.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
6363
$buildController: IBuildController,
6464
$platformValidationService: IPlatformValidationService,
6565
$logger: ILogger,
66-
$buildDataService: IBuildDataService) {
66+
$buildDataService: IBuildDataService,
67+
private $migrateController: IMigrateController) {
6768
super($options, $errors, $projectData, $platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
6869
}
6970

@@ -72,6 +73,7 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
7273
}
7374

7475
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
76+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
7577
const platform = this.$devicePlatformsConstants.iOS;
7678

7779
super.validatePlatform(platform);
@@ -99,7 +101,8 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
99101
$platformValidationService: IPlatformValidationService,
100102
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
101103
$buildDataService: IBuildDataService,
102-
protected $logger: ILogger) {
104+
protected $logger: ILogger,
105+
private $migrateController: IMigrateController) {
103106
super($options, $errors, $projectData, platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
104107
}
105108

@@ -116,6 +119,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
116119
}
117120

118121
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
122+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
119123
const platform = this.$devicePlatformsConstants.Android;
120124
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
121125
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });

lib/commands/debug.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
1616
private $debugDataService: IDebugDataService,
1717
private $debugController: IDebugController,
1818
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
19-
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
19+
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
20+
private $migrateController: IMigrateController) {
2021
super($options, $platformsDataService, $platformValidationService, $projectData);
2122
$cleanupService.setShouldDispose(false);
2223
}
@@ -52,6 +53,8 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
5253
}
5354

5455
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
56+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
57+
5558
this.$androidBundleValidatorHelper.validateNoAab();
5659

5760
if (!this.$platformValidationService.isPlatformSupportedForOS(this.platform, this.$projectData)) {

lib/commands/migrate.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ export class MigrateCommand implements ICommand {
99
}
1010

1111
public async execute(args: string[]): Promise<void> {
12-
await this.$migrateController.migrate({projectDir: this.$projectData.projectDir});
12+
await this.$migrateController.migrate({ projectDir: this.$projectData.projectDir });
1313
}
1414

1515
public async canExecute(args: string[]): Promise<boolean> {
16-
if (!await this.$migrateController.shouldMigrate({ projectDir: this.$projectData.projectDir })) {
16+
const shouldMigrateResult = await this.$migrateController.shouldMigrate({ projectDir: this.$projectData.projectDir });
17+
18+
if (!shouldMigrateResult) {
1719
this.$errors.failWithoutHelp('Project is compatible with NativeScript "v6.0.0". To get the latest NativesScript packages execute "tns update".');
1820
}
1921

lib/commands/prepare.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
1616
$projectData: IProjectData,
1717
private $platformCommandParameter: ICommandParameter,
1818
$platformsDataService: IPlatformsDataService,
19-
private $prepareDataService: PrepareDataService) {
19+
private $prepareDataService: PrepareDataService,
20+
private $migrateController: IMigrateController) {
2021
super($options, $platformsDataService, $platformValidationService, $projectData);
2122
this.$projectData.initializeProjectData();
2223
}
@@ -29,6 +30,7 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
2930
}
3031

3132
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
33+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
3234
const platform = args[0];
3335
const result = await this.$platformCommandParameter.validate(platform) &&
3436
await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);

lib/commands/preview.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ export class PreviewCommand implements ICommand {
44
public allowedParameters: ICommandParameter[] = [];
55

66
constructor(private $analyticsService: IAnalyticsService,
7-
private $bundleValidatorHelper: IBundleValidatorHelper,
87
private $errors: IErrors,
98
private $logger: ILogger,
9+
private $migrateController: IMigrateController,
1010
private $previewAppController: IPreviewAppController,
1111
private $networkConnectivityValidator: INetworkConnectivityValidator,
1212
private $projectData: IProjectData,
@@ -41,8 +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 });
45+
4446
await this.$networkConnectivityValidator.validate();
45-
this.$bundleValidatorHelper.validate(this.$projectData, "1.0.0");
4647
return true;
4748
}
4849
}

lib/commands/run.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class RunCommandBase implements ICommand {
1313
private $errors: IErrors,
1414
private $hostInfo: IHostInfo,
1515
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
16+
private $migrateController: IMigrateController,
1617
private $projectData: IProjectData
1718
) { }
1819

@@ -27,6 +28,8 @@ export class RunCommandBase implements ICommand {
2728
this.$errors.fail(ERROR_NO_VALID_SUBCOMMAND_FORMAT, "run");
2829
}
2930

31+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
32+
3033
this.$androidBundleValidatorHelper.validateNoAab();
3134

3235
this.$projectData.initializeProjectData();

lib/commands/test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ abstract class TestCommandBase {
1010
protected abstract $cleanupService: ICleanupService;
1111
protected abstract $liveSyncCommandHelper: ILiveSyncCommandHelper;
1212
protected abstract $devicesService: Mobile.IDevicesService;
13+
protected abstract $migrateController: IMigrateController;
1314

1415
async execute(args: string[]): Promise<void> {
1516
let devices = [];
@@ -48,6 +49,8 @@ abstract class TestCommandBase {
4849
}
4950

5051
async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
52+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
53+
5154
this.$projectData.initializeProjectData();
5255
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
5356
this.$cleanupService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
@@ -86,7 +89,8 @@ class TestAndroidCommand extends TestCommandBase implements ICommand {
8689
protected $errors: IErrors,
8790
protected $cleanupService: ICleanupService,
8891
protected $liveSyncCommandHelper: ILiveSyncCommandHelper,
89-
protected $devicesService: Mobile.IDevicesService) {
92+
protected $devicesService: Mobile.IDevicesService,
93+
protected $migrateController: IMigrateController) {
9094
super();
9195
}
9296
}
@@ -102,7 +106,8 @@ class TestIosCommand extends TestCommandBase implements ICommand {
102106
protected $errors: IErrors,
103107
protected $cleanupService: ICleanupService,
104108
protected $liveSyncCommandHelper: ILiveSyncCommandHelper,
105-
protected $devicesService: Mobile.IDevicesService) {
109+
protected $devicesService: Mobile.IDevicesService,
110+
protected $migrateController: IMigrateController) {
106111
super();
107112
}
108113

lib/controllers/migrate-controller.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { UpdateControllerBase } from "./update-controller-base";
66
import { fromWindowsRelativePathToUnix } from "../common/helpers";
77

88
export class MigrateController extends UpdateControllerBase implements IMigrateController {
9+
// TODO: Improve the messages here
10+
public UNABLE_TO_MIGRATE_APP_ERROR = "The project is not compatible with NativeScript 6.0";
11+
public MIGRATE_MESSAGE = "";
12+
913
constructor(
1014
protected $fs: IFileSystem,
1115
protected $platformCommandHelper: IPlatformCommandHelper,
@@ -71,7 +75,10 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
7175
shouldMigrateAction: (projectData: IProjectData) => this.hasDependency({ packageName: "nativescript-unit-test-runner", isDev: false }, projectData),
7276
migrateAction: this.migrateUnitTestRunner.bind(this)
7377
},
74-
{ packageName: MigrateController.typescriptPackageName, isDev: true, getVerifiedVersion: this.getAngularTypeScriptVersion.bind(this) }
78+
{ packageName: MigrateController.typescriptPackageName, isDev: true, getVerifiedVersion: this.getAngularTypeScriptVersion.bind(this) },
79+
{ packageName: "nativescript-localize", verifiedVersion: "4.2.0" },
80+
{ packageName: "nativescript-dev-babel", verifiedVersion: "0.2.1" },
81+
{ packageName: "nativescript-nfc", verifiedVersion: "4.0.1" }
7582
];
7683

7784
get verifiedPlatformVersions(): IDictionary<string> {
@@ -112,6 +119,8 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
112119
this.restoreBackup(MigrateController.folders, backupDir, projectData.projectDir);
113120
this.$errors.failWithoutHelp(`${MigrateController.migrateFailMessage} The error is: ${error}`);
114121
}
122+
123+
this.$logger.info(this.MIGRATE_MESSAGE);
115124
}
116125

117126
public async shouldMigrate({ projectDir }: IProjectDir): Promise<boolean> {
@@ -136,10 +145,10 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
136145
if (!hasDependency && dependency.shouldAddIfMissing) {
137146
return true;
138147
}
148+
}
139149

140-
if (!this.$androidResourcesMigrationService.hasMigrated(projectData.getAppResourcesDirectoryPath())) {
141-
return true;
142-
}
150+
if (!this.$androidResourcesMigrationService.hasMigrated(projectData.getAppResourcesDirectoryPath())) {
151+
return true;
143152
}
144153

145154
for (const platform in this.$devicePlatformsConstants) {
@@ -150,6 +159,13 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
150159
}
151160
}
152161

162+
public async validate({ projectDir }: IProjectDir): Promise<void> {
163+
const shouldMigrate = await this.shouldMigrate({ projectDir });
164+
if (shouldMigrate) {
165+
this.$errors.failWithoutHelp(this.UNABLE_TO_MIGRATE_APP_ERROR);
166+
}
167+
}
168+
153169
private async getAngularTypeScriptVersion(projectData: IProjectData): Promise<string> {
154170
let verifiedVersion = "3.4.1";
155171
try {

lib/controllers/prepare-controller.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export class PrepareController extends EventEmitter {
1616
private persistedData: IFilesChangeEventData[] = [];
1717

1818
constructor(
19-
private $bundleValidatorHelper: IBundleValidatorHelper,
2019
private $platformController: IPlatformController,
2120
public $hooksService: IHooksService,
2221
private $logger: ILogger,
@@ -55,8 +54,6 @@ export class PrepareController extends EventEmitter {
5554
@performanceLog()
5655
@hook("prepare")
5756
private async prepareCore(prepareData: IPrepareData, projectData: IProjectData): Promise<IPrepareResultData> {
58-
this.$bundleValidatorHelper.validate(projectData, "1.0.0");
59-
6057
await this.$platformController.addPlatformIfNeeded(prepareData);
6158

6259
this.$logger.info("Preparing project...");

lib/definitions/migrate.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
interface IMigrateController {
22
migrate(migrateData: IProjectDir): Promise<void>;
33
shouldMigrate(data: IProjectDir): Promise<boolean>;
4+
validate(data: IProjectDir): Promise<void>;
45
}
56

67
interface IDependency {

0 commit comments

Comments
 (0)