mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
feat: uninstall command for installed binaries
This commit is contained in:
parent
c4efd66e4e
commit
53e596fa67
@ -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) {
|
||||
|
||||
@ -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 ` +
|
||||
|
||||
@ -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`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user