本文整理汇总了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);
示例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);
示例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);
示例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);
示例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);
示例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(
示例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 = {
示例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);
示例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);
示例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)),
);
});