UNPKG

3.91 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 init_tsconfig_di_1 = require("./ng-package/entry-point/init-tsconfig.di");
9const entry_point_di_1 = require("./ng-package/entry-point/entry-point.di");
10const package_di_1 = require("./ng-package/package.di");
11const project_di_1 = require("./project.di");
12const 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 */
20class 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 instance 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.mapTo(undefined));
102 }
103}
104exports.NgPackagr = NgPackagr;
105const ngPackagr = () => new NgPackagr([
106 // Add default providers to this list.
107 ...package_di_1.PACKAGE_PROVIDERS,
108 ...entry_point_di_1.ENTRY_POINT_PROVIDERS,
109]);
110exports.ngPackagr = ngPackagr;
111//# sourceMappingURL=packagr.js.map
\No newline at end of file