Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function parseYamlAST(ymlPath) {
try {
const contents = fs.readFileSync(ymlPath, 'utf8')
lineNumbers = [] // reset current AST line Numbers array
window.CURRENT_AST = {} // reset current AST
window.CURRENT_AST.PATH = ymlPath
lineNumbers = getLineNumberInfo(contents)
// console.log('lineNumbers', lineNumbers)
const yamlAST = yaml.load(contents)
const nullYamlValues = []
const valueWithParent = []
parseAST(yamlAST, valueWithParent, nullYamlValues)
// console.log('nullYamlValues', nullYamlValues)
// console.log('valueWithParent', valueWithParent)
// console.log(window.CURRENT_AST)
// TODO: Validate Yaml Fields
// validateYamlFields(valueWithParent)
return yamlAST
} catch (e) {
return e
}
}
function parseYAMLSource(projectSource: ProjectSource, validationContext: ValidationContext): ParsedObjectProjectSource | undefined {
const root: YAMLNode | undefined = load(projectSource.body);
if (!root) {
return undefined;
}
root.errors.forEach(error => {
const severity = error.isWarning ? Severity.Warning : Severity.Error;
const endPos = getLineEndPosition(error.mark.line + 1, projectSource);
validationContext.addMessage(new ValidationMessage(severity, error.reason, new MessageLocation(projectSource, new SourcePosition(error.mark.position, error.mark.line + 1, error.mark.column + 1), endPos)));
});
if (root.errors.some(error => !error.isWarning)) {
// returning undefined will lead to ignoring this source file in future steps
return undefined;
}
return null
}
})
}
})
const schemaWithAdditionalTags = Schema.create(
Object.values(compiledTypeMap)
)
;(schemaWithAdditionalTags as any).compiledTypeMap = compiledTypeMap
const additionalOptions: Yaml.LoadOptions = {
schema: schemaWithAdditionalTags
}
return createJSONDocument(Yaml.load(text, additionalOptions), text)
}
private parse(text: string): ASTNode {
return buildAstRecursively(undefined, Yaml.load(text));;
}
private parse(text: string): ASTNode {
return buildAstRecursively(undefined, Yaml.load(text));;
}