mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
89 lines
1.5 KiB
JavaScript
89 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Serverless State Class
|
|
*/
|
|
|
|
const SError = require('./Error'),
|
|
SUtils = require('./utils/index'),
|
|
_ = require('lodash'),
|
|
path = require('path'),
|
|
fs = require('fs');
|
|
|
|
class ServerlessState {
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
|
|
constructor(Serverless) {
|
|
|
|
this._S = Serverless;
|
|
this.meta = new this._S.classes.Meta(this._S);
|
|
}
|
|
|
|
/**
|
|
* Load
|
|
* - Load from source (i.e., file system);
|
|
* - Returns promise
|
|
*/
|
|
|
|
load() {
|
|
|
|
let _this = this;
|
|
|
|
return _this._S.getProject().load()
|
|
.then(function() {
|
|
return _this.meta.load();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Save
|
|
* - Load from source (i.e., file system);
|
|
*/
|
|
|
|
save() {
|
|
|
|
let _this = this;
|
|
|
|
return _this._S.getProject().save({ deep: true })
|
|
.then(function() {
|
|
return _this.meta.save({ deep: true });
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Set
|
|
* - Set data from a javascript object
|
|
*/
|
|
|
|
set(data) {
|
|
this.meta = data.meta ? this.meta.set(data.meta) : this.meta;
|
|
this.project = data.project ? this._S.getProject().set(data.project, { deep: true }) : this._S.getProject();
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get
|
|
* - Returns clone of data
|
|
*/
|
|
|
|
get() {
|
|
return {
|
|
meta: this.meta.get(),
|
|
project: this._S.getProject().get()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get Meta
|
|
* - Returns meta data from state
|
|
*/
|
|
|
|
getMeta() {
|
|
return this.meta;
|
|
}
|
|
}
|
|
|
|
module.exports = ServerlessState; |