mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
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:
parent
5b5371b0af
commit
f86b55d770
@ -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));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user