當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript js-yaml.load函數代碼示例

本文整理匯總了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);
            });
        });
    }
開發者ID:a-lucas,項目名稱:angular.js-server,代碼行數:29,代碼來源:cache.ts

示例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"))
    }
})()
開發者ID:praycis-lee,項目名稱:fonts.css,代碼行數:11,代碼來源:build.ts

示例3: getDocMetadata

function getDocMetadata(tree) {
    if (tree.children[0].type == "yaml") {
        return yaml.load(tree.children[0].value);
    } else {
        return {};
    }
}
開發者ID:Alfresco,項目名稱:alfresco-ng2-components,代碼行數:7,代碼來源:tutorialIndex.ts

示例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');
    }
開發者ID:a-lucas,項目名稱:angular.js-server,代碼行數:26,代碼來源:masterProcess.ts

示例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!
  `)
}
開發者ID:Blanket-Warriors,項目名稱:Blog-O-Matic,代碼行數:26,代碼來源:postGenerator.ts

示例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 ]
}
開發者ID:Blanket-Warriors,項目名稱:Blog-O-Matic,代碼行數:8,代碼來源:index.ts

示例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'));
 });
開發者ID:a-lucas,項目名稱:angular.js-server,代碼行數:8,代碼來源:masterProcess.ts

示例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);
    }
開發者ID:a-lucas,項目名稱:angular.js-server,代碼行數:9,代碼來源:bridge.ts

示例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 });
   }
 }
開發者ID:robfletcher,項目名稱:deck,代碼行數:10,代碼來源:object.validator.ts

示例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
}
開發者ID:dianpeng,項目名稱:fly,代碼行數:10,代碼來源:file_app_store.ts

示例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;
  }
}
開發者ID:Narazaka,項目名稱:xlsx2seed.js,代碼行數:20,代碼來源:xlsx2seed.ts

示例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;
  }
開發者ID:MaxxtonGroup,項目名稱:microdocs,代碼行數:11,代碼來源:yaml-parser.ts

示例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)
  }
}
開發者ID:Nking92,項目名稱:azure-rest-api-specs,代碼行數:53,代碼來源:multiapi.ts

示例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);
 });
開發者ID:emjburns,項目名稱:deck,代碼行數:13,代碼來源:ManifestTrafficService.spec.ts

示例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);
 });
開發者ID:emjburns,項目名稱:deck,代碼行數:13,代碼來源:ManifestTrafficService.spec.ts


注:本文中的js-yaml.load函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。