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


TypeScript config.Generator類代碼示例

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


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

示例1: augmentAppWithServiceWorker

export function augmentAppWithServiceWorker(projectRoot: string, appRoot: string,
    outputPath: string, baseHref: string): Promise<void> {
  // Path to the worker script itself.
  const workerPath = resolveProjectModule(projectRoot, '@angular/service-worker/ngsw-worker.js');
  const safetyPath = path.join(path.dirname(workerPath), 'safety-worker.js');
  const configPath = path.resolve(appRoot, 'ngsw-config.json');

  if (!fs.existsSync(configPath)) {
    throw new Error(oneLine`Error: Expected to find an ngsw-config.json configuration
      file in the ${appRoot} folder. Either provide one or disable Service Worker
      in .angular-cli.json.`);
  }
  const config = fs.readFileSync(configPath, 'utf8');

  const Generator = require('@angular/service-worker/config').Generator;
  const gen = new Generator(new CliFilesystem(outputPath), baseHref);
  return gen
    .process(JSON.parse(config))
    .then((output: Object) => {
      const manifest = JSON.stringify(output, null, 2);
      fs.writeFileSync(path.resolve(outputPath, 'ngsw.json'), manifest);
      // Copy worker script to dist directory.
      const workerCode = fs.readFileSync(workerPath);
      fs.writeFileSync(path.resolve(outputPath, 'ngsw-worker.js'), workerCode);

      // If @angular/service-worker has the safety script, copy it into two locations.
      if (fs.existsSync(safetyPath)) {
        const safetyCode = fs.readFileSync(safetyPath);
        fs.writeFileSync(path.resolve(outputPath, 'worker-basic.min.js'), safetyCode);
        fs.writeFileSync(path.resolve(outputPath, 'safety-worker.js'), safetyCode);
      }
    });
}
開發者ID:deebloo,項目名稱:angular-cli,代碼行數:33,代碼來源:index.ts

示例2: augmentAppWithServiceWorker

export function augmentAppWithServiceWorker(projectRoot: string, appRoot: string,
    outputPath: string, baseHref: string): Promise<void> {
  const nodeModules = path.resolve(projectRoot, 'node_modules');
  const swModule = path.resolve(nodeModules, '@angular/service-worker');

  // Path to the worker script itself.
  const workerPath = path.resolve(swModule, 'ngsw-worker.js');
  const configPath = path.resolve(appRoot, 'ngsw-config.json');

  if (!fs.existsSync(configPath)) {
    throw new Error(stripIndent`Expected to find an ngsw-config.json configuration file in the
                                application root. Either provide one or disable Service Worker
                                build support in angular-cli.json.`);
  }
  const config = fs.readFileSync(configPath, 'utf8');

  const Generator = require('@angular/service-worker/config').Generator;
  const gen = new Generator(new CliFilesystem(outputPath), baseHref);
  return gen
    .process(JSON.parse(config))
    .then((output: Object) => {
      const manifest = JSON.stringify(output, null, 2);
      fs.writeFileSync(path.resolve(outputPath, 'ngsw.json'), manifest);
      // Copy worker script to dist directory.
      const workerCode = fs.readFileSync(workerPath);
      fs.writeFileSync(path.resolve(outputPath, 'ngsw-worker.js'), workerCode);
    });
}
開發者ID:3L4CKD4RK,項目名稱:angular-cli,代碼行數:28,代碼來源:index.ts

示例3:

(async() => {
  const control = await gen.process(configParsed);
  await filesystem.write('/ngsw.json', JSON.stringify(control, null, 2));
})();
開發者ID:AnthonyPAlicea,項目名稱:angular,代碼行數:4,代碼來源:main.ts


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