mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
So that the loaded plugins are not passed into the constructor. This is a preparation for the upcoming task to move the options to the plugins constructor rather than the hook which is run.
77 lines
2.1 KiB
JavaScript
77 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
require('shelljs/global');
|
|
|
|
const CLI = require('./classes/CLI');
|
|
const Config = require('./classes/Config');
|
|
const YamlParser = require('./classes/YamlParser');
|
|
const PluginManager = require('./classes/PluginManager');
|
|
const Utils = require('./classes/Utils');
|
|
const Service = require('./classes/Service');
|
|
const SError = require('./classes/Error');
|
|
const Version = require('./../package.json').version;
|
|
|
|
class Serverless {
|
|
constructor(config) {
|
|
let configObject = config;
|
|
configObject = configObject || {};
|
|
|
|
this.version = Version;
|
|
|
|
this.yamlParser = new YamlParser(this);
|
|
this.pluginManager = new PluginManager(this);
|
|
this.utils = new Utils(this);
|
|
this.service = new Service(this);
|
|
|
|
// use the servicePath from the options or try to find it in the CWD
|
|
configObject.servicePath = configObject.servicePath || this.utils.findServicePath();
|
|
|
|
this.config = new Config(this, configObject);
|
|
|
|
this.classes = {};
|
|
this.classes.CLI = CLI;
|
|
this.classes.YamlParser = YamlParser;
|
|
this.classes.PluginManager = PluginManager;
|
|
this.classes.Utils = Utils;
|
|
this.classes.Service = Service;
|
|
this.classes.Error = SError;
|
|
}
|
|
|
|
init() {
|
|
return this.service.load()
|
|
.then(() => {
|
|
// create a new CLI instance
|
|
this.cli = new CLI(
|
|
this,
|
|
this.config.interactive
|
|
);
|
|
|
|
// get an array of commands and options that should be processed
|
|
this.inputToBeProcessed = this.cli.processInput();
|
|
|
|
// load all plugins
|
|
this.pluginManager.loadAllPlugins();
|
|
|
|
// give the CLI the plugins so that it can print out plugin information
|
|
// such as options when the user enters --help
|
|
this.cli.setLoadedPlugins(this.pluginManager.getPlugins);
|
|
});
|
|
}
|
|
|
|
run() {
|
|
if (this.inputToBeProcessed.commands.length) {
|
|
// trigger the plugin lifecycle when there's something which should be processed
|
|
this.pluginManager.run(
|
|
this.inputToBeProcessed.commands,
|
|
this.inputToBeProcessed.options
|
|
);
|
|
}
|
|
}
|
|
|
|
getVersion() {
|
|
return this.version;
|
|
}
|
|
}
|
|
|
|
module.exports = Serverless;
|