Merge pull request #386 from visualasparagus/master

Centralized and fixed event.json loading
This commit is contained in:
Austen 2015-12-15 17:13:49 -08:00
commit fa5d8bea80

View File

@ -69,6 +69,7 @@ class FunctionRun extends SPlugin {
return _this._loadFunction(evt)
.bind(_this)
.then(_this._loadTestEvent)
.then(_this._runFunction)
.then(function(evt) {
return evt;
@ -97,12 +98,6 @@ class FunctionRun extends SPlugin {
// Load event object
evt.function = functions[0];
let eventPath = evt.function.pathFunction.replace('s-function.json', '');
if (fs.existsSync(path.join(eventPath, 'event.json'))) {
evt.function.event = SUtils.readAndParseJsonSync(path.join(eventPath, 'event.json'));
} else {
evt.function.event = {};
}
// Return
return evt;
@ -122,20 +117,14 @@ class FunctionRun extends SPlugin {
// Add function to evt
for (let i = 0; i < functions.length; i++) {
SUtils.sDebug(functions[i].name+" :: "+evt.name);
if (functions[i].name === evt.name || functions[i].name.toLowerCase() === evt.name) {
evt.function = functions[i];
}
}
if (!evt.function) throw new SError(`Could not find a function with the name ${evt.name}`);
// Load event object
let eventPath = evt.function.pathFunction.replace('s-function.json', '');
if (fs.existsSync(path.join(eventPath, 'event.json'))) {
evt.function.event = SUtils.readAndParseJsonSync(path.join(eventPath, 'event.json'));
} else {
evt.function.event = {};
}
// Return
return evt;
});
@ -155,12 +144,6 @@ class FunctionRun extends SPlugin {
evt.function = selected[0];
let eventPath = evt.function.pathFunction.replace('s-function.json', '');
if (fs.existsSync(path.join(eventPath, 'event.json'))) {
evt.function.event = SUtils.readAndParseJsonSync(path.join(eventPath, 'event.json'));
} else {
evt.function.event = {};
}
return evt;
});
}
@ -169,6 +152,24 @@ class FunctionRun extends SPlugin {
throw new SError(`No function specified`);
}
/**
* Populate the test event from the correct event.json file
*/
_loadTestEvent(evt) {
let _this = this,
eventPath = path.join(_this.S._projectRootPath, evt.function.pathFunction.replace('s-function.json', ''), 'event.json');
if (fs.existsSync(eventPath)) {
evt.function.event = SUtils.readAndParseJsonSync(eventPath);
} else {
evt.function.event = {};
}
return evt;
}
/**
* Run Function By Runtime
*/
@ -196,4 +197,4 @@ class FunctionRun extends SPlugin {
}
}
module.exports = FunctionRun;
module.exports = FunctionRun;