1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const injection_js_1 = require("injection-js");
|
4 | const rxjs_1 = require("rxjs");
|
5 | const operators_1 = require("rxjs/operators");
|
6 | const build_graph_1 = require("./graph/build-graph");
|
7 | const log = require("./utils/log");
|
8 | const init_tsconfig_di_1 = require("./ng-package/entry-point/init-tsconfig.di");
|
9 | const entry_point_di_1 = require("./ng-package/entry-point/entry-point.di");
|
10 | const package_di_1 = require("./ng-package/package.di");
|
11 | const project_di_1 = require("./project.di");
|
12 | const options_di_1 = require("./ng-package/options.di");
|
13 | /**
|
14 | * The original ng-packagr implemented on top of a rxjs-ified and di-jectable transformation pipeline.
|
15 | *
|
16 | * See the `docs/transformations.md` for more prose description.
|
17 | *
|
18 | * @link https://github.com/ng-packagr/ng-packagr/pull/572
|
19 | */
|
20 | class NgPackagr {
|
21 | constructor(providers) {
|
22 | this.providers = providers;
|
23 | this.buildTransform = package_di_1.PACKAGE_TRANSFORM.provide;
|
24 | }
|
25 | /**
|
26 | * Adds options to ng-packagr
|
27 | *
|
28 | * @param options Ng Packagr Options
|
29 | * @return Self instance for fluent API
|
30 | */
|
31 | withOptions(options) {
|
32 | this.providers.push(options_di_1.provideOptions(options));
|
33 | return this;
|
34 | }
|
35 | /**
|
36 | * Sets the path to the user's "ng-package" file (either `package.json`, `ng-package.json`, or `ng-package.js`)
|
37 | *
|
38 | * @param project File path
|
39 | * @return Self instance for fluent API
|
40 | */
|
41 | forProject(project) {
|
42 | this.providers.push(project_di_1.provideProject(project));
|
43 | return this;
|
44 | }
|
45 | /**
|
46 | * Adds dependency injection providers.
|
47 | *
|
48 | * @param providers
|
49 | * @return Self instance for fluent API
|
50 | * @link https://github.com/mgechev/injection-js
|
51 | */
|
52 | withProviders(providers) {
|
53 | this.providers = [...this.providers, ...providers];
|
54 | return this;
|
55 | }
|
56 | /**
|
57 | * Overwrites the default TypeScript configuration.
|
58 | *
|
59 | * @param defaultValues A tsconfig providing default values to the compilation.
|
60 | * @return Self instance for fluent API
|
61 | */
|
62 | withTsConfig(defaultValues) {
|
63 | this.providers.push(init_tsconfig_di_1.provideTsConfig(defaultValues));
|
64 | return this;
|
65 | }
|
66 | /**
|
67 | * Overwrites the 'build' transform.
|
68 | *
|
69 | * @param transform
|
70 | * @return Self intance for fluent API
|
71 | */
|
72 | withBuildTransform(transform) {
|
73 | this.buildTransform = transform;
|
74 | return this;
|
75 | }
|
76 | /**
|
77 | * Builds the project by kick-starting the 'build' transform over an (initially) empty `BuildGraph``
|
78 | *
|
79 | * @return A promisified result of the transformation pipeline.
|
80 | */
|
81 | build() {
|
82 | return this.buildAsObservable().toPromise();
|
83 | }
|
84 | /**
|
85 | * Builds and watch for changes by kick-starting the 'watch' transform over an (initially) empty `BuildGraph``
|
86 | *
|
87 | * @return An observable result of the transformation pipeline.
|
88 | */
|
89 | watch() {
|
90 | this.providers.push(options_di_1.provideOptions({ watch: true }));
|
91 | return this.buildAsObservable();
|
92 | }
|
93 | /**
|
94 | * Builds the project by kick-starting the 'build' transform over an (initially) empty `BuildGraph``
|
95 | *
|
96 | * @return An observable result of the transformation pipeline.
|
97 | */
|
98 | buildAsObservable() {
|
99 | const injector = injection_js_1.ReflectiveInjector.resolveAndCreate(this.providers);
|
100 | const buildTransformOperator = injector.get(this.buildTransform);
|
101 | return rxjs_1.of(new build_graph_1.BuildGraph()).pipe(buildTransformOperator, operators_1.catchError(err => {
|
102 | // Report error and re-throw to subscribers
|
103 | log.error(err);
|
104 | return rxjs_1.throwError(err);
|
105 | }), operators_1.map(() => undefined));
|
106 | }
|
107 | }
|
108 | exports.NgPackagr = NgPackagr;
|
109 | exports.ngPackagr = () => new NgPackagr([
|
110 | // Add default providers to this list.
|
111 | ...package_di_1.PACKAGE_PROVIDERS,
|
112 | ...entry_point_di_1.ENTRY_POINT_PROVIDERS,
|
113 | ]);
|
114 | //# sourceMappingURL=packagr.js.map |
\ | No newline at end of file |