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


TypeScript sander.readFile函數代碼示例

本文整理匯總了TypeScript中sander.readFile函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript readFile函數的具體用法?TypeScript readFile怎麽用?TypeScript readFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了readFile函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: installCommand

export async function installCommand(config: Config, args) {
  const path = args["p"] || args["path"] || process.cwd();
  const fname = args["f"] || args["fetcher"] || "default";
  const FETCHER = config.fetchers[fname];
  let ledeModulesToInstall: string[] = args["_"];
  let addToPackageJson = true;
  const workingDir = await searchForProjectDir(path);
  if (ledeModulesToInstall.length === 0) {
    ledeModulesToInstall = await loadFromPackage(workingDir);
    addToPackageJson = false;
  }

  await Promise.all(ledeModulesToInstall.map(install.bind({ fetcher: FETCHER, workingDir: join(workingDir, config.caches.DEP_CACHE) })))

  if (addToPackageJson) {
    let p = await sander.readFile(join(workingDir, "package.json"), {encoding: "utf8"});
    p = JSON.parse(p);
    if (p.ledeModules && Array.isArray(p.ledeModules)) {
      p.ledeModules.concat(ledeModulesToInstall)
    } else {
      p.ledeModules = ledeModulesToInstall;
    }
    await sander.writeFile(join(workingDir, "package.json"), JSON.stringify(p, null, 2));
  }
  ledeModulesToInstall.forEach(m => config.logger.info(`Finished installing ${m}`));
}
開發者ID:tbtimes,項目名稱:lede-cli,代碼行數:26,代碼來源:install.ts

示例2: Promise

 return new Promise((res, rej) => {
   Promise.all([
     Promise.resolve(bitToSettingsString(bit)),
     sander.readFile(bit.script, {encoding: "utf8"}),
     sander.readFile(bit.style, {encoding: "utf8"}),
     sander.readFile(bit.html, {encoding: "utf8"})
   ])
     .then(([settings, script, style, html]) => {
       const bitDetail = {
         settings,
         script: { file: basename(bit.script), contents: script },
         style: { file: basename(bit.style), contents: style },
         html: { file: basename(bit.html), contents: html }
       };
       return Object.assign({}, bit, bitDetail)
     })
     .then(res)
 })
開發者ID:tbtimes,項目名稱:lede-cli,代碼行數:18,代碼來源:save.ts

示例3: loadFromPackage

async function loadFromPackage(workingDir: string) {
  const location = join(workingDir, "package.json");
  const pack = await sander.readFile(location, {encoding: "utf8"});
  return JSON.parse(pack).ledeModules;
}
開發者ID:tbtimes,項目名稱:lede-cli,代碼行數:5,代碼來源:install.ts

示例4:

 preBlocks.map(block => sander.readFile(join(workingDir, "blocks", block), {encoding: "utf8"}))
開發者ID:tbtimes,項目名稱:lede-cli,代碼行數:1,代碼來源:save.ts


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