serverless-leo
Advanced tools
Comparing version 3.0.11 to 3.0.12-alpha
10
index.js
@@ -257,6 +257,7 @@ 'use strict' | ||
let file = getConfigFullPath(this.serverless, opts.file) | ||
if (state.generatedConfig || !fs.existsSync(file)) { | ||
if (state.generatedConfig) { | ||
return BbPromise.resolve() | ||
} | ||
state.generatedConfig = true | ||
return BbPromise.bind(this) | ||
@@ -285,4 +286,5 @@ .then(() => generateConfig(file)) | ||
let skipWebpack = (this.serverless.service.custom.leo || {}).skipWebpack !== false; | ||
// Setup the node runner | ||
if (opts.runner === 'node' && (this.serverless.service.provider.runtime || '').match(/^nodejs/)) { | ||
if (skipWebpack && opts.runner === 'node' && (this.serverless.service.provider.runtime || '').match(/^nodejs/)) { | ||
// Try and find the tsconfig build directory | ||
@@ -346,3 +348,5 @@ let tsConfigPath = path.resolve(process.cwd(), 'tsconfig.json') | ||
stack: (serverless.service.provider.stackParameters || []).reduce((all, one) => { | ||
all[one.ParameterKey] = one.ParameterValue; | ||
if (one != null) { | ||
all[one.ParameterKey] = one.ParameterValue; | ||
} | ||
return all; | ||
@@ -349,0 +353,0 @@ }, {}) |
@@ -58,3 +58,3 @@ /* eslint-disable space-before-function-paren */ | ||
let configOutputPath = filePath.replace(/\..*\.json$/, ext) | ||
let projectConfigTxt = fs.readFileSync(filePath).toString() | ||
let projectConfigTxt = fs.existsSync(filePath) && fs.readFileSync(filePath).toString() | ||
if (!projectConfigTxt) { | ||
@@ -86,2 +86,5 @@ return | ||
function expandConfig(projectConfig, path) { | ||
if (projectConfig == null || typeof projectConfig != "object") { | ||
return projectConfig; | ||
} | ||
let o = {} | ||
@@ -111,3 +114,7 @@ Object.entries(projectConfig).forEach(([key, value]) => { | ||
) { | ||
value = expandConfig(value, fieldPath) | ||
if (Array.isArray(value)) { | ||
value = value.map((a, i) => expandConfig(a, fieldPath.concat(i))) | ||
} else { | ||
value = expandConfig(value, fieldPath) | ||
} | ||
} | ||
@@ -185,6 +192,24 @@ o[key] = value | ||
let nextDepth = depth += spaces | ||
let r = Object.entries(field).map(([key, value]) => { | ||
return `${nextDepth}${key}: ${getType(value, nextDepth)};` | ||
}).join('\n') | ||
return `{\n${r}\n${depth.substring(0, depth.length - spacesLength)}}` | ||
if (Array.isArray(field)) { | ||
// Get unique set of types in the array | ||
let r = Array.from(new Set(Object.entries(field).map(([key, value]) => { | ||
return getType(value, nextDepth); | ||
}))); | ||
// Join them togethere if there is more than 1 | ||
let rLen = r.length; | ||
r = r.join("|"); | ||
if (rLen > 1) { | ||
r = `(${r})`; | ||
} | ||
// return array type | ||
return `${r}[]`; | ||
} else { | ||
let r = Object.entries(field).map(([key, value]) => { | ||
return `${nextDepth}${key}: ${getType(value, nextDepth)};` | ||
}).join('\n') | ||
return `{\n${r}\n${depth.substring(0, depth.length - spacesLength)}}` | ||
} | ||
} | ||
@@ -338,3 +363,3 @@ } else { | ||
} else if (serverless.service.custom.leo && serverless.service.custom.leo.configurationPath) { | ||
file = path.resolve(serverless.serviceDir, serverless.service.custom.leo.configurationPath) | ||
file = path.resolve(serverless.serviceDir || serverless.servicePath, serverless.service.custom.leo.configurationPath) | ||
} else { | ||
@@ -348,3 +373,3 @@ file = path.resolve(process.cwd(), './project-config.def.json') | ||
let output = {} | ||
Object.entries(config).forEach(([key, value]) => { | ||
Object.entries(config || {}).forEach(([key, value]) => { | ||
if (value != null && typeof value === 'object' && | ||
@@ -371,3 +396,3 @@ value.service != null && value.key != null && value.type != null) { | ||
let parts = value.key.split('.') | ||
parts.splice(1, 0, 'SecretString') | ||
parts = [parts[0], 'SecretString'].concat(parts.splice(1).join(".")); | ||
v = { 'Fn::Sub': `{{resolve:secretsmanager:${parts.join(':')}}}` } | ||
@@ -403,3 +428,4 @@ } | ||
let configFromCache = false; | ||
let configFileCache = path.resolve(serverless.config.serviceDir, `.rsf/config-${fullStage}.json`); | ||
let serviceDir = serverless.config.serviceDir || serverless.config.servicePath; | ||
let configFileCache = path.resolve(serviceDir, `.rsf/config-${fullStage}.json`); | ||
if (fs.existsSync(configFileCache)) { | ||
@@ -438,3 +464,3 @@ let stat = fs.statSync(configFileCache); | ||
let busConfigFromCache = false; | ||
let busConfigFileCache = path.resolve(serverless.config.serviceDir, `.rsf/bus-config-${fullStage}.json`); | ||
let busConfigFileCache = path.resolve(serviceDir, `.rsf/bus-config-${fullStage}.json`); | ||
if (fs.existsSync(busConfigFileCache)) { | ||
@@ -531,7 +557,9 @@ let stat = fs.statSync(busConfigFileCache); | ||
...(serverless.service.provider.stackParameters || []).reduce((all, one) => { | ||
let paramDef = (serverless.service.resources.Parameters || {})[one.ParameterKey]; | ||
if (paramDef && paramDef.Type.match(/AWS::SSM::Parameter/)) { | ||
all[one.ParameterKey] = `{{resolve:ssm:${one.ParameterValue}}}` | ||
} else { | ||
all[one.ParameterKey] = one.ParameterValue; | ||
if (one != null) { | ||
let paramDef = (serverless.service.resources.Parameters || {})[one.ParameterKey]; | ||
if (paramDef && paramDef.Type.match(/AWS::SSM::Parameter/)) { | ||
all[one.ParameterKey] = `{{resolve:ssm:${one.ParameterValue}}}` | ||
} else { | ||
all[one.ParameterKey] = one.ParameterValue; | ||
} | ||
} | ||
@@ -594,5 +622,6 @@ return all; | ||
const leoStack = custom.leoStack || serverless.service.custom.leoStack | ||
const useSecretsManager = serverless.service.custom.leo.rsfConfigType === 'secretsmanager' | ||
const useSecretsManager = ((serverless.service.custom || {}).leo || {}).rsfConfigType === 'secretsmanager' | ||
let { output, lookups, permissions } = getConfigReferences(config, useSecretsManager) | ||
let hasConfig = Object.keys(output || {}).length > 0; | ||
@@ -725,3 +754,3 @@ let params = {}; | ||
return { | ||
env: Object.assign({ | ||
env: Object.assign(hasConfig ? { | ||
RSF_CONFIG: useSecretsManager ? rsfConfigName : { | ||
@@ -732,3 +761,3 @@ 'Fn::Sub': [ | ||
} | ||
}, useSecretsManager ? { | ||
} : {}, useSecretsManager ? { | ||
// Add RStreams config resource | ||
@@ -807,3 +836,3 @@ RSTREAMS_CONFIG_SECRET: { | ||
params: params, | ||
resources: useSecretsManager ? { | ||
resources: (hasConfig && useSecretsManager) ? { | ||
RSFConfig: { | ||
@@ -810,0 +839,0 @@ Type: 'AWS::SecretsManager::Secret', |
@@ -90,4 +90,8 @@ const fs = require('fs') | ||
} | ||
if (config.id) { | ||
id = config.id; | ||
} | ||
// Only add the queue to the bot name if there are multiple events and no prefix | ||
if (source && !botPrefix && leoEvents.length > 1) { | ||
else if (source && !botPrefix && leoEvents.length > 1) { | ||
id = `${serviceName}-${stage}-${botPrefix}${source}-${ymlFunctionName}${botSuffix}` | ||
@@ -338,2 +342,23 @@ } else { | ||
// Add local invocation overrides | ||
Object.entries({ ...process.env, ...serverless.pluginManager.cliOptions }).forEach(([key, value]) => { | ||
let command = key.match(/^leo[_-](event|env)[_-](.*)$/i); | ||
if (command) { | ||
let obj = process.env; | ||
let field = command[2]; | ||
if (command[1] === "event") { | ||
let path = field.split("."); | ||
field = path.pop(); | ||
obj = path.reduce((a, b) => a[b] = a[b] || {}, event); | ||
} | ||
if (value.match(/^\d+(?:\.\d*)?$/)) { | ||
value = parseFloat(value) | ||
} | ||
obj[field] = value; | ||
} | ||
}); | ||
// Create the BotInvocationEvent structure | ||
@@ -340,0 +365,0 @@ event.botId = botInfo.id |
{ | ||
"name": "serverless-leo", | ||
"version": "3.0.11", | ||
"version": "3.0.12-alpha", | ||
"description": "Serverless plugin for leo microservices", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
145152
2866
1
28