-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathupdate.ts
40 lines (33 loc) · 1.63 KB
/
update.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
export class UpdateCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];
public static readonly SHOULD_MIGRATE_PROJECT_MESSAGE = 'This project is not compatible with the current NativeScript version and cannot be updated. Use "tns migrate" to make your project compatible.';
public static readonly PROJECT_UP_TO_DATE_MESSAGE = 'This project is up to date.';
constructor(
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $updateController: IUpdateController,
private $migrateController: IMigrateController,
private $options: IOptions,
private $errors: IErrors,
private $logger: ILogger,
private $projectData: IProjectData) {
this.$projectData.initializeProjectData();
}
public async execute(args: string[]): Promise<void> {
if (!await this.$updateController.shouldUpdate({ projectDir: this.$projectData.projectDir, version: args[0] })) {
this.$logger.printMarkdown(`__${UpdateCommand.PROJECT_UP_TO_DATE_MESSAGE}__`);
return;
}
await this.$updateController.update({ projectDir: this.$projectData.projectDir, version: args[0], frameworkPath: this.$options.frameworkPath });
}
public async canExecute(args: string[]): Promise<boolean> {
const shouldMigrate = await this.$migrateController.shouldMigrate({
projectDir: this.$projectData.projectDir,
platforms: [this.$devicePlatformsConstants.Android, this.$devicePlatformsConstants.iOS]
});
if (shouldMigrate) {
this.$errors.failWithoutHelp(UpdateCommand.SHOULD_MIGRATE_PROJECT_MESSAGE);
}
return args.length < 2 && this.$projectData.projectDir !== "";
}
}
$injector.registerCommand("update", UpdateCommand);