serverless/lib/plugins/install.js
Mariusz Nowak 2294a4b4cb refactor(CLI): Move lifecycles definition to commands schema
It's needed to be able to process commands as introduced by plugins without a need of processing Serverless instance
2021-03-24 11:50:24 +01:00

43 lines
990 B
JavaScript

'use strict';
const BbPromise = require('bluebird');
const cliCommandsSchema = require('../cli/commands-schema');
const download = require('../utils/downloadTemplateFromRepo');
class Install {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.commands = {
install: {
...cliCommandsSchema.get('install'),
},
};
this.hooks = {
'install:install': async () => BbPromise.bind(this).then(this.install),
};
}
async install() {
return download
.downloadTemplateFromRepo(this.options.url, this.options.name)
.then((serviceName) => {
const message = [
`Successfully installed "${serviceName}" `,
`${
this.options.name && this.options.name !== serviceName
? `as "${this.options.name}"`
: ''
}`,
].join('');
this.serverless.cli.log(message);
});
}
}
module.exports = Install;