-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathupdate.ts
75 lines (66 loc) · 2.29 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { IProjectData } from "../definitions/project";
import { IMigrateController } from "../definitions/migrate";
import { IOptions } from "../declarations";
import { ICommand, ICommandParameter } from "../common/definitions/commands";
import { IErrors } from "../common/declarations";
import { injector } from "../common/yok";
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 "ns 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,
private $markingModeService: IMarkingModeService
) {
this.$projectData.initializeProjectData();
}
public async execute(args: string[]): Promise<void> {
if (this.$options.markingMode) {
// ns update --markingMode
await this.$markingModeService.handleMarkingModeFullDeprecation({
projectDir: this.$projectData.projectDir,
forceSwitch: true,
});
return;
}
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,
],
loose: true,
});
if (shouldMigrate) {
this.$errors.fail(UpdateCommand.SHOULD_MIGRATE_PROJECT_MESSAGE);
}
return args.length < 2 && this.$projectData.projectDir !== "";
}
}
injector.registerCommand("update", UpdateCommand);