|
| 1 | +import * as path from "path"; |
| 2 | + |
| 3 | +export class UpdateCommand implements ICommand { |
| 4 | + constructor( |
| 5 | + private $projectData: IProjectData, |
| 6 | + private $platformService: IPlatformService, |
| 7 | + private $pluginsService: IPluginsService, |
| 8 | + private $logger: ILogger, |
| 9 | + private $fs: IFileSystem, |
| 10 | + private $options: IOptions, |
| 11 | + private $errors: IErrors) { } |
| 12 | + |
| 13 | + public execute(args: string[]): IFuture<void> { |
| 14 | + return (() => { |
| 15 | + let platforms = this.$platformService.getInstalledPlatforms().wait(); |
| 16 | + |
| 17 | + this.$platformService.removePlatforms(platforms).wait(); |
| 18 | + this.$pluginsService.remove("tns-core-modules").wait(); |
| 19 | + this.$pluginsService.remove("tns-core-modules-widgets").wait(); |
| 20 | + |
| 21 | + this.$fs.deleteDirectory(path.join(this.$projectData.projectDir, "lib")).wait(); |
| 22 | + this.$fs.deleteDirectory(path.join(this.$projectData.projectDir, "hooks")).wait(); |
| 23 | + this.$fs.deleteDirectory(path.join(this.$projectData.projectDir, "platforms")).wait(); |
| 24 | + this.$fs.deleteDirectory(path.join(this.$projectData.projectDir, "node_modules")).wait(); |
| 25 | + |
| 26 | + if (args.length === 1) { |
| 27 | + for (let platform of platforms) { |
| 28 | + this.$platformService.addPlatforms([ platform+"@"+args[0] ]).wait(); |
| 29 | + } |
| 30 | + this.$pluginsService.add("tns-core-modules@" + args[0]).wait(); |
| 31 | + } |
| 32 | + else { |
| 33 | + this.$platformService.addPlatforms(platforms).wait(); |
| 34 | + this.$pluginsService.add("tns-core-modules").wait(); |
| 35 | + } |
| 36 | + this.$pluginsService.ensureAllDependenciesAreInstalled().wait(); |
| 37 | + |
| 38 | + }).future<void>()(); |
| 39 | + } |
| 40 | + |
| 41 | + public canExecute(args: string[]): IFuture<boolean> { |
| 42 | + return (() => { |
| 43 | + return args.length < 2 && this.$projectData.projectDir !== ""; |
| 44 | + }).future<boolean>()(); |
| 45 | + } |
| 46 | + |
| 47 | + allowedParameters: ICommandParameter[] = []; |
| 48 | +} |
| 49 | +$injector.registerCommand("update", UpdateCommand); |
0 commit comments