UNPKG

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