mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
ServerlessState: create class and add to Serverless instance
This commit is contained in:
parent
bbfe50531a
commit
4e9d65e253
@ -28,7 +28,8 @@ class Serverless {
|
||||
constructor(config) {
|
||||
|
||||
// Add version
|
||||
this._version = require('./../package.json').version;
|
||||
this._version = require('./../package.json').version;
|
||||
this._run = false;
|
||||
|
||||
// Set Default Config
|
||||
this.config = {
|
||||
@ -46,6 +47,7 @@ class Serverless {
|
||||
this.hooks = {};
|
||||
this.commands = {};
|
||||
this.classes = {
|
||||
State: require('./ServerlessState'),
|
||||
Meta: require('./ServerlessMeta'),
|
||||
Project: require('./ServerlessProject'),
|
||||
Component: require('./ServerlessComponent'),
|
||||
@ -158,7 +160,6 @@ class Serverless {
|
||||
|
||||
// Set CLI
|
||||
_this.cli = {
|
||||
set: false,
|
||||
context: null,
|
||||
action: null,
|
||||
options: {},
|
||||
@ -314,12 +315,20 @@ class Serverless {
|
||||
|
||||
let _this = this;
|
||||
|
||||
// If CLI and first Action, prepare evt object
|
||||
if (_this.cli && !_this.cli.set) {
|
||||
evt = {
|
||||
options: extend(_this.cli.options, _this.cli.params)
|
||||
};
|
||||
_this.cli.set = true;
|
||||
// If first Action, init
|
||||
if (!_this._run) {
|
||||
|
||||
// Init State
|
||||
_this.S.state = new _this.S.classes.State(_this.S);
|
||||
|
||||
// If CLI command, init CLI
|
||||
if (_this.cli) {
|
||||
evt = {
|
||||
options: extend(_this.cli.options, _this.cli.params)
|
||||
};
|
||||
}
|
||||
|
||||
_this._run = true;
|
||||
}
|
||||
|
||||
// If not CLI and no options object, auto-set options
|
||||
|
||||
57
lib/ServerlessState.js
Normal file
57
lib/ServerlessState.js
Normal file
@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Serverless State Class
|
||||
*/
|
||||
|
||||
const SError = require('./ServerlessError'),
|
||||
SUtils = require('./utils/index'),
|
||||
_ = require('lodash'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
BbPromise = require('bluebird');
|
||||
|
||||
class ServerlessState
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
constructor(Serverless) {
|
||||
this.S = Serverless;
|
||||
this.load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load
|
||||
* - Load from source (i.e., file system);
|
||||
*/
|
||||
|
||||
load() {
|
||||
this.data = {
|
||||
meta: this.S.classes.Meta(this.S),
|
||||
project: this.S.classes.Project(this.S)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get
|
||||
* - Returns clone of data
|
||||
*/
|
||||
|
||||
get() {
|
||||
return _.cloneDeep(this.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set
|
||||
* - Set data
|
||||
*/
|
||||
|
||||
set(data) {
|
||||
this.data = _.merge(this.data, data);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ServerlessMeta;
|
||||
Loading…
x
Reference in New Issue
Block a user