1 | "use strict";
|
2 | var __read = (this && this.__read) || function (o, n) {
|
3 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
4 | if (!m) return o;
|
5 | var i = m.call(o), r, ar = [], e;
|
6 | try {
|
7 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
8 | }
|
9 | catch (error) { e = { error: error }; }
|
10 | finally {
|
11 | try {
|
12 | if (r && !r.done && (m = i["return"])) m.call(i);
|
13 | }
|
14 | finally { if (e) throw e.error; }
|
15 | }
|
16 | return ar;
|
17 | };
|
18 | var __values = (this && this.__values) || function(o) {
|
19 | var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
20 | if (m) return m.call(o);
|
21 | if (o && typeof o.length === "number") return {
|
22 | next: function () {
|
23 | if (o && i >= o.length) o = void 0;
|
24 | return { value: o && o[i++], done: !o };
|
25 | }
|
26 | };
|
27 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
28 | };
|
29 | exports.__esModule = true;
|
30 | var ts = require("typescript");
|
31 | var schematics_1 = require("@angular-devkit/schematics");
|
32 | var tasks_1 = require("@angular-devkit/schematics/tasks");
|
33 | var schematics_core_1 = require("../../schematics-core");
|
34 | var core_1 = require("@angular-devkit/core");
|
35 | function addImportToNgModule(options) {
|
36 | return function (host) {
|
37 | var e_1, _a;
|
38 | var modulePath = options.module;
|
39 | if (!modulePath) {
|
40 | return host;
|
41 | }
|
42 | if (!host.exists(modulePath)) {
|
43 | throw new Error('Specified module does not exist');
|
44 | }
|
45 | var text = host.read(modulePath);
|
46 | if (text === null) {
|
47 | throw new schematics_1.SchematicsException("File ".concat(modulePath, " does not exist."));
|
48 | }
|
49 | var sourceText = text.toString('utf-8');
|
50 | var source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
51 | var _b = __read((0, schematics_core_1.addImportToModule)(source, modulePath, "StoreDevtoolsModule.instrument({ maxAge: ".concat(options.maxAge, ", logOnly: environment.production })"), modulePath), 1), instrumentNgModuleImport = _b[0];
|
52 | var srcPath = (0, core_1.dirname)(options.path);
|
53 | var environmentsPath = (0, schematics_core_1.buildRelativePath)(modulePath, "/".concat(srcPath, "/environments/environment"));
|
54 | var changes = [
|
55 | (0, schematics_core_1.insertImport)(source, modulePath, 'StoreDevtoolsModule', '@ngrx/store-devtools'),
|
56 | (0, schematics_core_1.insertImport)(source, modulePath, 'environment', environmentsPath),
|
57 | instrumentNgModuleImport,
|
58 | ];
|
59 | var recorder = host.beginUpdate(modulePath);
|
60 | try {
|
61 | for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
|
62 | var change = changes_1_1.value;
|
63 | if (change instanceof schematics_core_1.InsertChange) {
|
64 | recorder.insertLeft(change.pos, change.toAdd);
|
65 | }
|
66 | }
|
67 | }
|
68 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
69 | finally {
|
70 | try {
|
71 | if (changes_1_1 && !changes_1_1.done && (_a = changes_1["return"])) _a.call(changes_1);
|
72 | }
|
73 | finally { if (e_1) throw e_1.error; }
|
74 | }
|
75 | host.commitUpdate(recorder);
|
76 | return host;
|
77 | };
|
78 | }
|
79 | function addNgRxStoreDevToolsToPackageJson() {
|
80 | return function (host, context) {
|
81 | (0, schematics_core_1.addPackageToPackageJson)(host, 'dependencies', '@ngrx/store-devtools', schematics_core_1.platformVersion);
|
82 | context.addTask(new tasks_1.NodePackageInstallTask());
|
83 | return host;
|
84 | };
|
85 | }
|
86 | function default_1(options) {
|
87 | return function (host, context) {
|
88 | options.path = (0, schematics_core_1.getProjectPath)(host, options);
|
89 | if (options.module) {
|
90 | options.module = (0, schematics_core_1.findModuleFromOptions)(host, {
|
91 | name: '',
|
92 | module: options.module,
|
93 | path: options.path
|
94 | });
|
95 | }
|
96 | var parsedPath = (0, schematics_core_1.parseName)(options.path, '');
|
97 | options.path = parsedPath.path;
|
98 | if (options.maxAge && (options.maxAge < 0 || options.maxAge === 1)) {
|
99 | throw new schematics_1.SchematicsException("maxAge should be an integer greater than 1.");
|
100 | }
|
101 | return (0, schematics_1.chain)([
|
102 | (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([addImportToNgModule(options)])),
|
103 | options && options.skipPackageJson
|
104 | ? (0, schematics_1.noop)()
|
105 | : addNgRxStoreDevToolsToPackageJson(),
|
106 | ])(host, context);
|
107 | };
|
108 | }
|
109 | exports["default"] = default_1;
|
110 |
|
\ | No newline at end of file |