mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
fixed that AST is passed as a function parameter
This commit is contained in:
parent
17422e2f51
commit
7ccff61b73
@ -4,7 +4,6 @@ const fs = require('fs');
|
||||
const _ = require('lodash');
|
||||
const os = require('os');
|
||||
|
||||
const astObject = {};
|
||||
const findKeyChain = (astContent) => {
|
||||
let content = astContent;
|
||||
const chain = [
|
||||
@ -19,32 +18,35 @@ const findKeyChain = (astContent) => {
|
||||
return chain.reverse().join('.');
|
||||
};
|
||||
|
||||
const parseAST = (ymlAstContent) => {
|
||||
const parseAST = (ymlAstContent, astObject) => {
|
||||
let newAstObject = astObject || {};
|
||||
if (ymlAstContent.mappings && _.isArray(ymlAstContent.mappings)) {
|
||||
_.forEach(ymlAstContent.mappings, (v) => {
|
||||
if (v.key.kind === 0 && v.value.kind === 0) {
|
||||
astObject[findKeyChain(v)] = v.value;
|
||||
newAstObject[findKeyChain(v)] = v.value;
|
||||
} else if (v.key.kind === 0 && v.value.kind === 2) {
|
||||
astObject[findKeyChain(v)] = v.value;
|
||||
parseAST(v.value);
|
||||
newAstObject[findKeyChain(v)] = v.value;
|
||||
newAstObject = parseAST(v.value, newAstObject);
|
||||
} else if (v.key.kind === 0 && v.value.kind === 3) {
|
||||
astObject[findKeyChain(v)] = v.value;
|
||||
parseAST(v.value);
|
||||
newAstObject[findKeyChain(v)] = v.value;
|
||||
newAstObject = parseAST(v.value, newAstObject);
|
||||
}
|
||||
});
|
||||
} else if (ymlAstContent.items && _.isArray(ymlAstContent.items)) {
|
||||
_.forEach(ymlAstContent.items, (v, i) => {
|
||||
if (v.kind === 0) {
|
||||
const key = `${findKeyChain(ymlAstContent.parent)}[${i}]`;
|
||||
astObject[key] = v;
|
||||
newAstObject[key] = v;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return newAstObject;
|
||||
};
|
||||
|
||||
const addNewArrayItem = (ymlFile, pathInYml, newValue) => {
|
||||
const yamlContent = fs.readFileSync(ymlFile, 'utf8');
|
||||
parseAST(yaml.load(yamlContent), astObject);
|
||||
const astObject = parseAST(yaml.load(yamlContent));
|
||||
|
||||
if (astObject[pathInYml] && astObject[pathInYml].items) {
|
||||
let newArray = [];
|
||||
@ -76,7 +78,7 @@ const addNewArrayItem = (ymlFile, pathInYml, newValue) => {
|
||||
|
||||
const removeExistingArrayItem = (ymlFile, pathInYml, removeValue) => {
|
||||
const yamlContent = fs.readFileSync(ymlFile, 'utf8');
|
||||
parseAST(yaml.load(yamlContent), astObject);
|
||||
const astObject = parseAST(yaml.load(yamlContent));
|
||||
|
||||
if (astObject[pathInYml] && astObject[pathInYml].items) {
|
||||
const newArray = [];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user