本文整理匯總了TypeScript中@angular-devkit/architect.BuilderContext.scheduleTarget方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript BuilderContext.scheduleTarget方法的具體用法?TypeScript BuilderContext.scheduleTarget怎麽用?TypeScript BuilderContext.scheduleTarget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@angular-devkit/architect.BuilderContext
的用法示例。
在下文中一共展示了BuilderContext.scheduleTarget方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: _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(),
]);
}
}
示例2: execute
async function execute(
options: ProtractorBuilderOptions,
context: BuilderContext,
): Promise<BuilderOutput> {
// ensure that only one of these options is used
if (options.devServerTarget && options.baseUrl) {
throw new Error(tags.stripIndents`
The 'baseUrl' option cannot be used with 'devServerTarget'.
When present, 'devServerTarget' will be used to automatically setup 'baseUrl' for Protractor.
`);
}
if (options.webdriverUpdate) {
try {
await updateWebdriver();
} catch (error) {
context.reportStatus('Error: ' + error);
return { success: false };
}
}
let baseUrl;
let server;
if (options.devServerTarget) {
const target = targetFromTargetString(options.devServerTarget);
const serverOptions = await context.getTargetOptions(target);
const overrides: Record<string, string | number | boolean> = { watch: false };
if (options.host !== undefined) { overrides.host = options.host; }
if (options.port !== undefined) { overrides.port = options.port; }
server = await context.scheduleTarget(target, overrides);
let result;
try {
result = await server.result;
} catch (error) {
context.reportStatus('Error: ' + error);
}
if (!result || !result.success) {
return { success: false };
}
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();
}
}
}