feat: uninstall command for installed binaries

This commit is contained in:
Mariusz Nowak 2019-11-14 15:46:08 +01:00 committed by Mariusz Nowak
parent c4efd66e4e
commit 53e596fa67
3 changed files with 27 additions and 9 deletions

View File

@ -18,7 +18,7 @@ const ServerlessError = require('./classes/Error').ServerlessError;
const Version = require('./../package.json').version;
const isStandaloneExecutable = require('./utils/isStandaloneExecutable');
const installationMaintananceCommands = new Set(['upgrade']);
const installationMaintananceCommands = new Set(['uninstall', 'upgrade']);
class Serverless {
constructor(config) {

View File

@ -24,12 +24,20 @@ module.exports = class Executable {
usage: 'Upgrade Serverless',
lifecycleEvents: ['upgrade'],
},
uninstall: {
isHidden: !isStandaloneExecutable,
usage: 'Uninstall Serverless',
lifecycleEvents: ['uninstall'],
},
};
this.hooks = {
'upgrade:upgrade': () => {
return isStandaloneExecutable ? this.upgrade() : this.rejectCommand('upgrade');
},
'uninstall:uninstall': () => {
return isStandaloneExecutable ? this.uninstall() : this.rejectCommand('uninstall');
},
};
}
@ -89,6 +97,10 @@ module.exports = class Executable {
});
}
uninstall() {
return fse.removeAsync(BINARIES_DIR_PATH).then(() => this.serverless.cli.log('Uninstalled'));
}
rejectCommand(command) {
throw new this.serverless.classes.Error(
`\`${command}\` command is supported only in context of a standalone exacutable instance ` +

View File

@ -8,15 +8,21 @@ const isPathDependent =
const truthyStr = val => val && !['0', 'false', 'f', 'n', 'no'].includes(val.toLowerCase());
const { CI, ADBLOCK, SILENT } = process.env;
if (!truthyStr(CI) && !truthyStr(ADBLOCK) && !truthyStr(SILENT)) {
const messageTokens = ['Serverless Framework successfully installed!'];
if (isPathDependent) {
messageTokens.push(
'To start your first project, please open another terminal and run “serverless”.',
'You can uninstall at anytime by running “serverless uninstall”.'
);
} else {
messageTokens.push('To start your first project run “serverless”.');
}
process.stdout.write(
`${boxen(
chalk.yellow(
`Serverless Framework successfully installed!\nTo start your first project, ${
isPathDependent ? 'please open another terminal and ' : ''
}run serverless.`
),
{ padding: 1, margin: 1, borderColor: 'yellow' }
)}\n`
`${boxen(chalk.yellow(messageTokens.join('\n\n')), {
padding: 1,
margin: 1,
borderColor: 'yellow',
})}\n`
);
}