serverless/lib/Serverless.js
Philipp Muens 39d30b3ca0 Add automatic servicePath detection functionality
The service directory will be automatically detected if the users CWD is a valid
Serverless service directory.
2016-05-26 14:34:56 +02:00

70 lines
1.7 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(() => {
this.pluginManager.loadAllPlugins();
this.cli = new CLI(
this,
this.config.interactive,
this.pluginManager.getPlugins()
);
this.inputToBeProcessed = this.cli.processInput();
});
}
run() {
if (this.inputToBeProcessed.commands.length) {
this.pluginManager.run(
this.inputToBeProcessed.commands,
this.inputToBeProcessed.options
);
}
}
getVersion() {
return this.version;
}
}
module.exports = Serverless;