|
| 1 | +const fs = require('fs-extra'); |
1 | 2 | const path = require('path');
|
2 | 3 | const Command = require('../command');
|
3 | 4 | const symlinkSync = require('symlink-or-copy').sync;
|
@@ -49,31 +50,36 @@ class InstallCommand extends Command {
|
49 | 50 | local
|
50 | 51 | });
|
51 | 52 |
|
52 |
| - await this.ui.listr([{ |
53 |
| - title: 'Checking for latest Ghost version', |
54 |
| - task: this.version |
55 |
| - }, { |
56 |
| - title: 'Setting up install directory', |
57 |
| - task: ensureStructure |
58 |
| - }, { |
59 |
| - title: 'Downloading and installing Ghost', |
60 |
| - task: (ctx, task) => { |
61 |
| - task.title = `Downloading and installing Ghost v${ctx.version}`; |
62 |
| - return yarnInstall(ctx.ui, ctx.argv.zip); |
63 |
| - } |
64 |
| - }, { |
65 |
| - title: 'Finishing install process', |
66 |
| - task: () => this.ui.listr([{ |
67 |
| - title: 'Linking latest Ghost and recording versions', |
68 |
| - task: this.link.bind(this) |
| 53 | + try { |
| 54 | + await this.ui.listr([{ |
| 55 | + title: 'Checking for latest Ghost version', |
| 56 | + task: this.version |
69 | 57 | }, {
|
70 |
| - title: 'Linking latest Casper', |
71 |
| - task: this.casper |
72 |
| - }], false) |
73 |
| - }], { |
74 |
| - argv: {...argv, version}, |
75 |
| - cliVersion: this.system.cliVersion |
76 |
| - }); |
| 58 | + title: 'Setting up install directory', |
| 59 | + task: ensureStructure |
| 60 | + }, { |
| 61 | + title: 'Downloading and installing Ghost', |
| 62 | + task: (ctx, task) => { |
| 63 | + task.title = `Downloading and installing Ghost v${ctx.version}`; |
| 64 | + return yarnInstall(ctx.ui, ctx.argv.zip); |
| 65 | + } |
| 66 | + }, { |
| 67 | + title: 'Finishing install process', |
| 68 | + task: () => this.ui.listr([{ |
| 69 | + title: 'Linking latest Ghost and recording versions', |
| 70 | + task: this.link.bind(this) |
| 71 | + }, { |
| 72 | + title: 'Linking latest Casper', |
| 73 | + task: this.casper |
| 74 | + }], false) |
| 75 | + }], { |
| 76 | + argv: {...argv, version}, |
| 77 | + cliVersion: this.system.cliVersion |
| 78 | + }); |
| 79 | + } catch (error) { |
| 80 | + this.cleanInstallDirectory(); |
| 81 | + throw error; |
| 82 | + } |
77 | 83 |
|
78 | 84 | if (!argv.setup) {
|
79 | 85 | return;
|
@@ -140,6 +146,11 @@ class InstallCommand extends Command {
|
140 | 146 | instance.cliVersion = this.system.cliVersion;
|
141 | 147 | instance.channel = ctx.argv.channel || 'stable';
|
142 | 148 | }
|
| 149 | + |
| 150 | + cleanInstallDirectory() { |
| 151 | + const cwd = process.cwd(); |
| 152 | + fs.readdirSync(cwd).map(file => fs.removeSync(file)); |
| 153 | + } |
143 | 154 | }
|
144 | 155 |
|
145 | 156 | InstallCommand.global = true;
|
|
0 commit comments