const main = async () => { for (let i = 0; i < tables.length; i++) { const data = await db.select().from(tables[i]); const yaml = YAML.stringify(data); await fs.writeFile(path.join(__dirname, 'seeds', 'data', `${tables[i]}.yml`), yaml); } db.destroy(); }
/** * Return the yaml parsed for a given string * * @param {string} str */ const loadString = async (str) => yaml.parse(str)
//____________________________________________________________________________ function yrequire(filename) { const s = fs.readFileSync(filename,'utf8'); return yaml.parse(s); }
const display = (filename) => { if (!fs.existsSync(scriptsPath)){ fs.mkdirSync(scriptsPath); } if(fileExists(scriptsPath+filename)){ const file = fs.readFileSync(scriptsPath+filename, 'utf8') let res = YAML.parse(file); console.log(""); read(res,"",0,false); } else { console.log(`There is no loaded script with name `+filename+` to be displayed`); } }
function __getServiceInformation(service_name) { return new Promise((resolve, reject) => { const file = fs.readFileSync('./app/gateway_conf.yml', 'utf8') const conf = yaml.parse(file) if ( conf.services.hasOwnProperty(service_name) ) { resolve(conf.services[service_name]) } else { const err = { type: 'NOT_FOUND', module_source: 'request_resolver', message: 'Invalid service access. Please check your request again/' } reject(err) } }) }
setWordupPkg(key, value) { dotProp.set(this.dotWordupJson, key, value) const newValue = dotProp.get(this.dotWordupJson, key) const ymlLevels = key.split('.') if(ymlLevels.length > 1){ this.dotWordupYml.setIn(ymlLevels, YAML.createNode(newValue)) }else{ this.dotWordupYml.set(key, YAML.createNode(newValue)) } try { fs.writeFileSync(this.getProjectPath('.wordup','config.yml'), this.dotWordupYml.toString()) } catch (err) { this.error(err, {exit:1}) } }
[ // Generate a random list of unique user agent strings ...Array.from( new Set( Array(1000) .fill() .map( () => new UserAgent(({ userAgent }) => !BOTS.test(userAgent)).toString() ) ) ), // Read from Yaml file ...Object.values( parse( readFileSync( join(__dirname, browserUserAgentsYaml), 'utf-8' ) ) ).flat() ].filter(Boolean)
function main(s) { let o = yaml.parse(s, { prettyErrors: true }); if (argv.verbose) console.log('Loaded definition '+defName); if (o && o.openapi) { despatch(o,config,configName,finish); } else { if (o && o.swaggerVersion && o.swaggerVersion === '1.2') { convert12(o); } else if (o && o.swagger && o.swagger === '2.0') { if (remoteConfig) { despatch(o,config,configName,finish); } else { convert20(o); } } else { console.error('Unrecognised OpenAPI/Swagger version'); } } }
setUp() { if (fs.existsSync(this.getProjectPath('.wordup','config.yml'))) { try { this.dotWordupYml = YAML.parseDocument(fs.readFileSync(this.getProjectPath('.wordup','config.yml'), 'utf8')) this.dotWordupJson = this.dotWordupYml.toJSON() } catch (err) { this.error('Could not parse wordup config: '+err, {exit:1}) } // Create the slug as a name. Because it could be also a path const slug = this.wPkg('slug') if(slug){ if (slug.lastIndexOf('/') !== -1) { dotProp.set(this.dotWordupJson, 'slugName', slug.substring(0, slug.lastIndexOf('/'))) } else { dotProp.set(this.dotWordupJson, 'slugName', slug) } } // Get config based on the current path this.config = this._wordupConfigstore.get('projects.' + this.projectId) } }
const filepath = join(__dirname, filename) const content = (await readFile(filepath)).toString() const data = YAML.parse(content) YAML.scalarOptions.str.fold.lineWidth = Infinity YAML.stringify(sorted)
const run = (filename) => { if (!fs.existsSync(scriptsPath)){ fs.mkdirSync(scriptsPath); } let fullpath = scriptsPath+filename; if(filename.substr(0,2)=="./"||filename.indexOf('/')!=-1){ let isValid = validate(filename,false); if(isValid)fullpath=filename; else return; } if(fileExists(fullpath)){ createLog(); console.log(`You can find a complete log for this run at ./_logs/`+logName) const file = fs.readFileSync(fullpath, 'utf8') let res = YAML.parse(file); read(res,"",0); execCommands(res,0); } else { console.log(`There is no loaded script with name `+filename); } }
function readCliConfig() { const configFile = path.join( process.env['HOME'], '.config/yandex-cloud/config.yaml' ); let config; try { config = yaml.parse(fs.readFileSync(configFile, 'utf8')); } catch (e) { throw new Error(`Failed to read config ${configFile}: ${e.toString()}`); } const current = config['current']; if (!current) { throw new Error( `Invalid config in ${configFile}: no current profile selected` ); } if (!config['profiles'][current]) { throw new Error( `Invalid config in ${configFile}: no profile named ${current} exists` ); } return config['profiles'][current]; }
[ // Read from text file ...readFileSync( join( __dirname, '../fixtures/', crawlerUserAgentsText ), 'utf-8' ).trim().split('\n'), // Read from JSON file ...require(crawlerUserAgentsJson).reduce( (accumulator, { instances }) => accumulator.concat(instances), [] ), // Read from Yaml file ...Object.values( parse( readFileSync( join(__dirname, crawlerUserAgentsYaml), 'utf-8' ) ) ).flat() ].filter(Boolean).filter(ua => !ignoreList.includes(ua))
const validate = (filename,print=true) => { let file; try{ file = fs.readFileSync(filename, 'utf8') } catch (e) { if(e.code==="ENOENT"){ console.log(`No such file by name '`+filename+`'`); } return false; } try { let res = YAML.parse(file); if(res instanceof Array){ if(print) console.log("Your YAML file is valid!"); } else { console.log("The commands in the YAML file are not in the correct format"); return false; } } catch (e){ console.log("The YAML file is not well formated"); return false; } return true; }
function yrequire(filename) { const s = fs.readFileSync(filename,'utf8'); return yaml.parse(s); }