From f86b55d770fef04791ea02f807fbb2189448ee14 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 24 Sep 2015 10:36:14 +1000 Subject: [PATCH] Reworked the recursive search for cf. My resources werent being updated as the readdirRecursiveAsync was only ever returning a top level stage direcotry and not descending correctly. --- lib/commands/module_install.js | 58 ++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/lib/commands/module_install.js b/lib/commands/module_install.js index 6095c33cb..b36281266 100644 --- a/lib/commands/module_install.js +++ b/lib/commands/module_install.js @@ -197,33 +197,35 @@ CMD.prototype._saveCfTemplate = Promise.method(function(modPath) { } //Update every resources-cf.json for every stage and region. Deep breath... - return wrench.readdirRecursiveAsync(projectCfPath) - .then(function(files) { - files.forEach(function(file) { - if (utils.endsWith(file, 'resources-cf.json')) { - var regionStageResourcesCfJson = utils.readAndParseJsonSync(file); + return new Promise(function(resolve, reject) { + resolve(wrench.readdirSyncRecursive(projectCfPath)) + }).then(function(files) { + files.forEach(function(file) { + file = path.join(projectCfPath, file); + if (utils.endsWith(file, 'resources-cf.json')) { + var regionStageResourcesCfJson = utils.readAndParseJsonSync(file); - cfExtensionPoints.LambdaIamPolicyDocumentStatements.forEach(function(policyStmt) { - regionStageResourcesCfJson.IamPolicyLambda.Properties.PolicyDocument.Statement.push(policyStmt); - }); - - cfExtensionPoints.ApiGatewayIamPolicyDocumentStatements.forEach(function(policyStmt) { - regionStageResourcesCfJson.IamPolicyApiGateway.Properties.PolicyDocument.Statement.push(policyStmt); - }); - - Object.keys(cfExtensionPoints.Resources).forEach(function(resourceKey) { - if (regionStageResourcesCfJson.Resources[resourceKey]) { - throw new JawsError( - 'Resource key ' + resourceKey + ' already defined in ' + file, - JawsError.errorCodes.UNKNOWN - ); - } - - regionStageResourcesCfJson.Resources[resourceKey] = cfExtensionPoints.Resources[resourceKey]; - }); - - utils.writeFile(file, JSON.stringify(regionStageResourcesCfJson, null, 2)); - } + cfExtensionPoints.LambdaIamPolicyDocumentStatements.forEach(function(policyStmt) { + regionStageResourcesCfJson.IamPolicyLambda.Properties.PolicyDocument.Statement.push(policyStmt); }); - }); -}); \ No newline at end of file + + cfExtensionPoints.ApiGatewayIamPolicyDocumentStatements.forEach(function(policyStmt) { + regionStageResourcesCfJson.IamPolicyApiGateway.Properties.PolicyDocument.Statement.push(policyStmt); + }); + + Object.keys(cfExtensionPoints.Resources).forEach(function(resourceKey) { + if (regionStageResourcesCfJson.Resources[resourceKey]) { + throw new JawsError( + 'Resource key ' + resourceKey + ' already defined in ' + file, + JawsError.errorCodes.UNKNOWN + ); + } + + regionStageResourcesCfJson.Resources[resourceKey] = cfExtensionPoints.Resources[resourceKey]; + }); + + utils.writeFile(file, JSON.stringify(regionStageResourcesCfJson, null, 2)); + } + }); + }); +});