dash deploy shows functions and endpoints according to cwd

This commit is contained in:
Eslam A. Hefnawy 2016-01-06 21:24:52 +02:00
parent 5275f2b3b0
commit c82e0cee53

View File

@ -103,8 +103,10 @@ module.exports = function(SPlugin, serverlessPath) {
_this.evt.options.aliasRestApi = _this.evt.options.aliasRestApi ? _this.evt.options.aliasRestApi : null;
_this.evt.options.functionPaths = [];
_this.evt.options.endpointPaths = [];
_this.evt.data.deployedFunctions = {};
_this.evt.data.deployedEndpoints = {};
_this.evt.options.functionPathsDash = [];
_this.evt.options.endpointPathsDash = [];
_this.evt.data.deployedFunctions = {};
_this.evt.data.deployedEndpoints = {};
// Instantiate Classes
_this.project = new _this.S.classes.Project(_this.S);
@ -154,6 +156,41 @@ module.exports = function(SPlugin, serverlessPath) {
return BbPromise.reject(new SError('Sorry, this is only available in interactive mode'));
}
// get functions/endpoints according to CWD.
let CWD = process.cwd(),
isModule = SUtils.fileExistsSync(path.join(CWD, 's-module.json')) || SUtils.fileExistsSync(path.join(CWD, '..', 's-module.json')),
isFunction = SUtils.fileExistsSync(path.join(CWD, 's-function.json'));
if (isModule) {
let moduleName;
try {
moduleName = SUtils.readAndParseJsonSync(path.join(CWD, 's-module.json')).name;
} catch (e) {
moduleName = SUtils.readAndParseJsonSync(path.join(CWD, '..', 's-module.json')).name;
}
let functionList = fs.readdirSync(path.join(_this.S.config.projectPath, 'back', 'modules', moduleName, 'functions'));
functionList.forEach(function(functionName) {
_this.evt.options.functionPathsDash.push(moduleName + path.sep + functionName);
let FunctionInstance = new _this.S.classes.Function(_this.S, {module: moduleName, function: functionName});
FunctionInstance.data.endpoints.forEach(function(endpoint) {
_this.evt.options.endpointPathsDash.push(moduleName + path.sep + functionName + '@' + endpoint.path + '~' + endpoint.method);
});
});
} else if (isFunction) {
let functionName = SUtils.readAndParseJsonSync(path.join(CWD, 's-function.json')).name;
let moduleName = SUtils.readAndParseJsonSync(path.join(CWD, '..', '..', 's-module.json')).name;
_this.evt.options.functionPathsDash.push(moduleName + path.sep + functionName);
let FunctionInstance = new _this.S.classes.Function(_this.S, {module: moduleName, function: functionName});
FunctionInstance.data.endpoints.forEach(function(endpoint) {
_this.evt.options.endpointPathsDash.push(moduleName + path.sep + functionName + '@' + endpoint.path + '~' + endpoint.method);
});
}
return BbPromise.resolve(_this.evt);
}
@ -165,7 +202,11 @@ module.exports = function(SPlugin, serverlessPath) {
let _this = this;
return BbPromise.resolve(_this.project.getFunctions())
// Prepare functions
let getFunctionsOptions = {
paths: _this.evt.options.functionPathsDash
};
return BbPromise.resolve(_this.project.getFunctions(getFunctionsOptions))
.then(function (functions) {
_this.functions = functions;
});
@ -179,7 +220,10 @@ module.exports = function(SPlugin, serverlessPath) {
let _this = this;
return BbPromise.resolve(_this.project.getEndpoints())
let getEndpointsOptions = {
paths: _this.evt.options.endpointPathsDash
};
return BbPromise.resolve(_this.project.getEndpoints(getEndpointsOptions))
.then(function (endpoints) {
_this.endpoints = endpoints;
});