SerializerFileSystem: sstart Templates

This commit is contained in:
Austen Collins 2016-02-19 18:06:03 -08:00
parent 05662606cb
commit 4ddea440eb
2 changed files with 54 additions and 5 deletions

View File

@ -459,7 +459,7 @@ class SerializerFileSystem {
* Serialize Variables
*/
serializeStage(variables) {
serializeVariables(variables) {
let _this = this;
// Load component, then traverse component dirs to get all functions
@ -472,6 +472,55 @@ class SerializerFileSystem {
JSON.stringify(variables.toObject(), null, 2));
});
}
/**
* Deserialize Templates
*/
deserializeTemplates(templates) {
let _this = this;
// Load component, then traverse component dirs to get all functions
return BbPromise.try(function() {
// Validate: Check project path is set
if (!_this._S.hasProject()) throw new SError('Templates could not be loaded because no project path has been set on Serverless instance');
// Validate: Check exists
if (!SUtils.fileExistsSync(templates._config.filePath)) {
throw new SError('Templates could not be loaded because it does not exist in your project');
}
// Set Data
templates.fromObject(SUtils.readFileSync(templates._config.filePath));
})
.then(function() {
// TODO: Look up each parent until s-project.json is found and add parent templates via addParent()
})
}
/**
* Serialize Templates
*/
// TODO: Finish
serializeTemplates(templates) {
let _this = this;
// Load component, then traverse component dirs to get all functions
return BbPromise.try(function() {
// Validate: Check project path is set
if (!_this._S.hasProject()) throw new SError('Variables could not be saved because no project path has been set on Serverless instance');
return SUtils.writeFile(variables._config.filePath,
JSON.stringify(variables.toObject(), null, 2));
});
}
}
module.exports = SerializerFileSystem;

View File

@ -16,12 +16,12 @@ class Templates {
}
/**
* Set Parent
* - Optional: For file system serializer
* Format: { path: "", parent: {} }
* Add Parent
* - Parent templates which this template extends
* - Format: {parent}
*/
_setParent(parent) {
addParent(parent) {
}