mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
102 lines
2.7 KiB
JavaScript
102 lines
2.7 KiB
JavaScript
'use strict';
|
|
|
|
const JawsError = require('./jaws-error'),
|
|
JawsCLI = require('./utils/cli');
|
|
|
|
/**
|
|
* This is the base class that all JAWS plugins should extend.
|
|
*
|
|
*/
|
|
class JawsPlugin {
|
|
|
|
/**
|
|
*
|
|
* @param Jaws class object
|
|
* @param config object
|
|
*/
|
|
constructor(Jaws, config) {
|
|
this.Jaws = Jaws;
|
|
this.config = config;
|
|
}
|
|
|
|
/**
|
|
* Define your plugins name
|
|
*
|
|
* @returns {string}
|
|
*/
|
|
static getName() {
|
|
return 'com.yourdomain.' + JawsPlugin.name;
|
|
}
|
|
|
|
/**
|
|
* @returns {Promise} ES6 native upon completion of all registrations
|
|
*/
|
|
registerActions() {
|
|
//This is where you do something like below.
|
|
//NOTE: the order of the options should exactly match the order of the params to your `theAction` method
|
|
|
|
//this.Jaws.action(this.theAction.bind(this), {
|
|
// handler: 'deployLambda',
|
|
// description: 'deploys lambda code',
|
|
// context: 'lambda',
|
|
// contextAction: 'deploy',
|
|
// options: [
|
|
// {
|
|
// option: 'stage',
|
|
// shortcut: 's',
|
|
// description: 'Stage to deploy to'
|
|
// },
|
|
// ...
|
|
// ],
|
|
//});
|
|
|
|
return Promise.resolve();
|
|
}
|
|
|
|
/**
|
|
* @returns {Promise} ES6 native upon completion of all registrations
|
|
*/
|
|
registerHooks() {
|
|
return Promise.resolve();
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param promptSchema @see https://github.com/flatiron/prompt#prompting-with-validation-default-values-and-more-complex-properties
|
|
* @param overrides map {key: 'overrideValue'}
|
|
* @returns {Promise} containing answers by key
|
|
*/
|
|
promptInput(promptSchema, overrides) {
|
|
if (this.Jaws._interactive) { //CLI
|
|
let Prompter = JawsCLI.prompt();
|
|
Prompter.override = overrides;
|
|
return Prompter.getAsync(promptSchema);
|
|
} else if (this.Jaws.isWebInterface) {
|
|
//TODO: implement
|
|
return Promise.reject(new JawsError('Not implemented', JawsError.errorCodes.UNKNOWN));
|
|
} else {
|
|
return Promise.resolve(); //in non interactive mode. All options must be set programatically
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param message string
|
|
* @param choices [{key:"",value:"",label:""}]
|
|
* @param multi boolean
|
|
* @param doneLabel string optional
|
|
* @returns {Promise} containing [{value:'blah'},..]
|
|
*/
|
|
selectInput(message, choices, multi, doneLabel) {
|
|
if (this.Jaws._interactive) { //CLI
|
|
return JawsCLI.select(message, choices, multi, doneLabel);
|
|
} else if (this.Jaws.isWebInterface) {
|
|
//TODO: implement
|
|
return Promise.reject(new JawsError('Not implemented', JawsError.errorCodes.UNKNOWN));
|
|
} else {
|
|
return Promise.reject(new JawsError('You must specify all necessary options when in a non-interactive mode', JawsError.errorCodes.UNKNOWN));
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = JawsPlugin; |