-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathindex.ts
40 lines (34 loc) · 1.23 KB
/
index.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
/**
* @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 { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
import { resolve } from 'path';
import { Observable, from } from 'rxjs';
import { mapTo, switchMap } from 'rxjs/operators';
import { Schema as NgPackagrBuilderOptions } from './schema';
async function initialize(
options: NgPackagrBuilderOptions,
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 }),
);
}
export { NgPackagrBuilderOptions };
export default createBuilder<Record<string, string> & NgPackagrBuilderOptions>(execute);