mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
CLI testing: some fixes
This commit is contained in:
parent
9f85c658a4
commit
56efd97f8a
@ -27,7 +27,7 @@ class Function extends SerializerFileSystem {
|
||||
this.name = data.name || 'function' + SUtils.generateShortId(6);
|
||||
this.customName = false;
|
||||
this.customRole = false;
|
||||
this.handler = './' + data.name +'/handler.handler';
|
||||
this.handler = data.name +'/handler.handler';
|
||||
this.timeout = 6;
|
||||
this.memorySize = 1024;
|
||||
this.custom = {
|
||||
|
||||
@ -165,16 +165,15 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
_prompt() {
|
||||
|
||||
let _this = this,
|
||||
sPath = _this.getSPathFromCwd(_this.S._projectPath),
|
||||
sPathParsed = SUtils.parseSPath(sPath),
|
||||
cwdType = SUtils.getCwdType(),
|
||||
functions;
|
||||
|
||||
if (sPathParsed.function) {
|
||||
functions = [_this.S.getProject().getFunction(sPathParsed.function)];
|
||||
} else if (sPathParsed.component) {
|
||||
functions = _this.S.getProject().getComponent(sPathParsed.component).getAllFunctions();
|
||||
if(cwdType.function) {
|
||||
functions = [_this.project.getFunction(cwdType.function)];
|
||||
} else if (cwdType.component) {
|
||||
functions = _this.project.getComponent(cwdType.component).getAllFunctions();
|
||||
} else {
|
||||
functions = _this.S.getProject().getAllFunctions();
|
||||
functions = _this.project.getAllFunctions();
|
||||
}
|
||||
|
||||
// Prepare function & endpoints choices
|
||||
@ -183,7 +182,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
_.each( functions, function(func){
|
||||
// Push function component as spacer
|
||||
choices.push({
|
||||
spacer: func.getComponent()
|
||||
spacer: func.getName()
|
||||
});
|
||||
|
||||
choices.push({
|
||||
|
||||
@ -64,8 +64,8 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
SCli.log(`${stages.length} stages ------------------------------`);
|
||||
stages.forEach(function(stage) {
|
||||
stagesNum++;
|
||||
let regions = _this.S.getProject().getAllRegions(stage);
|
||||
SCli.log(` |_ ${stage} (${regions.length} regions)`);
|
||||
let regions = _this.S.getProject().getAllRegions(stage.name);
|
||||
SCli.log(` |_ ${stage.name} (${regions.length} regions)`);
|
||||
|
||||
// list regions for stage
|
||||
regions.forEach(function(region) {
|
||||
|
||||
@ -172,8 +172,10 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
_this.regions = _this.evt.options.region ? [_this.evt.options.region] : _this.project.getAllRegions(_this.evt.options.stage).map(r => {return r.name;});
|
||||
|
||||
if (_this.evt.options.names.length) {
|
||||
_this.evt.options.names.forEach(function(endpointName) {
|
||||
_this.endpoints.push(_this.project.getEndpoint(endpointName.split('#')[0], endpointName.split('#')[1]));
|
||||
_this.evt.options.names.forEach(function(name) {
|
||||
let endpoint = _this.project.getEndpoint(name.split('#')[0], name.split('#')[1]);
|
||||
if (!endpoint) throw new SError(`Endpoint "${name}" doesn't exist in your project`);
|
||||
_this.endpoints.push(_this.project.getEndpoint(endpoint));
|
||||
});
|
||||
}
|
||||
|
||||
@ -197,10 +199,10 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
_this.endpoints = _this.project.getAllEndpoints();
|
||||
}
|
||||
|
||||
if (_this.endpoints.length === 0) throw new SError(`You don't have any endpoints in your project`);
|
||||
|
||||
// Validate Stage
|
||||
if (!_this.evt.options.stage) {
|
||||
throw new SError(`Stage is required`);
|
||||
}
|
||||
if (!_this.evt.options.stage) throw new SError(`Stage is required`);
|
||||
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
|
||||
@ -162,16 +162,16 @@ usage: serverless function create <function>`,
|
||||
|
||||
_this.functionName = _this.evt.options.path.split('/')[_this.evt.options.path.split('/').length - 1];
|
||||
|
||||
// Validate: Don't allow function creation within a function
|
||||
|
||||
if (_this.S.getProject().getFunction( _this.functionName )) {
|
||||
return BbPromise.reject(new SError('You cannot create a function in another function'));
|
||||
return BbPromise.reject(new SError(`Please choose a unique function name. You already have a function named "${_this.functionName}"`));
|
||||
}
|
||||
|
||||
// If component does not exist in project, throw error
|
||||
_this.evt.options.component = _this.S.getProject().getComponent( _this.evt.options.path.split('/')[0] );
|
||||
if (!_this.evt.options.component) {
|
||||
return BbPromise.reject(new SError(
|
||||
'Component (' + _this.evt.options.path.split('/')[0] + ') does not exist in project',
|
||||
'Component "' + _this.evt.options.path.split('/')[0] + '" does not exist in project',
|
||||
SError.errorCodes.INVALID_PROJECT_SERVERLESS
|
||||
));
|
||||
}
|
||||
|
||||
@ -188,13 +188,12 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
if (_this.evt.options.names.length) {
|
||||
_this.evt.options.names.forEach(function(name) {
|
||||
let func = _this.project.getFunction(name);
|
||||
if (!func) throw new SError(`Function "${name}" doesn't exist in your project`);
|
||||
_this.functions.push(_this.project.getFunction(name));
|
||||
});
|
||||
}
|
||||
|
||||
// Validate Stage
|
||||
if (!_this.evt.options.stage) throw new SError(`Stage is required`);
|
||||
|
||||
// If CLI and no function names targeted, deploy from CWD
|
||||
if (_this.S.cli &&
|
||||
!_this.evt.options.names.length &&
|
||||
@ -211,7 +210,7 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
// If --all is selected, load all paths
|
||||
if (_this.evt.options.all) {
|
||||
_this.evt.options.functions = _this.S.getProject().getAllFunctions();
|
||||
_this.functions = _this.S.getProject().getAllFunctions();
|
||||
}
|
||||
|
||||
// Ensure tmp folder exists in _meta
|
||||
@ -219,6 +218,11 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
fse.mkdirSync(_this.S.getProject().getRootPath('_meta', '_tmp'));
|
||||
}
|
||||
|
||||
if (_this.functions.length === 0) throw new SError(`You don't have any functions in your project`);
|
||||
|
||||
// Validate Stage
|
||||
if (!_this.evt.options.stage) throw new SError(`Stage is required`);
|
||||
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user