UNPKG

4.24 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 build_graph_1 = require("./graph/build-graph");
7const entry_point_di_1 = require("./ng-package/entry-point/entry-point.di");
8const init_tsconfig_di_1 = require("./ng-package/entry-point/init-tsconfig.di");
9const options_di_1 = require("./ng-package/options.di");
10const package_di_1 = require("./ng-package/package.di");
11const project_di_1 = require("./project.di");
12/**
13 * The original ng-packagr implemented on top of a rxjs-ified and di-jectable transformation pipeline.
14 *
15 * See the `docs/transformations.md` for more prose description.
16 *
17 * @link https://github.com/ng-packagr/ng-packagr/pull/572
18 */
19class NgPackagr {
20 constructor(providers) {
21 this.providers = providers;
22 this.buildTransform = package_di_1.PACKAGE_TRANSFORM.provide;
23 }
24 /**
25 * Adds options to ng-packagr
26 *
27 * @param options Ng Packagr Options
28 * @return Self instance for fluent API
29 * @deprecated use the options parameter in 'build' and 'watch' methods
30 */
31 withOptions(options) {
32 this.providers.push((0, 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((0, 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((0, 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(options = {}) {
82 this.providers.push((0, options_di_1.provideOptions)(options));
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(options = {}) {
91 this.providers.push((0, options_di_1.provideOptions)({ ...options, 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 if (!this.providers.some(p => 'provide' in p && p.provide === init_tsconfig_di_1.DEFAULT_TS_CONFIG_TOKEN)) {
101 this.withTsConfig(undefined);
102 }
103 const injector = injection_js_1.ReflectiveInjector.resolveAndCreate(this.providers);
104 const buildTransformOperator = injector.get(this.buildTransform);
105 return (0, rxjs_1.of)(new build_graph_1.BuildGraph()).pipe(buildTransformOperator, (0, rxjs_1.map)(() => undefined));
106 }
107}
108exports.NgPackagr = NgPackagr;
109const 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]);
114exports.ngPackagr = ngPackagr;
115//# sourceMappingURL=packagr.js.map
\No newline at end of file