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.
This commit is contained in:
Jacob Evans 2015-09-24 10:36:14 +10:00
parent 5b5371b0af
commit f86b55d770

View File

@ -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);
});
});
});
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));
}
});
});
});