Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parseAST (text: string) {
const cst = YAML.parseCST(text)
cst.setOrigRanges() // Workaround for CRLF eol, https://github.com/eemeli/yaml/issues/127
const doc = new YAML.Document({ keepCstNodes: true }).parse(cst[0])
const findPairs = (node: YAML.ast.AstNode | YAML.ast.Pair | null, path: string[] = []): KeyInDocument[] => {
if (!node)
return []
if (node.type === 'MAP' || node.type === 'SEQ')
// @ts-ignore
return _.flatMap(node.items, m => findPairs(m, path))
if (node.type === 'PAIR' && node.value != null && node.key != null) {
if (!['BLOCK_FOLDED', 'BLOCK_LITERAL', 'PLAIN', 'QUOTE_DOUBLE', 'QUOTE_SINGLE'].includes(node.value.type)) {
return findPairs(node.value, [...path, node.key.toString()])
}
else {
const valueCST = node.value.cstNode
if (!valueCST || !valueCST.valueRange)
return []
const { start, end, origStart, origEnd } = valueCST.valueRange
newConfig.wpInstall.users = [{
'name': newConfig.wpInstall.adminUser,
'email': newConfig.wpInstall.adminEmail,
'password': newConfig.wpInstall.adminPassword,
'role':'administrator'
}]
delete newConfig.wpInstall.adminUser
delete newConfig.wpInstall.adminEmail
delete newConfig.wpInstall.adminPassword
}
}
try {
const doc = new YAML.Document()
doc.commentBefore = ' This is the new wordup config. All wordup specific config from package.json moved here.'
doc.contents = newConfig
fs.writeFileSync(this.getProjectPath('.wordup','config.yml'), doc.toString())
} catch (err) {
this.error(err, {exit:1})
}
this.log('INFO: The wordup config has been moved to .wordup/config.yml in your project folder.')
this.log('')
}
}
}
export function toYAML({ language, date, commit, items }: Translation) {
const doc = new YAML.Document();
doc.commentBefore = `
Padloc Translation File
language: ${language}
date: ${date.toISOString()}
commit: ${commit}
`;
doc.contents = YAML.createNode(items.flatMap(item => [item.original, item.translation])) as any;
for (const [i, item] of items.entries()) {
const node = (doc.contents as any).items[i * 2];
node.commentBefore = item.sources
.map(
({ file, line, character, comment }) => ` ${file}:${line},${character}${comment ? ` (${comment})` : ""}`
)