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


TypeScript architect.createBuilder函數代碼示例

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


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

示例1: if

    if (typeof serverOptions.publicHost === 'string') {
      let publicHost = serverOptions.publicHost as string;
      if (!/^\w+:\/\//.test(publicHost)) {
        publicHost = `${serverOptions.ssl
          ? 'https'
          : 'http'}://${publicHost}`;
      }
      const clientUrl = url.parse(publicHost);
      baseUrl = url.format(clientUrl);
    } else if (typeof result.port === 'number') {
      baseUrl = url.format({
        protocol: serverOptions.ssl ? 'https' : 'http',
        hostname: options.host,
        port: result.port.toString(),
      });
    }
  }

  try {
    return await runProtractor(context.workspaceRoot, { ...options, baseUrl });
  } catch {
    return { success: false };
  } finally {
    if (server) {
      await server.stop();
    }
  }
}

export default createBuilder<JsonObject & ProtractorBuilderOptions>(execute);
開發者ID:angular,項目名稱:angular-cli,代碼行數:30,代碼來源:index.ts

示例2: return

        failureCb: () => subscriber.next({ success: false }),
        // Workaround for https://github.com/karma-runner/karma/issues/3154
        // When this workaround is removed, user projects need to be updated to use a Karma
        // version that has a fix for this issue.
        toJSON: () => { },
        logger: context.logger,
      };

      // Complete the observable once the Karma server returns.
      const karmaServer = new karma.Server(
        transforms.karmaOptions ? transforms.karmaOptions(karmaOptions) : karmaOptions,
        () => subscriber.complete());
      // karma typings incorrectly define start's return value as void
      // tslint:disable-next-line:no-use-of-empty-return-value
      const karmaStart = karmaServer.start() as unknown as Promise<void>;

      // Cleanup, signal Karma to exit.
      return () => {
        // Karma only has the `stop` method start with 3.1.1, so we must defensively check.
        const karmaServerWithStop = karmaServer as unknown as { stop: () => Promise<void> };
        if (typeof karmaServerWithStop.stop === 'function') {
          return karmaStart.then(() => karmaServerWithStop.stop());
        }
      };
    })),
  );
}

export { KarmaBuilderOptions };
export default createBuilder<Record<string, string> & KarmaBuilderOptions>(execute);
開發者ID:angular,項目名稱:angular-cli,代碼行數:30,代碼來源:index.ts

示例3:

    // If baseHref or deployUrl is absolute, unsupported by ng serve
    return null;
  }

  // normalize baseHref
  // for ng serve the starting base is always `/` so a relative
  // and root relative value are identical
  const baseHrefParts = (baseHref || '')
    .split('/')
    .filter(part => part !== '');
  if (baseHref && !baseHref.endsWith('/')) {
    baseHrefParts.pop();
  }
  const normalizedBaseHref = baseHrefParts.length === 0 ? '/' : `/${baseHrefParts.join('/')}/`;

  if (deployUrl && deployUrl[0] === '/') {
    if (baseHref && baseHref[0] === '/' && normalizedBaseHref !== deployUrl) {
      // If baseHref and deployUrl are root relative and not equivalent, unsupported by ng serve
      return null;
    }

    return deployUrl;
  }

  // Join together baseHref and deployUrl
  return `${normalizedBaseHref}${deployUrl || ''}`;
}


export default createBuilder<DevServerBuilderOptions, DevServerBuilderOutput>(serveWebpackBrowser);
開發者ID:angular,項目名稱:angular-cli,代碼行數:30,代碼來源:index.ts

示例4: _bazelBuilder

import {BuilderContext, BuilderOutput, createBuilder,} from '@angular-devkit/architect';
import {JsonObject} from '@angular-devkit/core';
import {checkInstallation, copyBazelFiles, deleteBazelFiles, getTemplateDir, runBazel} from './bazel';
import {Schema} from './schema';

async function _bazelBuilder(options: JsonObject & Schema, context: BuilderContext, ):
    Promise<BuilderOutput> {
      const {logger, workspaceRoot} = context;
      const {bazelCommand, leaveBazelFilesOnDisk, targetLabel, watch} = options;
      const executable = watch ? 'ibazel' : 'bazel';
      const binary = checkInstallation(executable, workspaceRoot);
      const templateDir = getTemplateDir(workspaceRoot);
      const bazelFiles = copyBazelFiles(workspaceRoot, templateDir);

      try {
        const flags: string[] = [];
        await runBazel(workspaceRoot, binary, bazelCommand, targetLabel, flags);
        return {success: true};
      } catch (err) {
        logger.error(err.message);
        return {success: false};
      } finally {
        if (!leaveBazelFilesOnDisk) {
          deleteBazelFiles(bazelFiles);  // this will never throw
        }
      }
    }

export default createBuilder(_bazelBuilder);
開發者ID:alxhub,項目名稱:angular,代碼行數:29,代碼來源:index.ts

示例5: import

  root: string,
): Promise<import ('ng-packagr').NgPackagr> {
  const packager = (await import('ng-packagr')).ngPackagr();

  packager.forProject(resolve(root, options.project));

  if (options.tsConfig) {
    packager.withTsConfig(resolve(root, options.tsConfig));
  }

  return packager;
}

export function execute(
  options: NgPackagrBuilderOptions,
  context: BuilderContext,
): Observable<BuilderOutput> {
  return from(initialize(options, context.workspaceRoot)).pipe(
    switchMap(packager => options.watch ? packager.watch() : packager.build()),
    mapTo({ success: true }),
    catchError(error => {
      context.reportStatus('Error: ' + error);

      return [{ success: false }];
    }),
  );
}

export { NgPackagrBuilderOptions };
export default createBuilder<Record<string, string> & NgPackagrBuilderOptions>(execute);
開發者ID:angular,項目名稱:angular-cli,代碼行數:30,代碼來源:index.ts

示例6: concatMap

    concatMap(webpackConfig => runWebpack(webpackConfig, context)),
    map(output => {
      if (output.success === false) {
        return output as ServerBuilderOutput;
      }

      return {
        ...output,
        outputPath: path.resolve(root, options.outputPath),
      } as ServerBuilderOutput;
    }),
  );
}

export default createBuilder<json.JsonObject & ServerBuilderOptions, ServerBuilderOutput>(
  execute,
);

function getCompilerConfig(wco: WebpackConfigOptions) {
  if (wco.buildOptions.main || wco.buildOptions.polyfills) {
    return wco.buildOptions.aot ? getAotConfig(wco) : getNonAotConfig(wco);
  }

  return {};
}

async function buildServerWebpackConfig(
  options: ServerBuilderOptions,
  context: BuilderContext,
) {
  const { config } = await generateBrowserWebpackConfigFromContext(
開發者ID:angular,項目名稱:angular-cli,代碼行數:31,代碼來源:index.ts

示例7: _lint

  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.');
  }

  return {
    success: options.force || result.errorCount === 0,
  };
}


export default createBuilder<TslintBuilderOptions>(_run);


async function _lint(
  projectTslint: typeof tslint,
  systemRoot: string,
  tslintConfigPath: string | null,
  options: TslintBuilderOptions,
  program?: ts.Program,
  allPrograms?: ts.Program[],
): Promise<LintResult> {
  const Linter = projectTslint.Linter;
  const Configuration = projectTslint.Configuration;

  const files = getFilesToLint(systemRoot, options, Linter, program);
  const lintOptions = {
開發者ID:angular,項目名稱:angular-cli,代碼行數:30,代碼來源:index.ts

示例8: of

            );
          } else {
            return of({ success });
          }
        }),
        concatMap(buildEvent => {
          if (buildEvent.success && !options.watch && options.serviceWorker) {
            return from(augmentAppWithServiceWorker(
              host,
              root,
              projectRoot,
              resolve(root, normalize(options.outputPath)),
              options.baseHref || '/',
              options.ngswConfigPath,
            ).then(() => ({ success: true }), () => ({ success: false })));
          } else {
            return of(buildEvent);
          }
        }),
        map(event => ({
          ...event,
          // If we use differential loading, both configs have the same outputs
          outputPath: path.resolve(context.workspaceRoot, options.outputPath),
        } as BrowserBuilderOutput)),
      );
    }),
  );
}

export default createBuilder<json.JsonObject & BrowserBuilderSchema>(buildWebpackBrowser);
開發者ID:angular,項目名稱:angular-cli,代碼行數:30,代碼來源:index.ts

示例9: InMemoryOutputPlugin

    {
      ...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();
}

export default createBuilder<JsonObject & ExtractI18nBuilderOptions>(execute);
開發者ID:angular,項目名稱:angular-cli,代碼行數:30,代碼來源:index.ts

示例10: return

          if (err) {
            obs.error(err);
          } else {
            const address = this.address();
            result = {
              success: true,
              port: typeof address === 'string' ? 0 : address.port,
              family: typeof address === 'string' ? '' : address.family,
              address: typeof address === 'string' ? address : address.address,
            };
          }
        },
      );

      // Teardown logic. Close the server when unsubscribed from.
      return () => server.close();
    })),
  );
}


export default createBuilder<
  json.JsonObject & WebpackDevServerBuilderSchema, DevServerBuildOutput
>((options, context) => {
  const configPath = resolve(normalize(context.workspaceRoot), normalize(options.webpackConfig));

  return from(import(getSystemPath(configPath))).pipe(
    switchMap((config: webpack.Configuration) => runWebpackDevServer(config, context)),
  );
});
開發者ID:angular,項目名稱:angular-cli,代碼行數:30,代碼來源:index.ts


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