本文整理汇总了TypeScript中js-yaml.load函数的典型用法代码示例。如果您正苦于以下问题:TypeScript load函数的具体用法?TypeScript load怎么用?TypeScript load使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(configDir: string, cb: Function) {
const serverConfigpath: string = path.join(configDir, 'serverConfig.yml');
this.serverConfig = yaml.load(fs.readFileSync(serverConfigpath, 'utf8'));
const renderRulesPath: string = path.join(configDir, 'serverRenderRules.yml');
this.renderRules = Validators.unserializeServerRules(yaml.load(fs.readFileSync(renderRulesPath, 'utf8')));
const cacheRulesPath: string = path.join(configDir, 'serverCacheRules.yml');
this.cacheRules = CacheEngineCB.helpers.unserializeCacheRules(yaml.load(fs.readFileSync(cacheRulesPath, 'utf8')));
CacheCreator.createCache('SERVER', true, this.serverConfig.redisConfig, this.cacheRules, (err) => {
if (err) {
debug('Some error: ', err);
const error = new Error(err);
this.logger.error(error);
return cb(err);
}
UrlCache.loadCacheEngine(this.serverConfig.domain, 'SERVER', this.serverConfig.redisConfig, (err) => {
if(err) {
const error = new Error(err);
this.logger.error(error);
return cb(err);
}
cb(null);
});
});
}
示例2: function
(async function () {
const fontsYAML = await readFile('src/fonts/fonts.yml')
const enFontsYAML = await readFile('src/fonts/fonts.en.yml')
const fonts = yaml.load(fontsYAML) as Font[]
const enFonts = yaml.load(enFontsYAML) as Font[]
const results = new Parser(fonts, enFonts).parse()
const writeFile = promisify(fs.writeFile);
for (let fn of [css, less, scss, styl]) {
await writeFile("dist/fonts." + fn.name, results.map(fn).join("\n"))
}
})()
示例3: getDocMetadata
function getDocMetadata(tree) {
if (tree.children[0].type == "yaml") {
return yaml.load(tree.children[0].value);
} else {
return {};
}
}
示例4: constructor
constructor(private configDir:string) {
debug('DIRNAME = ', __dirname);
if (!fs.existsSync(configDir)) {
throw `The config dir doesn't exists ${configDir}`;
}
let configPath:string;
['serverConfig.yml', 'serverRenderRules.yml', 'serverCacheRules.yml', 'slimerRestCacheRules.yml'].forEach((item) => {
configPath = path.join(configDir, item);
if (!fs.existsSync(configPath)) {
throw new Error('The config file ' + configPath + ' doesnt exists');
}
//check file validity
yaml.load(fs.readFileSync(configPath, 'utf8'));
});
//todo check every config file syntax
this.serverConfig = yaml.load(fs.readFileSync( path.join(this.configDir, 'serverConfig.yml') , 'utf8'));
debug('serverConfig ', this.serverConfig);
ServerLog.initLogs(this.serverConfig.logBasePath, this.serverConfig.gelf);
ServerLog.Log.info('Master starting');
}
示例5: postGenerator
export async function postGenerator() {
console.log("\n😳 😳 🤖 😳 LET'S MAKE A BLOG POST! 😳 😳 🤖 😳 \n")
const config = load(fs.readFileSync("./blog.config.yml", "utf8")) || {}
const { author = "", title = "" } = await prompt([
q.postTitle,
{ ...q.postAuthor, default: config.author || "" },
]) as IPost
const id = title
.replace(",", "")
.replace(/[^a-zA-Z0-9_.@()-]/g, "-")
.toLowerCase()
const permalink = join("posts", `${id}.md`)
const now = new Date()
const postData = { author, id, permalink, title, created: now, updated: now }
const frontmatter = `---\n${dump(postData)}---\n`
await writeFile(permalink, frontmatter + `# ${title}\n`)
console.log(`
Congratulations! 🎉 🎉 🎉
You generated a blog post!
`)
}
示例6: parse
async function parse(previewDir: string, name: string) {
const unparsed = await readFile(resolve(previewDir, "posts", name))
const parsed = /(?:^---\n)([\s\S]*)(?:---\n)(([\s\S])*)/gm.exec(unparsed) || []
const hasFrontmatter = parsed.length
const text = (hasFrontmatter ? parsed[2] : unparsed)
const metadata = load(parsed[1])
return [ metadata, text ]
}
示例7: Error
['serverConfig.yml', 'serverRenderRules.yml', 'serverCacheRules.yml', 'slimerRestCacheRules.yml'].forEach((item) => {
configPath = path.join(configDir, item);
if (!fs.existsSync(configPath)) {
throw new Error('The config file ' + configPath + ' doesnt exists');
}
//check file validity
yaml.load(fs.readFileSync(configPath, 'utf8'));
});
示例8: constructor
constructor(private configDir: string) {
const serverConfigpath: string = path.join(configDir, 'serverConfig.yml');
this.serverConfig = yaml.load(fs.readFileSync(serverConfigpath, 'utf8'));
Bridge_Pool.init(this.serverConfig);
ServerLog.initLogs(this.serverConfig.logBasePath, this.serverConfig.gelf);
}
示例9: validate
public validate(variable: IVariable, errors: IVariableError[]): void {
if (!variable.value) {
errors.push({ message: 'Field is required.' });
}
try {
load(variable.value);
} catch (e) {
errors.push({ message: e.message });
}
}
示例10: getSecrets
function getSecrets(cwd: string) {
const localSecretsPath = path.join(cwd, secretsFile)
let secrets = {}
if (fs.existsSync(localSecretsPath)) {
secrets = YAML.load(fs.readFileSync(localSecretsPath).toString())
}
return secrets
}
示例11: get_config
function get_config(program: Program) { // tslint:disable-line no-shadowed-variable
try {
if (program.configContent) {
return jsyaml.load(program.configContent) as Xlsx2SeedSheetConfig;
} else {
if (program.config) {
return jsyaml.load(fs.readFileSync(program.config, {encoding: 'utf8'})) as Xlsx2SeedSheetConfig;
} else if (fs.existsSync(default_config_file)) {
return jsyaml.load(fs.readFileSync(default_config_file, {encoding: 'utf8'})) as Xlsx2SeedSheetConfig;
} else {
return {};
}
}
} catch (error) {
console.error('load config failed!');
console.error(error.toString());
process.exit(1);
throw error;
}
}
示例12: parse
function parse (body:string) {
if (body.length === 0) {
// special-case empty yaml body, as it's a common client-side mistake
// TODO: maybe make this configurable or part of "strict" option
return {}
}
debug('parse yaml');
let result = yamlParser.load(body);
return result;
}
示例13: async
const main = async (dir: string) => {
try {
const list = fs.recursiveReaddir(dir)
for await (const file of list) {
const f = path.parse(file)
if (f.base === "readme.md") {
console.log(`processing ${file}`)
const content = (await fs.readFile(file)).toString()
const readMe = cm.parse(content)
const set = new Set<string>()
for (const c of cm.iterate(readMe.markDown)) {
if (
c.type === "code_block" &&
c.info !== null &&
c.info.startsWith("yaml") &&
c.literal !== null
) {
const y = (yaml.load(c.literal) as Code)["input-file"]
if (typeof y === "string") {
set.add(y)
} else if (it.isArray(y)) {
for (const i of y) {
set.add(i)
}
}
}
}
const readMeMulti = cm.createNode(
"document",
cm.createNode(
"heading",
cm.createText("Multi-API support for AutoRest v3 generators")
),
cm.createNode(
"block_quote",
cm.createNode(
"paragraph",
cm.createText("see https://aka.ms/autorest")
)
),
cm.createCodeBlock(
"yaml $(enable-multi-api)",
yaml.dump({ "input-file": it.toArray(set) }, { lineWidth: 1000 })
)
)
const x = cm.markDownExToString({ markDown: readMeMulti })
fs.writeFile(path.join(f.dir, "readme.enable-multi-api.md"), x)
}
}
} catch (e) {
console.error(e)
}
}
示例14: load
['', "traffic.spinnaker.io/load-balancers: '[]'"].forEach(annotation => {
const canDisable = ManifestTrafficService.canDisableServerGroup({
disabled: false,
serverGroupManagers: [],
manifest: load(`
kind: ReplicaSet
metadata:
annotations:
${annotation}
`),
} as any);
expect(canDisable).toEqual(false);
});
示例15: it
it('will not disable an already disabled server group', () => {
const canDisable = ManifestTrafficService.canDisableServerGroup({
disabled: true,
serverGroupManagers: [],
manifest: load(`
kind: ReplicaSet
metadata:
annotations:
traffic.spinnaker.io/load-balancers: '[\"service my-service\"]'
`),
} as any);
expect(canDisable).toEqual(false);
});