-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathupdate.ts
77 lines (66 loc) · 2.41 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
76
77
import * as path from "path";
import * as shelljs from "shelljs";
export class UpdateCommand implements ICommand {
constructor(
private $projectData: IProjectData,
private $platformService: IPlatformService,
private $pluginsService: IPluginsService,
private $logger: ILogger,
private $options: IOptions,
private $errors: IErrors) { }
public execute(args: string[]): IFuture<void> {
return (() => {
let folders = [ "lib", "hooks", "platforms", "node_modules" ];
let tmpDir = path.join(this.$projectData.projectDir, ".tmp_backup");
try {
shelljs.rm("-fr", tmpDir);
shelljs.mkdir(tmpDir);
shelljs.cp(path.join(this.$projectData.projectDir, "package.json"), tmpDir);
for (let folder of folders) {
shelljs.cp("-rf", path.join(this.$projectData.projectDir, folder), tmpDir);
}
} catch(error) {
this.$logger.error("Could not backup project folders!");
return;
}
try {
this.executeCore(args, folders);
} catch (error) {
shelljs.cp("-f", path.join(tmpDir, "package.json"), this.$projectData.projectDir);
for (let folder of folders) {
shelljs.rm("-rf", path.join(this.$projectData.projectDir, folder));
shelljs.cp("-fr", path.join(tmpDir, folder), this.$projectData.projectDir);
}
this.$logger.error("Could not update the project!");
} finally {
shelljs.rm("-fr", tmpDir);
}
}).future<void>()();
}
public canExecute(args: string[]): IFuture<boolean> {
return (() => {
return args.length < 2 && this.$projectData.projectDir !== "";
}).future<boolean>()();
}
private executeCore(args: string[], folders: string[]) {
let platforms = this.$platformService.getInstalledPlatforms().wait();
this.$platformService.removePlatforms(platforms).wait();
this.$pluginsService.remove("tns-core-modules").wait();
this.$pluginsService.remove("tns-core-modules-widgets").wait();
for (let folder of folders) {
shelljs.rm("-fr", folder);
}
if (args.length === 1) {
for (let platform of platforms) {
this.$platformService.addPlatforms([ platform+"@"+args[0] ]).wait();
}
this.$pluginsService.add("tns-core-modules@" + args[0]).wait();
} else {
this.$platformService.addPlatforms(platforms).wait();
this.$pluginsService.add("tns-core-modules").wait();
}
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();
}
allowedParameters: ICommandParameter[] = [];
}
$injector.registerCommand("update", UpdateCommand);