-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathrun-target-spec.ts
62 lines (55 loc) · 1.93 KB
/
run-target-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { experimental, logging, normalize } from '@angular-devkit/core';
import { Observable, merge, throwError, timer } from 'rxjs';
import { concatMap, concatMapTo, finalize, takeUntil } from 'rxjs/operators';
import { Architect, BuildEvent, BuilderContext, TargetSpecifier } from '../src';
import { TestProjectHost } from './test-project-host';
/**
* @deprecated
*/
export const DefaultTimeout = 45000;
/**
* @deprecated
*/
export function runTargetSpec(
host: TestProjectHost,
targetSpec: TargetSpecifier,
overrides = {},
timeout = DefaultTimeout,
logger: logging.Logger = new logging.NullLogger(),
): Observable<BuildEvent> {
targetSpec = { ...targetSpec, overrides };
const workspaceFile = normalize('angular.json');
const workspace = new experimental.workspace.Workspace(host.root(), host);
// Emit when runArchitect$ completes or errors.
// TODO: There must be a better way of doing this...
let finalizeCB = () => { };
const runArchitectFinalize$ = new Observable(obs => {
finalizeCB = () => obs.next();
});
// Load the workspace from the root of the host, then run a target.
const builderContext: Partial<BuilderContext> = {
logger,
targetSpecifier: targetSpec,
};
const runArchitect$ = workspace.loadWorkspaceFromHost(workspaceFile).pipe(
concatMap(ws => new Architect(ws).loadArchitect()),
concatMap(arch => arch.run(arch.getBuilderConfiguration(targetSpec), builderContext)),
finalize(() => finalizeCB()),
);
// Error out after the timeout if runArchitect$ hasn't finalized.
const timeout$ = timer(timeout).pipe(
takeUntil(runArchitectFinalize$),
concatMapTo(throwError(`runTargetSpec timeout (${timeout}) reached.`)),
);
return merge(
timeout$,
runArchitect$,
);
}