Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pathInObjectTree.push(currentNode);
for (let i = pathInObjectTree.length - 1; i > 0; i--) {
if (_.keys(pathInObjectTree[i]).length > 0) {
break;
}
_.unset(pathInObjectTree[i - 1], pathInYmlArray[i - 1]);
}
}
const headObjectPath = _.head(pathInYmlArray);
let newText = '';
if (plainObject[headObjectPath]) {
const newObject = {};
newObject[headObjectPath] = plainObject[headObjectPath];
newText = yaml.dump(newObject);
}
const beginning = yamlContent.substring(0, astObject[headObjectPath].parent.key.startPosition);
const end = yamlContent.substring(astObject[pathInYml].endPosition, yamlContent.length);
return fs.writeFileAsync(ymlFile, `${beginning}${newText}${end}`);
}
return BbPromise.resolve();
});
}
}
const arrayPropertyName = _.last(pathInYmlArray);
let arrayProperty = currentNode[arrayPropertyName];
if (_.isUndefined(arrayProperty) || _.isArray(arrayProperty)) {
arrayProperty = arrayProperty || [];
} else {
throw new Error(`${arrayProperty} can only be undefined or an array!`);
}
currentNode[arrayPropertyName] = _.union(arrayProperty, [newValue]);
const branchToReplaceName = _.head(pathInYmlArray);
const newObject = {};
newObject[branchToReplaceName] = plainObject[branchToReplaceName];
const newText = yaml.dump(newObject);
if (astObject[branchToReplaceName]) {
const beginning = yamlContent
.substring(0, astObject[branchToReplaceName].parent.key.startPosition);
const end = yamlContent
.substring(astObject[branchToReplaceName].endPosition, yamlContent.length);
return fs.writeFileAsync(ymlFile, `${beginning}${newText}${end}`);
}
return fs.writeFileAsync(ymlFile, `${yamlContent}${os.EOL}${newText}`);
});