/* * Helper to load landofile */ const loadLandoFile = file => { try { return yaml.safeLoad(fs.readFileSync(file)); } catch (e) { throw new Error(`There was a problem with parsing ${file}. Ensure it is valid YAML! ${e}`); } }
_(files) // Filter if file exists .filter(fs.existsSync) // Start collecting .reduce((a, file) => exports.merge(a, yaml.safeLoad(fs.readFileSync(file))), {})
function toYAML (value) { return yaml.safeDump(value, { noRefs: true }).trim() }
load(data) { return yaml.load(data, {schema: this.PLATFORM_SCHEMA}); }
_(files) .filter(file => fs.existsSync(file)) .map(file => yaml.safeLoad(fs.readFileSync(file))) .thru(data => _.merge({}, ...data)) .thru(data => { // Set the php version // @TODO: what is the best version here? data.php = _.toString(_.get(data, 'php_version', '5.6')); // Set the webroot data.webroot = (_.get(data, 'web_docroot', false)) ? 'web' : '.'; // Set the drush version data.drush = _.toString(_.get(data, 'drush_version', '8')); // if drush version is less than 8, use 8 anyway if (data.drush < 8) data.drush = 8; // return return data; }) .value()
/** * Dumps an object to a YAML file * * @since 3.0.0 * @alias lando.yaml.dump * @param {String} file The path to the file to be loaded * @param {Object} data The object to dump * @return {String} Flename */ dump(file, data = {}) { // Make sure we have a place to store these files mkdirp.sync(path.dirname(file)); // Remove any properties that might be bad and dump data = JSON.parse(JSON.stringify(data)); // And dump fs.writeFileSync(file, yaml.safeDump(data)); // Log and return filename return file; }
/** * Parses YAML text. * * @param {string} yaml YAML to parse. * @returns {Object} Object representation. */ function yamlParse(yaml) { return jsYaml.safeLoad(yaml); }
function readYAML (fp) { try { return yaml.safeLoad(fs.readFileSync(fp, 'utf8')) } catch (err) { if (err.code !== 'ENOENT') fail(err) } }
/** * Loads a yaml object from a file. * * @since 3.0.0 * @alias lando.yaml.load * @param {String} file The path to the file to be loaded * @return {Object} The loaded object * @example * // Add a string to the cache * const thing = lando.yaml.load('/tmp/myfile.yml'); */ load(file) { try { return yaml.safeLoad(fs.readFileSync(file)); } catch (e) { this.log.error('Problem parsing %s with %s', file, e.message); } }
function stringify(obj) { return yaml.safeDump(obj); }
function loadKubeconfig (cfgPath) { let cfgPaths if (!cfgPath) { cfgPaths = defaultConfigPaths() } else if (Array.isArray(cfgPath)) { cfgPaths = cfgPath } else { cfgPaths = [cfgPath] } const configs = cfgPaths.map(cfgPath => { const config = yaml.safeLoad(fs.readFileSync(cfgPath)) return mapCertificates(cfgPath, config) }) return merge.all(configs) }
const getConfig = () => yaml.safeLoad(fs.readFileSync(configPath, 'utf8'))
function toYAML (value) { return yaml.safeDump(value, { noRefs: true }).trim() }
function parse(text) { return yaml.safeLoad(text, 'utf8'); }