@ngrx/entity 21.0.0-rc.0 → 21.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/migrations/6_0_0/index.js +6 -3
- package/migrations/6_0_0/index.js.map +1 -1
- package/package.json +2 -2
- package/schematics/ng-add/index.js +13 -10
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics/ng-add/schema.js +2 -0
- package/schematics-core/index.js +75 -24
- package/schematics-core/index.js.map +1 -1
- package/schematics-core/utility/ast-utils.js +234 -260
- package/schematics-core/utility/ast-utils.js.map +1 -1
- package/schematics-core/utility/change.js +82 -92
- package/schematics-core/utility/change.js.map +1 -1
- package/schematics-core/utility/config.js +13 -9
- package/schematics-core/utility/config.js.map +1 -1
- package/schematics-core/utility/find-component.js +35 -30
- package/schematics-core/utility/find-component.js.map +1 -1
- package/schematics-core/utility/find-module.js +38 -33
- package/schematics-core/utility/find-module.js.map +1 -1
- package/schematics-core/utility/json-utilts.js +8 -27
- package/schematics-core/utility/json-utilts.js.map +1 -1
- package/schematics-core/utility/libs-version.js +4 -1
- package/schematics-core/utility/libs-version.js.map +1 -1
- package/schematics-core/utility/ngrx-utils.js +129 -152
- package/schematics-core/utility/ngrx-utils.js.map +1 -1
- package/schematics-core/utility/package.js +6 -4
- package/schematics-core/utility/package.js.map +1 -1
- package/schematics-core/utility/parse-name.js +8 -5
- package/schematics-core/utility/parse-name.js.map +1 -1
- package/schematics-core/utility/project.js +23 -17
- package/schematics-core/utility/project.js.map +1 -1
- package/schematics-core/utility/strings.js +32 -21
- package/schematics-core/utility/strings.js.map +1 -1
- package/schematics-core/utility/update.js +18 -15
- package/schematics-core/utility/update.js.map +1 -1
- package/schematics-core/utility/visitors.js +104 -192
- package/schematics-core/utility/visitors.js.map +1 -1
|
@@ -1,87 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return { value: o && o[i++], done: !o };
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
|
-
};
|
|
12
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
-
if (!m) return o;
|
|
15
|
-
var i = m.call(o), r, ar = [], e;
|
|
16
|
-
try {
|
|
17
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
-
}
|
|
19
|
-
catch (error) { e = { error: error }; }
|
|
20
|
-
finally {
|
|
21
|
-
try {
|
|
22
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
-
}
|
|
24
|
-
finally { if (e) throw e.error; }
|
|
25
|
-
}
|
|
26
|
-
return ar;
|
|
27
|
-
};
|
|
28
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
-
if (ar || !(i in from)) {
|
|
31
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
-
ar[i] = from[i];
|
|
33
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
34
7
|
}
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.addReducerToState = addReducerToState;
|
|
37
|
+
exports.addReducerToStateInterface = addReducerToStateInterface;
|
|
38
|
+
exports.addReducerToActionReducerMap = addReducerToActionReducerMap;
|
|
39
|
+
exports.addReducerImportToNgModule = addReducerImportToNgModule;
|
|
40
|
+
exports.omit = omit;
|
|
41
|
+
exports.getPrefix = getPrefix;
|
|
42
|
+
const ts = __importStar(require("typescript"));
|
|
43
|
+
const stringUtils = __importStar(require("./strings"));
|
|
44
|
+
const change_1 = require("./change");
|
|
45
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
46
|
+
const core_1 = require("@angular-devkit/core");
|
|
47
|
+
const find_module_1 = require("./find-module");
|
|
48
|
+
const ast_utils_1 = require("./ast-utils");
|
|
49
|
+
function addReducerToState(options) {
|
|
50
|
+
return (host) => {
|
|
47
51
|
if (!options.reducers) {
|
|
48
52
|
return host;
|
|
49
53
|
}
|
|
50
|
-
|
|
54
|
+
const reducersPath = (0, core_1.normalize)(`/${options.path}/${options.reducers}`);
|
|
51
55
|
if (!host.exists(reducersPath)) {
|
|
52
|
-
throw new Error(
|
|
56
|
+
throw new Error(`Specified reducers path ${reducersPath} does not exist`);
|
|
53
57
|
}
|
|
54
|
-
|
|
58
|
+
const text = host.read(reducersPath);
|
|
55
59
|
if (text === null) {
|
|
56
|
-
throw new SchematicsException(
|
|
60
|
+
throw new schematics_1.SchematicsException(`File ${reducersPath} does not exist.`);
|
|
57
61
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
const sourceText = text.toString('utf-8');
|
|
63
|
+
const source = ts.createSourceFile(reducersPath, sourceText, ts.ScriptTarget.Latest, true);
|
|
64
|
+
const reducerPath = `/${options.path}/` +
|
|
61
65
|
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
|
|
62
66
|
(options.group ? 'reducers/' : '') +
|
|
63
67
|
stringUtils.dasherize(options.name) +
|
|
64
68
|
'.reducer';
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (change instanceof InsertChange) {
|
|
75
|
-
recorder.insertLeft(change.pos, change.toAdd);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
80
|
-
finally {
|
|
81
|
-
try {
|
|
82
|
-
if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
|
|
69
|
+
const relativePath = (0, find_module_1.buildRelativePath)(reducersPath, reducerPath);
|
|
70
|
+
const reducerImport = (0, ast_utils_1.insertImport)(source, reducersPath, `* as from${stringUtils.classify(options.name)}`, relativePath, true);
|
|
71
|
+
const stateInterfaceInsert = addReducerToStateInterface(source, reducersPath, options);
|
|
72
|
+
const reducerMapInsert = addReducerToActionReducerMap(source, reducersPath, options);
|
|
73
|
+
const changes = [reducerImport, stateInterfaceInsert, reducerMapInsert];
|
|
74
|
+
const recorder = host.beginUpdate(reducersPath);
|
|
75
|
+
for (const change of changes) {
|
|
76
|
+
if (change instanceof change_1.InsertChange) {
|
|
77
|
+
recorder.insertLeft(change.pos, change.toAdd);
|
|
83
78
|
}
|
|
84
|
-
finally { if (e_1) throw e_1.error; }
|
|
85
79
|
}
|
|
86
80
|
host.commitUpdate(recorder);
|
|
87
81
|
return host;
|
|
@@ -90,150 +84,133 @@ export function addReducerToState(options) {
|
|
|
90
84
|
/**
|
|
91
85
|
* Insert the reducer into the first defined top level interface
|
|
92
86
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
function addReducerToStateInterface(source, reducersPath, options) {
|
|
88
|
+
const stateInterface = source.statements.find((stm) => stm.kind === ts.SyntaxKind.InterfaceDeclaration);
|
|
89
|
+
let node = stateInterface;
|
|
96
90
|
if (!node) {
|
|
97
|
-
return new NoopChange();
|
|
91
|
+
return new change_1.NoopChange();
|
|
98
92
|
}
|
|
99
|
-
|
|
93
|
+
const state = options.plural
|
|
100
94
|
? stringUtils.pluralize(options.name)
|
|
101
95
|
: stringUtils.camelize(options.name);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
96
|
+
const keyInsert = `[from${stringUtils.classify(options.name)}.${stringUtils.camelize(state)}FeatureKey]: from${stringUtils.classify(options.name)}.State;`;
|
|
97
|
+
const expr = node;
|
|
98
|
+
let position;
|
|
99
|
+
let toInsert;
|
|
106
100
|
if (expr.members.length === 0) {
|
|
107
101
|
position = expr.getEnd() - 1;
|
|
108
|
-
toInsert =
|
|
102
|
+
toInsert = ` ${keyInsert}\n`;
|
|
109
103
|
}
|
|
110
104
|
else {
|
|
111
105
|
node = expr.members[expr.members.length - 1];
|
|
112
106
|
position = node.getEnd() + 1;
|
|
113
107
|
// Get the indentation of the last element, if any.
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
const text = node.getFullText(source);
|
|
109
|
+
const matches = text.match(/^\r?\n+(\s*)/);
|
|
116
110
|
if (matches && matches.length > 0) {
|
|
117
|
-
toInsert =
|
|
111
|
+
toInsert = `${matches[1]}${keyInsert}\n`;
|
|
118
112
|
}
|
|
119
113
|
else {
|
|
120
|
-
toInsert =
|
|
114
|
+
toInsert = `\n${keyInsert}`;
|
|
121
115
|
}
|
|
122
116
|
}
|
|
123
|
-
return new InsertChange(reducersPath, position, toInsert);
|
|
117
|
+
return new change_1.InsertChange(reducersPath, position, toInsert);
|
|
124
118
|
}
|
|
125
119
|
/**
|
|
126
120
|
* Insert the reducer into the ActionReducerMap
|
|
127
121
|
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
.filter(
|
|
132
|
-
.filter(
|
|
133
|
-
.map(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return { initializer: variable.initializer, type
|
|
122
|
+
function addReducerToActionReducerMap(source, reducersPath, options) {
|
|
123
|
+
let initializer;
|
|
124
|
+
const actionReducerMap = source.statements
|
|
125
|
+
.filter((stm) => stm.kind === ts.SyntaxKind.VariableStatement)
|
|
126
|
+
.filter((stm) => !!stm.declarationList)
|
|
127
|
+
.map((stm) => {
|
|
128
|
+
const { declarations, } = stm.declarationList;
|
|
129
|
+
const variable = declarations.find((decl) => decl.kind === ts.SyntaxKind.VariableDeclaration);
|
|
130
|
+
const type = variable ? variable.type : {};
|
|
131
|
+
return { initializer: variable.initializer, type };
|
|
138
132
|
})
|
|
139
|
-
.filter(
|
|
140
|
-
.find(
|
|
141
|
-
var type = _a.type;
|
|
142
|
-
return type.typeName.text === 'ActionReducerMap';
|
|
143
|
-
});
|
|
133
|
+
.filter((initWithType) => initWithType.type !== undefined)
|
|
134
|
+
.find(({ type }) => type.typeName.text === 'ActionReducerMap');
|
|
144
135
|
if (!actionReducerMap || !actionReducerMap.initializer) {
|
|
145
|
-
return new NoopChange();
|
|
136
|
+
return new change_1.NoopChange();
|
|
146
137
|
}
|
|
147
|
-
|
|
148
|
-
|
|
138
|
+
let node = actionReducerMap.initializer;
|
|
139
|
+
const state = options.plural
|
|
149
140
|
? stringUtils.pluralize(options.name)
|
|
150
141
|
: stringUtils.camelize(options.name);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
142
|
+
const keyInsert = `[from${stringUtils.classify(options.name)}.${stringUtils.camelize(state)}FeatureKey]: from${stringUtils.classify(options.name)}.reducer,`;
|
|
143
|
+
const expr = node;
|
|
144
|
+
let position;
|
|
145
|
+
let toInsert;
|
|
155
146
|
if (expr.properties.length === 0) {
|
|
156
147
|
position = expr.getEnd() - 1;
|
|
157
|
-
toInsert =
|
|
148
|
+
toInsert = ` ${keyInsert}\n`;
|
|
158
149
|
}
|
|
159
150
|
else {
|
|
160
151
|
node = expr.properties[expr.properties.length - 1];
|
|
161
152
|
position = node.getEnd() + 1;
|
|
162
153
|
// Get the indentation of the last element, if any.
|
|
163
|
-
|
|
164
|
-
|
|
154
|
+
const text = node.getFullText(source);
|
|
155
|
+
const matches = text.match(/^\r?\n+(\s*)/);
|
|
165
156
|
if (matches && matches.length > 0) {
|
|
166
|
-
toInsert =
|
|
157
|
+
toInsert = `\n${matches[1]}${keyInsert}`;
|
|
167
158
|
}
|
|
168
159
|
else {
|
|
169
|
-
toInsert =
|
|
160
|
+
toInsert = `\n${keyInsert}`;
|
|
170
161
|
}
|
|
171
162
|
}
|
|
172
|
-
return new InsertChange(reducersPath, position, toInsert);
|
|
163
|
+
return new change_1.InsertChange(reducersPath, position, toInsert);
|
|
173
164
|
}
|
|
174
165
|
/**
|
|
175
166
|
* Add reducer feature to NgModule
|
|
176
167
|
*/
|
|
177
|
-
|
|
178
|
-
return
|
|
179
|
-
var e_2, _a;
|
|
168
|
+
function addReducerImportToNgModule(options) {
|
|
169
|
+
return (host) => {
|
|
180
170
|
if (!options.module) {
|
|
181
171
|
return host;
|
|
182
172
|
}
|
|
183
|
-
|
|
173
|
+
const modulePath = options.module;
|
|
184
174
|
if (!host.exists(options.module)) {
|
|
185
|
-
throw new Error(
|
|
175
|
+
throw new Error(`Specified module path ${modulePath} does not exist`);
|
|
186
176
|
}
|
|
187
|
-
|
|
177
|
+
const text = host.read(modulePath);
|
|
188
178
|
if (text === null) {
|
|
189
|
-
throw new SchematicsException(
|
|
179
|
+
throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
|
|
190
180
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),
|
|
181
|
+
const sourceText = text.toString('utf-8');
|
|
182
|
+
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
183
|
+
const commonImports = [
|
|
184
|
+
(0, ast_utils_1.insertImport)(source, modulePath, 'StoreModule', '@ngrx/store'),
|
|
195
185
|
];
|
|
196
|
-
|
|
186
|
+
const reducerPath = `/${options.path}/` +
|
|
197
187
|
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
|
|
198
188
|
(options.group ? 'reducers/' : '') +
|
|
199
189
|
stringUtils.dasherize(options.name) +
|
|
200
190
|
'.reducer';
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
191
|
+
const relativePath = (0, find_module_1.buildRelativePath)(modulePath, reducerPath);
|
|
192
|
+
const reducerImport = (0, ast_utils_1.insertImport)(source, modulePath, `* as from${stringUtils.classify(options.name)}`, relativePath, true);
|
|
193
|
+
const state = options.plural
|
|
204
194
|
? stringUtils.pluralize(options.name)
|
|
205
195
|
: stringUtils.camelize(options.name);
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (change instanceof InsertChange) {
|
|
213
|
-
recorder.insertLeft(change.pos, change.toAdd);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
218
|
-
finally {
|
|
219
|
-
try {
|
|
220
|
-
if (changes_2_1 && !changes_2_1.done && (_a = changes_2.return)) _a.call(changes_2);
|
|
196
|
+
const [storeNgModuleImport] = (0, ast_utils_1.addImportToModule)(source, modulePath, `StoreModule.forFeature(from${stringUtils.classify(options.name)}.${state}FeatureKey, from${stringUtils.classify(options.name)}.reducer)`, relativePath);
|
|
197
|
+
const changes = [...commonImports, reducerImport, storeNgModuleImport];
|
|
198
|
+
const recorder = host.beginUpdate(modulePath);
|
|
199
|
+
for (const change of changes) {
|
|
200
|
+
if (change instanceof change_1.InsertChange) {
|
|
201
|
+
recorder.insertLeft(change.pos, change.toAdd);
|
|
221
202
|
}
|
|
222
|
-
finally { if (e_2) throw e_2.error; }
|
|
223
203
|
}
|
|
224
204
|
host.commitUpdate(recorder);
|
|
225
205
|
return host;
|
|
226
206
|
};
|
|
227
207
|
}
|
|
228
|
-
|
|
208
|
+
function omit(object, keyToRemove) {
|
|
229
209
|
return Object.keys(object)
|
|
230
|
-
.filter(
|
|
231
|
-
.reduce(
|
|
232
|
-
var _a;
|
|
233
|
-
return Object.assign(result, (_a = {}, _a[key] = object[key], _a));
|
|
234
|
-
}, {});
|
|
210
|
+
.filter((key) => key !== keyToRemove)
|
|
211
|
+
.reduce((result, key) => Object.assign(result, { [key]: object[key] }), {});
|
|
235
212
|
}
|
|
236
|
-
|
|
213
|
+
function getPrefix(options) {
|
|
237
214
|
return stringUtils.camelize(options.prefix || 'load');
|
|
238
215
|
}
|
|
239
216
|
//# sourceMappingURL=ngrx-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngrx-utils.js","sourceRoot":"","sources":["../../../../../modules/entity/schematics-core/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gBAA1B,IAAM,MAAM,oBAAA;gBACf,IAAI,MAAM,YAAY,YAAY,EAAE,CAAC;oBACnC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;gBAChD,CAAC;YACH,CAAC;;;;;;;;;QACD,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAE5B,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI,CAClB,MAAS,EACT,WAAoB;IAEpB,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SACvB,MAAM,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,KAAK,WAAW,EAAnB,CAAmB,CAAC;SACpC,MAAM,CAAC,UAAC,MAAM,EAAE,GAAG;;QAAK,OAAA,MAAM,CAAC,MAAM,CAAC,MAAM,YAAI,GAAC,GAAG,IAAG,MAAM,CAAC,GAAG,CAAC,MAAG;IAA7C,CAA6C,EAAE,EAAE,CAAC,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,OAA4B;IACpD,OAAO,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC;AACxD,CAAC","sourcesContent":["import * as ts from 'typescript';\nimport * as stringUtils from './strings';\nimport { InsertChange, Change, NoopChange } from './change';\nimport { Tree, SchematicsException, Rule } from '@angular-devkit/schematics';\nimport { normalize } from '@angular-devkit/core';\nimport { buildRelativePath } from './find-module';\nimport { addImportToModule, insertImport } from './ast-utils';\n\nexport function addReducerToState(options: any): Rule {\n return (host: Tree) => {\n if (!options.reducers) {\n return host;\n }\n\n const reducersPath = normalize(`/${options.path}/${options.reducers}`);\n\n if (!host.exists(reducersPath)) {\n throw new Error(`Specified reducers path ${reducersPath} does not exist`);\n }\n\n const text = host.read(reducersPath);\n if (text === null) {\n throw new SchematicsException(`File ${reducersPath} does not exist.`);\n }\n\n const sourceText = text.toString('utf-8');\n\n const source = ts.createSourceFile(\n reducersPath,\n sourceText,\n ts.ScriptTarget.Latest,\n true\n );\n\n const reducerPath =\n `/${options.path}/` +\n (options.flat ? '' : stringUtils.dasherize(options.name) + '/') +\n (options.group ? 'reducers/' : '') +\n stringUtils.dasherize(options.name) +\n '.reducer';\n\n const relativePath = buildRelativePath(reducersPath, reducerPath);\n const reducerImport = insertImport(\n source,\n reducersPath,\n `* as from${stringUtils.classify(options.name)}`,\n relativePath,\n true\n );\n\n const stateInterfaceInsert = addReducerToStateInterface(\n source,\n reducersPath,\n options\n );\n const reducerMapInsert = addReducerToActionReducerMap(\n source,\n reducersPath,\n options\n );\n\n const changes = [reducerImport, stateInterfaceInsert, reducerMapInsert];\n const recorder = host.beginUpdate(reducersPath);\n for (const change of changes) {\n if (change instanceof InsertChange) {\n recorder.insertLeft(change.pos, change.toAdd);\n }\n }\n host.commitUpdate(recorder);\n\n return host;\n };\n}\n\n/**\n * Insert the reducer into the first defined top level interface\n */\nexport function addReducerToStateInterface(\n source: ts.SourceFile,\n reducersPath: string,\n options: { name: string; plural: boolean }\n): Change {\n const stateInterface = source.statements.find(\n (stm) => stm.kind === ts.SyntaxKind.InterfaceDeclaration\n );\n let node = stateInterface as ts.Statement;\n\n if (!node) {\n return new NoopChange();\n }\n\n const state = options.plural\n ? stringUtils.pluralize(options.name)\n : stringUtils.camelize(options.name);\n\n const keyInsert = `[from${stringUtils.classify(\n options.name\n )}.${stringUtils.camelize(state)}FeatureKey]: from${stringUtils.classify(\n options.name\n )}.State;`;\n const expr = node as any;\n let position;\n let toInsert;\n\n if (expr.members.length === 0) {\n position = expr.getEnd() - 1;\n toInsert = ` ${keyInsert}\\n`;\n } else {\n node = expr.members[expr.members.length - 1];\n position = node.getEnd() + 1;\n // Get the indentation of the last element, if any.\n const text = node.getFullText(source);\n const matches = text.match(/^\\r?\\n+(\\s*)/);\n\n if (matches && matches.length > 0) {\n toInsert = `${matches[1]}${keyInsert}\\n`;\n } else {\n toInsert = `\\n${keyInsert}`;\n }\n }\n\n return new InsertChange(reducersPath, position, toInsert);\n}\n\n/**\n * Insert the reducer into the ActionReducerMap\n */\nexport function addReducerToActionReducerMap(\n source: ts.SourceFile,\n reducersPath: string,\n options: { name: string; plural: boolean }\n): Change {\n let initializer: any;\n const actionReducerMap: any = source.statements\n .filter((stm) => stm.kind === ts.SyntaxKind.VariableStatement)\n .filter((stm: any) => !!stm.declarationList)\n .map((stm: any) => {\n const {\n declarations,\n }: {\n declarations: ts.SyntaxKind.VariableDeclarationList[];\n } = stm.declarationList;\n const variable: any = declarations.find(\n (decl: any) => decl.kind === ts.SyntaxKind.VariableDeclaration\n );\n const type = variable ? variable.type : {};\n\n return { initializer: variable.initializer, type };\n })\n .filter((initWithType) => initWithType.type !== undefined)\n .find(({ type }) => type.typeName.text === 'ActionReducerMap');\n\n if (!actionReducerMap || !actionReducerMap.initializer) {\n return new NoopChange();\n }\n\n let node = actionReducerMap.initializer;\n\n const state = options.plural\n ? stringUtils.pluralize(options.name)\n : stringUtils.camelize(options.name);\n\n const keyInsert = `[from${stringUtils.classify(\n options.name\n )}.${stringUtils.camelize(state)}FeatureKey]: from${stringUtils.classify(\n options.name\n )}.reducer,`;\n const expr = node as any;\n let position;\n let toInsert;\n\n if (expr.properties.length === 0) {\n position = expr.getEnd() - 1;\n toInsert = ` ${keyInsert}\\n`;\n } else {\n node = expr.properties[expr.properties.length - 1];\n position = node.getEnd() + 1;\n // Get the indentation of the last element, if any.\n const text = node.getFullText(source);\n const matches = text.match(/^\\r?\\n+(\\s*)/);\n\n if (matches && matches.length > 0) {\n toInsert = `\\n${matches[1]}${keyInsert}`;\n } else {\n toInsert = `\\n${keyInsert}`;\n }\n }\n\n return new InsertChange(reducersPath, position, toInsert);\n}\n\n/**\n * Add reducer feature to NgModule\n */\nexport function addReducerImportToNgModule(options: any): Rule {\n return (host: Tree) => {\n if (!options.module) {\n return host;\n }\n\n const modulePath = options.module;\n if (!host.exists(options.module)) {\n throw new Error(`Specified module path ${modulePath} does not exist`);\n }\n\n const text = host.read(modulePath);\n if (text === null) {\n throw new SchematicsException(`File ${modulePath} does not exist.`);\n }\n const sourceText = text.toString('utf-8');\n\n const source = ts.createSourceFile(\n modulePath,\n sourceText,\n ts.ScriptTarget.Latest,\n true\n );\n\n const commonImports = [\n insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),\n ];\n\n const reducerPath =\n `/${options.path}/` +\n (options.flat ? '' : stringUtils.dasherize(options.name) + '/') +\n (options.group ? 'reducers/' : '') +\n stringUtils.dasherize(options.name) +\n '.reducer';\n const relativePath = buildRelativePath(modulePath, reducerPath);\n const reducerImport = insertImport(\n source,\n modulePath,\n `* as from${stringUtils.classify(options.name)}`,\n relativePath,\n true\n );\n const state = options.plural\n ? stringUtils.pluralize(options.name)\n : stringUtils.camelize(options.name);\n const [storeNgModuleImport] = addImportToModule(\n source,\n modulePath,\n `StoreModule.forFeature(from${stringUtils.classify(\n options.name\n )}.${state}FeatureKey, from${stringUtils.classify(\n options.name\n )}.reducer)`,\n relativePath\n );\n const changes = [...commonImports, reducerImport, storeNgModuleImport];\n const recorder = host.beginUpdate(modulePath);\n for (const change of changes) {\n if (change instanceof InsertChange) {\n recorder.insertLeft(change.pos, change.toAdd);\n }\n }\n host.commitUpdate(recorder);\n\n return host;\n };\n}\n\nexport function omit<T extends { [key: string]: any }>(\n object: T,\n keyToRemove: keyof T\n): Partial<T> {\n return Object.keys(object)\n .filter((key) => key !== keyToRemove)\n .reduce((result, key) => Object.assign(result, { [key]: object[key] }), {});\n}\n\nexport function getPrefix(options: { prefix?: string }) {\n return stringUtils.camelize(options.prefix || 'load');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ngrx-utils.js","sourceRoot":"","sources":["../../../../../modules/entity/schematics-core/utility/ngrx-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,8CAgEC;AAKD,gEA6CC;AAKD,oEA8DC;AAKD,gEAkEC;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G,EAAE,EAAE,CAAC,GAAG,KAAK,WAAW,CAAC;SACpC,MAAM,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAChF,CAAC;AAED,SAAgB,SAAS,CAAC,OAA4B;IACpD,OAAO,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC;AACxD,CAAC","sourcesContent":["import * as ts from 'typescript';\nimport * as stringUtils from './strings';\nimport { InsertChange, Change, NoopChange } from './change';\nimport { Tree, SchematicsException, Rule } from '@angular-devkit/schematics';\nimport { normalize } from '@angular-devkit/core';\nimport { buildRelativePath } from './find-module';\nimport { addImportToModule, insertImport } from './ast-utils';\n\nexport function addReducerToState(options: any): Rule {\n return (host: Tree) => {\n if (!options.reducers) {\n return host;\n }\n\n const reducersPath = normalize(`/${options.path}/${options.reducers}`);\n\n if (!host.exists(reducersPath)) {\n throw new Error(`Specified reducers path ${reducersPath} does not exist`);\n }\n\n const text = host.read(reducersPath);\n if (text === null) {\n throw new SchematicsException(`File ${reducersPath} does not exist.`);\n }\n\n const sourceText = text.toString('utf-8');\n\n const source = ts.createSourceFile(\n reducersPath,\n sourceText,\n ts.ScriptTarget.Latest,\n true\n );\n\n const reducerPath =\n `/${options.path}/` +\n (options.flat ? '' : stringUtils.dasherize(options.name) + '/') +\n (options.group ? 'reducers/' : '') +\n stringUtils.dasherize(options.name) +\n '.reducer';\n\n const relativePath = buildRelativePath(reducersPath, reducerPath);\n const reducerImport = insertImport(\n source,\n reducersPath,\n `* as from${stringUtils.classify(options.name)}`,\n relativePath,\n true\n );\n\n const stateInterfaceInsert = addReducerToStateInterface(\n source,\n reducersPath,\n options\n );\n const reducerMapInsert = addReducerToActionReducerMap(\n source,\n reducersPath,\n options\n );\n\n const changes = [reducerImport, stateInterfaceInsert, reducerMapInsert];\n const recorder = host.beginUpdate(reducersPath);\n for (const change of changes) {\n if (change instanceof InsertChange) {\n recorder.insertLeft(change.pos, change.toAdd);\n }\n }\n host.commitUpdate(recorder);\n\n return host;\n };\n}\n\n/**\n * Insert the reducer into the first defined top level interface\n */\nexport function addReducerToStateInterface(\n source: ts.SourceFile,\n reducersPath: string,\n options: { name: string; plural: boolean }\n): Change {\n const stateInterface = source.statements.find(\n (stm) => stm.kind === ts.SyntaxKind.InterfaceDeclaration\n );\n let node = stateInterface as ts.Statement;\n\n if (!node) {\n return new NoopChange();\n }\n\n const state = options.plural\n ? stringUtils.pluralize(options.name)\n : stringUtils.camelize(options.name);\n\n const keyInsert = `[from${stringUtils.classify(\n options.name\n )}.${stringUtils.camelize(state)}FeatureKey]: from${stringUtils.classify(\n options.name\n )}.State;`;\n const expr = node as any;\n let position;\n let toInsert;\n\n if (expr.members.length === 0) {\n position = expr.getEnd() - 1;\n toInsert = ` ${keyInsert}\\n`;\n } else {\n node = expr.members[expr.members.length - 1];\n position = node.getEnd() + 1;\n // Get the indentation of the last element, if any.\n const text = node.getFullText(source);\n const matches = text.match(/^\\r?\\n+(\\s*)/);\n\n if (matches && matches.length > 0) {\n toInsert = `${matches[1]}${keyInsert}\\n`;\n } else {\n toInsert = `\\n${keyInsert}`;\n }\n }\n\n return new InsertChange(reducersPath, position, toInsert);\n}\n\n/**\n * Insert the reducer into the ActionReducerMap\n */\nexport function addReducerToActionReducerMap(\n source: ts.SourceFile,\n reducersPath: string,\n options: { name: string; plural: boolean }\n): Change {\n let initializer: any;\n const actionReducerMap: any = source.statements\n .filter((stm) => stm.kind === ts.SyntaxKind.VariableStatement)\n .filter((stm: any) => !!stm.declarationList)\n .map((stm: any) => {\n const {\n declarations,\n }: {\n declarations: ts.SyntaxKind.VariableDeclarationList[];\n } = stm.declarationList;\n const variable: any = declarations.find(\n (decl: any) => decl.kind === ts.SyntaxKind.VariableDeclaration\n );\n const type = variable ? variable.type : {};\n\n return { initializer: variable.initializer, type };\n })\n .filter((initWithType) => initWithType.type !== undefined)\n .find(({ type }) => type.typeName.text === 'ActionReducerMap');\n\n if (!actionReducerMap || !actionReducerMap.initializer) {\n return new NoopChange();\n }\n\n let node = actionReducerMap.initializer;\n\n const state = options.plural\n ? stringUtils.pluralize(options.name)\n : stringUtils.camelize(options.name);\n\n const keyInsert = `[from${stringUtils.classify(\n options.name\n )}.${stringUtils.camelize(state)}FeatureKey]: from${stringUtils.classify(\n options.name\n )}.reducer,`;\n const expr = node as any;\n let position;\n let toInsert;\n\n if (expr.properties.length === 0) {\n position = expr.getEnd() - 1;\n toInsert = ` ${keyInsert}\\n`;\n } else {\n node = expr.properties[expr.properties.length - 1];\n position = node.getEnd() + 1;\n // Get the indentation of the last element, if any.\n const text = node.getFullText(source);\n const matches = text.match(/^\\r?\\n+(\\s*)/);\n\n if (matches && matches.length > 0) {\n toInsert = `\\n${matches[1]}${keyInsert}`;\n } else {\n toInsert = `\\n${keyInsert}`;\n }\n }\n\n return new InsertChange(reducersPath, position, toInsert);\n}\n\n/**\n * Add reducer feature to NgModule\n */\nexport function addReducerImportToNgModule(options: any): Rule {\n return (host: Tree) => {\n if (!options.module) {\n return host;\n }\n\n const modulePath = options.module;\n if (!host.exists(options.module)) {\n throw new Error(`Specified module path ${modulePath} does not exist`);\n }\n\n const text = host.read(modulePath);\n if (text === null) {\n throw new SchematicsException(`File ${modulePath} does not exist.`);\n }\n const sourceText = text.toString('utf-8');\n\n const source = ts.createSourceFile(\n modulePath,\n sourceText,\n ts.ScriptTarget.Latest,\n true\n );\n\n const commonImports = [\n insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),\n ];\n\n const reducerPath =\n `/${options.path}/` +\n (options.flat ? '' : stringUtils.dasherize(options.name) + '/') +\n (options.group ? 'reducers/' : '') +\n stringUtils.dasherize(options.name) +\n '.reducer';\n const relativePath = buildRelativePath(modulePath, reducerPath);\n const reducerImport = insertImport(\n source,\n modulePath,\n `* as from${stringUtils.classify(options.name)}`,\n relativePath,\n true\n );\n const state = options.plural\n ? stringUtils.pluralize(options.name)\n : stringUtils.camelize(options.name);\n const [storeNgModuleImport] = addImportToModule(\n source,\n modulePath,\n `StoreModule.forFeature(from${stringUtils.classify(\n options.name\n )}.${state}FeatureKey, from${stringUtils.classify(\n options.name\n )}.reducer)`,\n relativePath\n );\n const changes = [...commonImports, reducerImport, storeNgModuleImport];\n const recorder = host.beginUpdate(modulePath);\n for (const change of changes) {\n if (change instanceof InsertChange) {\n recorder.insertLeft(change.pos, change.toAdd);\n }\n }\n host.commitUpdate(recorder);\n\n return host;\n };\n}\n\nexport function omit<T extends { [key: string]: any }>(\n object: T,\n keyToRemove: keyof T\n): Partial<T> {\n return Object.keys(object)\n .filter((key) => key !== keyToRemove)\n .reduce((result, key) => Object.assign(result, { [key]: object[key] }), {});\n}\n\nexport function getPrefix(options: { prefix?: string }) {\n return stringUtils.camelize(options.prefix || 'load');\n}\n"]}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addPackageToPackageJson = addPackageToPackageJson;
|
|
1
4
|
/**
|
|
2
5
|
* Adds a package to the package.json
|
|
3
6
|
*/
|
|
4
|
-
|
|
5
|
-
var _a, _b;
|
|
7
|
+
function addPackageToPackageJson(host, type, pkg, version) {
|
|
6
8
|
if (host.exists('package.json')) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
const sourceText = host.read('package.json')?.toString('utf-8') ?? '{}';
|
|
10
|
+
const json = JSON.parse(sourceText);
|
|
9
11
|
if (!json[type]) {
|
|
10
12
|
json[type] = {};
|
|
11
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.js","sourceRoot":"","sources":["../../../../../modules/entity/schematics-core/utility/package.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"package.js","sourceRoot":"","sources":["../../../../../modules/entity/schematics-core/utility/package.ts"],"names":[],"mappings":";;AAKA,0DAqBC;AAxBD;;GAEG;AACH,SAAgB,uBAAuB,CACrC,IAAU,EACV,IAAY,EACZ,GAAW,EACX,OAAe;IAEf,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;QACxE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAChB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAClB,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;QAC5B,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { Tree } from '@angular-devkit/schematics';\n\n/**\n * Adds a package to the package.json\n */\nexport function addPackageToPackageJson(\n host: Tree,\n type: string,\n pkg: string,\n version: string\n): Tree {\n if (host.exists('package.json')) {\n const sourceText = host.read('package.json')?.toString('utf-8') ?? '{}';\n const json = JSON.parse(sourceText);\n if (!json[type]) {\n json[type] = {};\n }\n\n if (!json[type][pkg]) {\n json[type][pkg] = version;\n }\n\n host.overwrite('package.json', JSON.stringify(json, null, 2));\n }\n\n return host;\n}\n"]}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseName = parseName;
|
|
4
|
+
const core_1 = require("@angular-devkit/core");
|
|
5
|
+
function parseName(path, name) {
|
|
6
|
+
const nameWithoutPath = (0, core_1.basename)(name);
|
|
7
|
+
const namePath = (0, core_1.dirname)((path + '/' + name));
|
|
5
8
|
return {
|
|
6
9
|
name: nameWithoutPath,
|
|
7
|
-
path: normalize('/' + namePath),
|
|
10
|
+
path: (0, core_1.normalize)('/' + namePath),
|
|
8
11
|
};
|
|
9
12
|
}
|
|
10
13
|
//# sourceMappingURL=parse-name.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-name.js","sourceRoot":"","sources":["../../../../../modules/entity/schematics-core/utility/parse-name.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-name.js","sourceRoot":"","sources":["../../../../../modules/entity/schematics-core/utility/parse-name.ts"],"names":[],"mappings":";;AAOA,8BAQC;AAfD,+CAA0E;AAO1E,SAAgB,SAAS,CAAC,IAAY,EAAE,IAAY;IAClD,MAAM,eAAe,GAAG,IAAA,eAAQ,EAAC,IAAY,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,IAAA,cAAO,EAAC,CAAC,IAAI,GAAG,GAAG,GAAG,IAAI,CAAS,CAAC,CAAC;IAEtD,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,IAAA,gBAAS,EAAC,GAAG,GAAG,QAAQ,CAAC;KAChC,CAAC;AACJ,CAAC","sourcesContent":["import { Path, basename, dirname, normalize } from '@angular-devkit/core';\n\nexport interface Location {\n name: string;\n path: Path;\n}\n\nexport function parseName(path: string, name: string): Location {\n const nameWithoutPath = basename(name as Path);\n const namePath = dirname((path + '/' + name) as Path);\n\n return {\n name: nameWithoutPath,\n path: normalize('/' + namePath),\n };\n}\n"]}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProject = getProject;
|
|
4
|
+
exports.getProjectPath = getProjectPath;
|
|
5
|
+
exports.isLib = isLib;
|
|
6
|
+
exports.getProjectMainFile = getProjectMainFile;
|
|
7
|
+
const config_1 = require("./config");
|
|
8
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
9
|
+
function getProject(host, options) {
|
|
10
|
+
const workspace = (0, config_1.getWorkspace)(host);
|
|
5
11
|
if (!options.project) {
|
|
6
|
-
|
|
12
|
+
const defaultProject = workspace
|
|
7
13
|
.defaultProject;
|
|
8
14
|
options.project =
|
|
9
15
|
defaultProject !== undefined
|
|
@@ -12,29 +18,29 @@ export function getProject(host, options) {
|
|
|
12
18
|
}
|
|
13
19
|
return workspace.projects[options.project];
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
function getProjectPath(host, options) {
|
|
22
|
+
const project = getProject(host, options);
|
|
17
23
|
if (project.root.slice(-1) === '/') {
|
|
18
24
|
project.root = project.root.substring(0, project.root.length - 1);
|
|
19
25
|
}
|
|
20
26
|
if (options.path === undefined) {
|
|
21
|
-
|
|
22
|
-
return
|
|
27
|
+
const projectDirName = project.projectType === 'application' ? 'app' : 'lib';
|
|
28
|
+
return `${project.root ? `/${project.root}` : ''}/src/${projectDirName}`;
|
|
23
29
|
}
|
|
24
30
|
return options.path;
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
function isLib(host, options) {
|
|
33
|
+
const project = getProject(host, options);
|
|
28
34
|
return project.projectType === 'library';
|
|
29
35
|
}
|
|
30
|
-
|
|
36
|
+
function getProjectMainFile(host, options) {
|
|
31
37
|
if (isLib(host, options)) {
|
|
32
|
-
throw new SchematicsException(
|
|
38
|
+
throw new schematics_1.SchematicsException(`Invalid project type`);
|
|
33
39
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!
|
|
37
|
-
throw new SchematicsException(
|
|
40
|
+
const project = getProject(host, options);
|
|
41
|
+
const projectOptions = project.architect['build'].options;
|
|
42
|
+
if (!projectOptions?.main && !projectOptions?.browser) {
|
|
43
|
+
throw new schematics_1.SchematicsException(`Could not find the main file ${project}`);
|
|
38
44
|
}
|
|
39
45
|
return (projectOptions.browser || projectOptions.main);
|
|
40
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../../../../modules/entity/schematics-core/utility/project.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../../../../modules/entity/schematics-core/utility/project.ts"],"names":[],"mappings":";;AAYA,gCAgBC;AAED,wCAkBC;AAED,sBAOC;AAED,gDAeC;AAzED,qCAAwC;AACxC,2DAAuE;AAUvE,SAAgB,UAAU,CACxB,IAAU,EACV,OAAoE;IAEpE,MAAM,SAAS,GAAG,IAAA,qBAAY,EAAC,IAAI,CAAC,CAAC;IAErC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACrB,MAAM,cAAc,GAAI,SAAyC;aAC9D,cAAc,CAAC;QAClB,OAAO,CAAC,OAAO;YACb,cAAc,KAAK,SAAS;gBAC1B,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC;AAED,SAAgB,cAAc,CAC5B,IAAU,EACV,OAAoE;IAEpE,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAE1C,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QACnC,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,cAAc,GAClB,OAAO,CAAC,WAAW,KAAK,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QAExD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,cAAc,EAAE,CAAC;IAC3E,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC;AAED,SAAgB,KAAK,CACnB,IAAU,EACV,OAAoE;IAEpE,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAE1C,OAAO,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC;AAC3C,CAAC;AAED,SAAgB,kBAAkB,CAChC,IAAU,EACV,OAAoE;IAEpE,IAAI,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,gCAAmB,CAAC,sBAAsB,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1C,MAAM,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;IAE1D,IAAI,CAAC,cAAc,EAAE,IAAI,IAAI,CAAC,cAAc,EAAE,OAAO,EAAE,CAAC;QACtD,MAAM,IAAI,gCAAmB,CAAC,gCAAgC,OAAO,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO,CAAC,cAAc,CAAC,OAAO,IAAI,cAAc,CAAC,IAAI,CAAW,CAAC;AACnE,CAAC","sourcesContent":["import { workspaces } from '@angular-devkit/core';\nimport { getWorkspace } from './config';\nimport { SchematicsException, Tree } from '@angular-devkit/schematics';\n\nexport interface WorkspaceProject {\n root: string;\n projectType: string;\n architect: {\n [key: string]: workspaces.TargetDefinition;\n };\n}\n\nexport function getProject(\n host: Tree,\n options: { project?: string | undefined; path?: string | undefined }\n): WorkspaceProject {\n const workspace = getWorkspace(host);\n\n if (!options.project) {\n const defaultProject = (workspace as { defaultProject?: string })\n .defaultProject;\n options.project =\n defaultProject !== undefined\n ? defaultProject\n : Object.keys(workspace.projects)[0];\n }\n\n return workspace.projects[options.project];\n}\n\nexport function getProjectPath(\n host: Tree,\n options: { project?: string | undefined; path?: string | undefined }\n) {\n const project = getProject(host, options);\n\n if (project.root.slice(-1) === '/') {\n project.root = project.root.substring(0, project.root.length - 1);\n }\n\n if (options.path === undefined) {\n const projectDirName =\n project.projectType === 'application' ? 'app' : 'lib';\n\n return `${project.root ? `/${project.root}` : ''}/src/${projectDirName}`;\n }\n\n return options.path;\n}\n\nexport function isLib(\n host: Tree,\n options: { project?: string | undefined; path?: string | undefined }\n) {\n const project = getProject(host, options);\n\n return project.projectType === 'library';\n}\n\nexport function getProjectMainFile(\n host: Tree,\n options: { project?: string | undefined; path?: string | undefined }\n) {\n if (isLib(host, options)) {\n throw new SchematicsException(`Invalid project type`);\n }\n const project = getProject(host, options);\n const projectOptions = project.architect['build'].options;\n\n if (!projectOptions?.main && !projectOptions?.browser) {\n throw new SchematicsException(`Could not find the main file ${project}`);\n }\n\n return (projectOptions.browser || projectOptions.main) as string;\n}\n"]}
|