• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript architect.BuilderContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@angular-devkit/architect.BuilderContext的典型用法代码示例。如果您正苦于以下问题:TypeScript BuilderContext类的具体用法?TypeScript BuilderContext怎么用?TypeScript BuilderContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了BuilderContext类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: execute

async function execute(options: ExtractI18nBuilderOptions, context: BuilderContext) {
  // Check Angular version.
  Version.assertCompatibleAngularVersion(context.workspaceRoot);

  const browserTarget = targetFromTargetString(options.browserTarget);
  const browserOptions = await context.validateOptions<JsonObject & BrowserBuilderOptions>(
    await context.getTargetOptions(browserTarget),
    await context.getBuilderNameForTarget(browserTarget),
  );

  // We need to determine the outFile name so that AngularCompiler can retrieve it.
  let outFile = options.outFile || getI18nOutfile(options.i18nFormat);
  if (options.outputPath) {
    // AngularCompilerPlugin doesn't support genDir so we have to adjust outFile instead.
    outFile = path.join(options.outputPath, outFile);
  }

  const { config } = await generateBrowserWebpackConfigFromContext(
    {
      ...browserOptions,
      optimization: {
        scripts: false,
        styles: false,
      },
      i18nLocale: options.i18nLocale,
      i18nFormat: options.i18nFormat,
      i18nFile: outFile,
      aot: true,
      progress: options.progress,
      assets: [],
      scripts: [],
      styles: [],
      deleteOutputPath: false,
    },
    context,
    wco => [
      { plugins: [new InMemoryOutputPlugin()] },
      getCommonConfig(wco),
      getAotConfig(wco, true),
      getStylesConfig(wco),
      getStatsConfig(wco),
    ],
  );

  return runWebpack(config[0], context).toPromise();
}
开发者ID:angular,项目名称:angular-cli,代码行数:46,代码来源:index.ts


示例2: _appShellBuilder

async function _appShellBuilder(
  options: JsonObject & BuildWebpackAppShellSchema,
  context: BuilderContext,
): Promise<BuilderOutput> {
  const browserTarget = targetFromTargetString(options.browserTarget);
  const serverTarget = targetFromTargetString(options.serverTarget);

  // Never run the browser target in watch mode.
  // If service worker is needed, it will be added in _renderUniversal();
  const browserTargetRun = await context.scheduleTarget(browserTarget, {
    watch: false,
    serviceWorker: false,
  });
  const serverTargetRun = await context.scheduleTarget(serverTarget, {});

  try {
    const [browserResult, serverResult] = await Promise.all([
      browserTargetRun.result as {} as BrowserBuilderOutput,
      serverTargetRun.result,
    ]);

    if (browserResult.success === false || browserResult.outputPath === undefined) {
      return browserResult;
    } else if (serverResult.success === false) {
      return serverResult;
    }

    return await _renderUniversal(options, context, browserResult, serverResult);
  } catch (err) {
    return { success: false, error: err.message };
  } finally {
    // Just be good citizens and stop those jobs.
    await Promise.all([
      browserTargetRun.stop(),
      serverTargetRun.stop(),
    ]);
  }
}
开发者ID:angular,项目名称:angular-cli,代码行数:38,代码来源:index.ts


示例3: _run

async function _run(
  options: TslintBuilderOptions,
  context: BuilderContext,
): Promise<BuilderOutput> {
  const systemRoot = context.workspaceRoot;
  process.chdir(context.currentDirectory);
  const projectName = (context.target && context.target.project) || '<???>';

  // Print formatter output only for non human-readable formats.
  const printInfo =
    ['prose', 'verbose', 'stylish'].includes(options.format || '') && !options.silent;

  context.reportStatus(`Linting ${JSON.stringify(projectName)}...`);
  if (printInfo) {
    context.logger.info(`Linting ${JSON.stringify(projectName)}...`);
  }

  if (!options.tsConfig && options.typeCheck) {
    throw new Error('A "project" must be specified to enable type checking.');
  }

  const projectTslint = await _loadTslint();
  const tslintConfigPath = options.tslintConfig
    ? path.resolve(systemRoot, options.tslintConfig)
    : null;
  const Linter = projectTslint.Linter;

  let result: undefined | LintResult = undefined;
  if (options.tsConfig) {
    const tsConfigs = Array.isArray(options.tsConfig) ? options.tsConfig : [options.tsConfig];
    context.reportProgress(0, tsConfigs.length);
    const allPrograms = tsConfigs.map(tsConfig => {
      return Linter.createProgram(path.resolve(systemRoot, tsConfig));
    });

    let i = 0;
    for (const program of allPrograms) {
      const partial = await _lint(
        projectTslint,
        systemRoot,
        tslintConfigPath,
        options,
        program,
        allPrograms,
      );
      if (result === undefined) {
        result = partial;
      } else {
        result.failures = result.failures
          .filter(curr => {
            return !partial.failures.some(prev => curr.equals(prev));
          })
          .concat(partial.failures);

        // we are not doing much with 'errorCount' and 'warningCount'
        // apart from checking if they are greater than 0 thus no need to dedupe these.
        result.errorCount += partial.errorCount;
        result.warningCount += partial.warningCount;
        result.fileNames = [...new Set([...result.fileNames, ...partial.fileNames])];

        if (partial.fixes) {
          result.fixes = result.fixes ? result.fixes.concat(partial.fixes) : partial.fixes;
        }
      }

      context.reportProgress(++i, allPrograms.length);
    }
  } else {
    result = await _lint(projectTslint, systemRoot, tslintConfigPath, options);
  }

  if (result == undefined) {
    throw new Error('Invalid lint configuration. Nothing to lint.');
  }

  if (!options.silent) {
    const Formatter = projectTslint.findFormatter(options.format || '');
    if (!Formatter) {
      throw new Error(`Invalid lint format "${options.format}".`);
    }
    const formatter = new Formatter();

    const output = formatter.format(result.failures, result.fixes, result.fileNames);
    if (output.trim()) {
      context.logger.info(output);
    }
  }

  if (result.warningCount > 0 && printInfo) {
    context.logger.warn('Lint warnings found in the listed files.');
  }

  if (result.errorCount > 0 && printInfo) {
    context.logger.error('Lint errors found in the listed files.');
  }

  if (result.warningCount === 0 && result.errorCount === 0 && printInfo) {
    context.logger.info('All files pass linting.');
  }

//.........这里部分代码省略.........
开发者ID:angular,项目名称:angular-cli,代码行数:101,代码来源:index.ts


示例4: _renderUniversal

async function _renderUniversal(
  options: BuildWebpackAppShellSchema,
  context: BuilderContext,
  browserResult: BrowserBuilderOutput,
  serverResult: ServerBuilderOutput,
): Promise<BrowserBuilderOutput> {
  const browserIndexOutputPath = path.join(browserResult.outputPath || '', 'index.html');
  const indexHtml = fs.readFileSync(browserIndexOutputPath, 'utf8');
  const serverBundlePath = await _getServerModuleBundlePath(options, context, serverResult);

  const root = context.workspaceRoot;
  requireProjectModule(root, 'zone.js/dist/zone-node');

  const renderModuleFactory = requireProjectModule(
    root,
    '@angular/platform-server',
  ).renderModuleFactory;
  const AppServerModuleNgFactory = require(serverBundlePath).AppServerModuleNgFactory;
  const outputIndexPath = options.outputIndexPath
    ? path.join(root, options.outputIndexPath)
    : browserIndexOutputPath;

  // Render to HTML and overwrite the client index file.
  const html = await renderModuleFactory(AppServerModuleNgFactory, {
    document: indexHtml,
    url: options.route,
  });

  fs.writeFileSync(outputIndexPath, html);

  const browserTarget = targetFromTargetString(options.browserTarget);
  const rawBrowserOptions = await context.getTargetOptions(browserTarget);
  const browserBuilderName = await context.getBuilderNameForTarget(browserTarget);
  const browserOptions = await context.validateOptions<JsonObject & BrowserBuilderSchema>(
    rawBrowserOptions,
    browserBuilderName,
  );

  if (browserOptions.serviceWorker) {
    const host = new NodeJsSyncHost();
    // Create workspace.
    const registry = new schema.CoreSchemaRegistry();
    registry.addPostTransform(schema.transforms.addUndefinedDefaults);

    const workspace = await experimental.workspace.Workspace.fromPath(
      host,
      normalize(context.workspaceRoot),
      registry,
    );
    const projectName = context.target ? context.target.project : workspace.getDefaultProjectName();

    if (!projectName) {
      throw new Error('Must either have a target from the context or a default project.');
    }
    const projectRoot = resolve(
      workspace.root,
      normalize(workspace.getProject(projectName).root),
    );

    await augmentAppWithServiceWorker(
      host,
      normalize(root),
      projectRoot,
      join(normalize(root), browserOptions.outputPath),
      browserOptions.baseHref || '/',
      browserOptions.ngswConfigPath,
    );
  }

  return browserResult;
}
开发者ID:angular,项目名称:angular-cli,代码行数:71,代码来源:index.ts


示例5: setup

  async function setup(): Promise<{
    browserOptions: json.JsonObject & BrowserBuilderSchema,
    webpackConfig: webpack.Configuration,
    webpackDevServerConfig: WebpackDevServer.Configuration,
    port: number,
  }> {
    // Get the browser configuration from the target name.
    const rawBrowserOptions = await context.getTargetOptions(browserTarget);

    // Override options we need to override, if defined.
    const overrides = (Object.keys(options) as (keyof DevServerBuilderOptions)[])
    .filter(key => options[key] !== undefined && devServerBuildOverriddenKeys.includes(key))
    .reduce<json.JsonObject & Partial<BrowserBuilderSchema>>((previous, key) => ({
      ...previous,
      [key]: options[key],
    }), {});

    // In dev server we should not have budgets because of extra libs such as socks-js
    overrides.budgets = undefined;

    const browserName = await context.getBuilderNameForTarget(browserTarget);
    const browserOptions = await context.validateOptions<json.JsonObject & BrowserBuilderSchema>(
      { ...rawBrowserOptions, ...overrides },
      browserName,
    );

    const webpackConfigResult = await buildBrowserWebpackConfigFromContext(
      browserOptions,
      context,
      host,
    );

    // No differential loading for dev-server, hence there is just one config
    let webpackConfig = webpackConfigResult.config[0];

    const port = await checkPort(options.port || 0, options.host || 'localhost', 4200);
    const webpackDevServerConfig = webpackConfig.devServer = buildServerConfig(
      root,
      options,
      browserOptions,
      context.logger,
    );

    if (transforms.webpackConfiguration) {
      webpackConfig = await transforms.webpackConfiguration(webpackConfig);
    }

    return { browserOptions, webpackConfig, webpackDevServerConfig, port };
  }
开发者ID:angular,项目名称:angular-cli,代码行数:49,代码来源:index.ts


示例6: update

 function update(status: string) {
   context.reportProgress(
     modulesDone + hooksDone,
     modulesCount + Math.max(hooksDone, numberOfHooks),
     status,
   );
 }
开发者ID:angular,项目名称:angular-cli,代码行数:7,代码来源:architect.ts


示例7: catchError

    catchError(error => {
      context.reportStatus('Error: ' + error);

      return [{ success: false }];
    }),
开发者ID:angular,项目名称:angular-cli,代码行数:5,代码来源:index.ts



注:本文中的@angular-devkit/architect.BuilderContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript architect.Architect类代码示例发布时间:2022-05-28
下一篇:
TypeScript architect.Architect类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap