serverless-leo
Advanced tools
Comparing version 1.1.2 to 1.1.3
'use strict' | ||
var path = require('path') | ||
const utils = require('./lib/utils') | ||
const fs = require('fs') | ||
const parse = require('parse-gitignore') | ||
const findUp = require('find-up') | ||
const { | ||
findResourceInDirectoryInfosFactory, | ||
folderResourceReducer, | ||
getContentFactory | ||
} = require('./includeContent') | ||
// TODO: Recursive | ||
// TODO: Ignore same as .gitignore OR make ignoreFunctionPatterns & ignoreResourcePatterns OR BOTH | ||
// TODO: Use custom params (multiple folders & patterns) | ||
module.exports = (serverless) => { | ||
const functionsFolderDirInfo = utils.getDirInfo('bots') | ||
// console.log(serverless.service.custom) | ||
// serverless.service.custom.functionFolders | ||
// serverless.service.custom.resourceFolders | ||
// serverless.service.custom.matchFunctionPatterns | ||
// serverless.service.custom.matchResourcePatterns | ||
const functionYmls = {} | ||
functionsFolderDirInfo.forEach(dirInfo => { | ||
if (dirInfo.isDir) { | ||
const functionFolderDirInfo = utils.getDirInfo(dirInfo.path) | ||
functionFolderDirInfo.forEach(d => { | ||
const ymlFound = d.isFile && d.file === 'serverless.yml' | ||
if (ymlFound) { | ||
var absolutePath = path.resolve(d.path) | ||
const functionYml = serverless.utils.readFileSync(absolutePath) | ||
if (functionYml) { | ||
const functionKeys = Object.keys(functionYml) | ||
if (!functionKeys) throw new Error('Function definition missing.') | ||
if (functionKeys.length > 1) throw new Error('Duplicate function definition.') | ||
const functionIdentifier = functionKeys[0] | ||
// Add to Functions | ||
if (!(functionIdentifier in serverless.service.functions)) { | ||
serverless.cli.log(`Including function definition: ${d.path}`) | ||
Object.assign(functionYmls, functionYml) | ||
} else { | ||
serverless.cli.log(`WARNING: Resource ${functionIdentifier} already defined!!! (Have you defined ${functionIdentifier} multiple times?)`) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
}) | ||
return functionYmls | ||
module.exports = async (serverless) => { | ||
const gitignorepath = await findUp('.gitignore') | ||
const ignoreResourcePatterns = parse(fs.readFileSync(gitignorepath)) | ||
const { functionFolders, matchFunctionPatterns } = serverless.service.custom | ||
const getContent = getContentFactory(serverless) | ||
const findResourcesInDirInfos = findResourceInDirectoryInfosFactory(matchFunctionPatterns, ignoreResourcePatterns, getContent) | ||
return functionFolders.reduce(folderResourceReducer(findResourcesInDirInfos), {}) | ||
} |
@@ -7,3 +7,2 @@ 'use strict' | ||
const path = require('path') | ||
const gatherBots = require('./lib/gatherBots') | ||
const validate = require('./lib/validate') | ||
@@ -47,3 +46,2 @@ const compileLeo = require('./lib/leo') | ||
this, | ||
gatherBots, | ||
validate, | ||
@@ -50,0 +48,0 @@ compileLeo |
'use strict' | ||
const _ = require('lodash') | ||
const { cloneDeep, times } = require('lodash') | ||
const BbPromise = require('bluebird') | ||
@@ -36,7 +36,7 @@ | ||
if (registrations.length === 0) { | ||
registrations.push(_.cloneDeep(customInstall)) | ||
registrations.push(cloneDeep(customInstall)) | ||
} | ||
let currentRegister = registrations[registrations.length - 1] | ||
if (Object.keys(currentRegister.Properties).length > 100) { | ||
currentRegister = _.cloneDeep(customInstall) | ||
currentRegister = cloneDeep(customInstall) | ||
registrations.push(currentRegister) | ||
@@ -53,3 +53,3 @@ } | ||
const logicalId = this.provider.naming.getLambdaLogicalId(ymlFunctionName) | ||
const botNumbers = _.times(functionObj.botCount || 1, Number) | ||
const botNumbers = times(functionObj.botCount || 1, Number) | ||
@@ -83,3 +83,3 @@ botNumbers.forEach(botNumber => { | ||
botId = `${this.serverless.service.service}-${stage}-${ymlFunctionName}_${sourceQueue}${botSuffix}` | ||
const installEventProperty = _.cloneDeep(installProperty) | ||
const installEventProperty = cloneDeep(installProperty) | ||
installEventProperty.id = botId | ||
@@ -86,0 +86,0 @@ if (config && config.name) { |
@@ -10,2 +10,5 @@ const fs = require('fs') | ||
const getDirInfo = (folderPath) => { | ||
const dirExists = fs.existsSync(folderPath) | ||
if (!dirExists) return [] | ||
return fs.readdirSync(folderPath).map(f => { | ||
@@ -12,0 +15,0 @@ const newPath = `${folderPath}/${f}` |
'use strict' | ||
const _ = require('lodash') | ||
const { forEach } = require('lodash') | ||
@@ -22,5 +22,5 @@ module.exports = { | ||
_.forEach(this.serverless.service.functions, functionObject => { | ||
forEach(this.serverless.service.functions, functionObject => { | ||
if (functionObject.events) { | ||
_.forEach(functionObject.events, (functionEvent, functionName) => { | ||
forEach(functionObject.events, (functionEvent, functionName) => { | ||
if (typeof functionEvent.leo === 'object') { | ||
@@ -27,0 +27,0 @@ if (!functionEvent.leo.queue) { |
{ | ||
"name": "serverless-leo", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Serverless plugin for leo microservices", | ||
@@ -32,3 +32,6 @@ "main": "index.js", | ||
"bluebird": "^3.5.4", | ||
"lodash": "^4.17.11" | ||
"find-up": "^3.0.0", | ||
"ignore": "^5.1.1", | ||
"lodash": "^4.17.11", | ||
"parse-gitignore": "^1.0.1" | ||
}, | ||
@@ -35,0 +38,0 @@ "devDependencies": { |
'use strict' | ||
const expect = require('chai').expect | ||
const _ = require('lodash') | ||
const { cloneDeep } = require('lodash') | ||
const testServerless = require('./testServerless') | ||
@@ -29,3 +29,3 @@ | ||
const sls = testServerless() | ||
const lambda = _.cloneDeep(helloNodeWorldLambda) | ||
const lambda = cloneDeep(helloNodeWorldLambda) | ||
lambda.events = [ | ||
@@ -42,3 +42,3 @@ { | ||
const sls = testServerless() | ||
const lambda = _.cloneDeep(helloNodeWorldLambda) | ||
const lambda = cloneDeep(helloNodeWorldLambda) | ||
lambda.leoCron = '* * * * * *' | ||
@@ -51,3 +51,3 @@ sls.serverless.service.functions.helloNodeWorld = lambda | ||
const sls = testServerless() | ||
const lambda = _.cloneDeep(helloNodeWorldLambda) | ||
const lambda = cloneDeep(helloNodeWorldLambda) | ||
lambda.events = [ | ||
@@ -65,3 +65,3 @@ { | ||
const sls = testServerless() | ||
const lambda = _.cloneDeep(helloNodeWorldLambda) | ||
const lambda = cloneDeep(helloNodeWorldLambda) | ||
lambda.events = [ | ||
@@ -81,3 +81,3 @@ { | ||
const sls = testServerless() | ||
const lambda = _.cloneDeep(helloNodeWorldLambda) | ||
const lambda = cloneDeep(helloNodeWorldLambda) | ||
lambda.events = [ | ||
@@ -98,3 +98,3 @@ { | ||
const sls = testServerless() | ||
const lambda = _.cloneDeep(helloNodeWorldLambda) | ||
const lambda = cloneDeep(helloNodeWorldLambda) | ||
lambda.events = [ | ||
@@ -122,3 +122,3 @@ { | ||
const sls = testServerless() | ||
const lambda = _.cloneDeep(helloNodeWorldLambda) | ||
const lambda = cloneDeep(helloNodeWorldLambda) | ||
lambda.events = [ | ||
@@ -137,3 +137,3 @@ { | ||
const sls = testServerless() | ||
const lambda = _.cloneDeep(helloNodeWorldLambda) | ||
const lambda = cloneDeep(helloNodeWorldLambda) | ||
lambda.events = [ | ||
@@ -140,0 +140,0 @@ { |
'use strict' | ||
const _ = require('lodash') | ||
const { cloneDeep } = require('lodash') | ||
const naming = require('../../node_modules/serverless/lib/plugins/aws/lib/naming') | ||
@@ -223,3 +223,3 @@ const srcLeo = require('../../lib/leo') | ||
module.exports = () => { | ||
const serverless = _.cloneDeep(testServerless) | ||
const serverless = cloneDeep(testServerless) | ||
@@ -226,0 +226,0 @@ // hand waved functions |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
36022
14
785
5
5
+ Addedfind-up@^3.0.0
+ Addedignore@^5.1.1
+ Addedparse-gitignore@^1.0.1
+ Addedfind-up@3.0.0(transitive)
+ Addedignore@5.3.1(transitive)
+ Addedlocate-path@3.0.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@3.0.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedparse-gitignore@1.0.1(transitive)
+ Addedpath-exists@3.0.0(transitive)