UNPKG

3.35 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.exportPushModule = exports.importPushModule = exports.migrateToNgrxPush = void 0;
4var ts = require("typescript");
5var schematics_1 = require("@angular-devkit/schematics");
6var schematics_core_1 = require("../../schematics-core");
7var ASYNC_REGEXP = /\| {0,}async/g;
8var PUSH_MODULE = 'PushModule';
9var COMPONENT_MODULE = '@ngrx/component';
10var pushModuleToFind = function (node) {
11 return ts.isIdentifier(node) && node.text === PUSH_MODULE;
12};
13var ngModulesToFind = function (node) {
14 return ts.isIdentifier(node) &&
15 (node.text === 'CommonModule' || node.text === 'BrowserModule');
16};
17function migrateToNgrxPush() {
18 return function (host) {
19 return (0, schematics_core_1.visitTemplates)(host, function (template) {
20 var match;
21 var changes = [];
22 while ((match = ASYNC_REGEXP.exec(template.content)) !== null) {
23 var m = match.toString();
24 changes.push(new schematics_core_1.ReplaceChange(template.fileName,
25 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
26 template.start + match.index, m, m.replace('async', 'ngrxPush')));
27 }
28 return (0, schematics_core_1.commitChanges)(host, template.fileName, changes);
29 });
30 };
31}
32exports.migrateToNgrxPush = migrateToNgrxPush;
33function importPushModule() {
34 return function (host) {
35 (0, schematics_core_1.visitTSSourceFiles)(host, function (sourceFile) {
36 var hasCommonModuleOrBrowserModule = false;
37 var hasPushModule = false;
38 (0, schematics_core_1.visitNgModuleImports)(sourceFile, function (_, importNodes) {
39 hasCommonModuleOrBrowserModule = importNodes.some(ngModulesToFind);
40 hasPushModule = importNodes.some(pushModuleToFind);
41 });
42 if (hasCommonModuleOrBrowserModule && !hasPushModule) {
43 var changes = (0, schematics_core_1.addImportToModule)(sourceFile, sourceFile.fileName, PUSH_MODULE, COMPONENT_MODULE);
44 (0, schematics_core_1.commitChanges)(host, sourceFile.fileName, changes);
45 }
46 });
47 };
48}
49exports.importPushModule = importPushModule;
50function exportPushModule() {
51 return function (host) {
52 (0, schematics_core_1.visitTSSourceFiles)(host, function (sourceFile) {
53 var hasCommonModuleOrBrowserModule = false;
54 var hasPushModule = false;
55 (0, schematics_core_1.visitNgModuleExports)(sourceFile, function (_, exportNodes) {
56 hasCommonModuleOrBrowserModule = exportNodes.some(ngModulesToFind);
57 hasPushModule = exportNodes.some(pushModuleToFind);
58 });
59 if (hasCommonModuleOrBrowserModule && !hasPushModule) {
60 var changes = (0, schematics_core_1.addExportToModule)(sourceFile, sourceFile.fileName, PUSH_MODULE, COMPONENT_MODULE);
61 (0, schematics_core_1.commitChanges)(host, sourceFile.fileName, changes);
62 }
63 });
64 };
65}
66exports.exportPushModule = exportPushModule;
67function default_1() {
68 return (0, schematics_1.chain)([migrateToNgrxPush(), importPushModule(), exportPushModule()]);
69}
70exports.default = default_1;
71//# sourceMappingURL=index.js.map
\No newline at end of file