1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.SchematicImpl = exports.InvalidSchematicsNameException = void 0;
|
11 | const core_1 = require("@angular-devkit/core");
|
12 | const rxjs_1 = require("rxjs");
|
13 | const operators_1 = require("rxjs/operators");
|
14 | const call_1 = require("../rules/call");
|
15 | const scoped_1 = require("../tree/scoped");
|
16 | class InvalidSchematicsNameException extends core_1.BaseException {
|
17 | constructor(name) {
|
18 | super(`Schematics has invalid name: "${name}".`);
|
19 | }
|
20 | }
|
21 | exports.InvalidSchematicsNameException = InvalidSchematicsNameException;
|
22 | class SchematicImpl {
|
23 | constructor(_description, _factory, _collection, _engine) {
|
24 | this._description = _description;
|
25 | this._factory = _factory;
|
26 | this._collection = _collection;
|
27 | this._engine = _engine;
|
28 | if (!_description.name.match(/^[-@/_.a-zA-Z0-9]+$/)) {
|
29 | throw new InvalidSchematicsNameException(_description.name);
|
30 | }
|
31 | }
|
32 | get description() {
|
33 | return this._description;
|
34 | }
|
35 | get collection() {
|
36 | return this._collection;
|
37 | }
|
38 | call(options, host, parentContext, executionOptions) {
|
39 | const context = this._engine.createContext(this, parentContext, executionOptions);
|
40 | return host.pipe((0, operators_1.first)(), (0, operators_1.concatMap)((tree) => this._engine
|
41 | .transformOptions(this, options, context)
|
42 | .pipe((0, operators_1.map)((o) => [tree, o]))), (0, operators_1.concatMap)(([tree, transformedOptions]) => {
|
43 | let input;
|
44 | let scoped = false;
|
45 | if (executionOptions && executionOptions.scope) {
|
46 | scoped = true;
|
47 | input = new scoped_1.ScopedTree(tree, executionOptions.scope);
|
48 | }
|
49 | else {
|
50 | input = tree;
|
51 | }
|
52 | return (0, call_1.callRule)(this._factory(transformedOptions), (0, rxjs_1.of)(input), context).pipe((0, operators_1.map)((output) => {
|
53 | if (output === input) {
|
54 | return tree;
|
55 | }
|
56 | else if (scoped) {
|
57 | tree.merge(output);
|
58 | return tree;
|
59 | }
|
60 | else {
|
61 | return output;
|
62 | }
|
63 | }));
|
64 | }));
|
65 | }
|
66 | }
|
67 | exports.SchematicImpl = SchematicImpl;
|