@ngrx/signals 20.1.0 → 21.0.0-beta.0
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/fesm2022/ngrx-signals-entities.mjs.map +1 -1
- package/fesm2022/ngrx-signals-events.mjs +219 -57
- package/fesm2022/ngrx-signals-events.mjs.map +1 -1
- package/fesm2022/ngrx-signals-rxjs-interop.mjs +4 -4
- package/fesm2022/ngrx-signals-rxjs-interop.mjs.map +1 -1
- package/fesm2022/ngrx-signals.mjs +11 -8
- package/fesm2022/ngrx-signals.mjs.map +1 -1
- package/migrations/18_0_0-rc_3-protected-state/index.js +54 -23
- package/migrations/18_0_0-rc_3-protected-state/index.js.map +1 -1
- package/migrations/18_0_0-rc_3-writablestatesource/index.js +45 -12
- package/migrations/18_0_0-rc_3-writablestatesource/index.js.map +1 -1
- package/migrations/19_0_0-rc_0-props/index.js +72 -83
- package/migrations/19_0_0-rc_0-props/index.js.map +1 -1
- package/migrations/21_0_0-beta_0-rename-withEffects-to-withEventHandlers/index.js +103 -0
- package/migrations/21_0_0-beta_0-rename-withEffects-to-withEventHandlers/index.js.map +1 -0
- package/migrations/migration.json +5 -0
- package/package.json +8 -8
- package/schematics/ng-add/index.js +5 -5
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics-core/index.js +1 -1
- package/schematics-core/index.js.map +1 -1
- package/schematics-core/utility/ast-utils.js +198 -240
- package/schematics-core/utility/ast-utils.js.map +1 -1
- package/schematics-core/utility/change.js +68 -85
- package/schematics-core/utility/change.js.map +1 -1
- package/schematics-core/utility/config.js +7 -7
- package/schematics-core/utility/config.js.map +1 -1
- package/schematics-core/utility/find-component.js +20 -20
- package/schematics-core/utility/find-component.js.map +1 -1
- package/schematics-core/utility/find-module.js +21 -21
- package/schematics-core/utility/find-module.js.map +1 -1
- package/schematics-core/utility/json-utilts.js +4 -26
- package/schematics-core/utility/json-utilts.js.map +1 -1
- package/schematics-core/utility/libs-version.js +1 -1
- package/schematics-core/utility/libs-version.js.map +1 -1
- package/schematics-core/utility/ngrx-utils.js +110 -141
- package/schematics-core/utility/ngrx-utils.js.map +1 -1
- package/schematics-core/utility/package.js +2 -3
- package/schematics-core/utility/package.js.map +1 -1
- package/schematics-core/utility/parse-name.js +3 -3
- package/schematics-core/utility/parse-name.js.map +1 -1
- package/schematics-core/utility/project.js +13 -13
- package/schematics-core/utility/project.js.map +1 -1
- package/schematics-core/utility/strings.js +12 -12
- package/schematics-core/utility/strings.js.map +1 -1
- package/schematics-core/utility/update.js +12 -12
- package/schematics-core/utility/update.js.map +1 -1
- package/schematics-core/utility/visitors.js +78 -180
- package/schematics-core/utility/visitors.js.map +1 -1
- package/types/ngrx-signals-entities.d.ts +324 -0
- package/types/ngrx-signals-events.d.ts +360 -0
- package/types/ngrx-signals-rxjs-interop.d.ts +15 -0
- package/{testing/src/unprotected.d.ts → types/ngrx-signals-testing.d.ts} +5 -3
- package/types/ngrx-signals.d.ts +332 -0
- package/entities/index.d.ts +0 -1
- package/entities/src/entity-config.d.ts +0 -17
- package/entities/src/helpers.d.ts +0 -25
- package/entities/src/index.d.ts +0 -18
- package/entities/src/models.d.ts +0 -24
- package/entities/src/updaters/add-entities.d.ts +0 -17
- package/entities/src/updaters/add-entity.d.ts +0 -17
- package/entities/src/updaters/prepend-entities.d.ts +0 -17
- package/entities/src/updaters/prepend-entity.d.ts +0 -17
- package/entities/src/updaters/remove-all-entities.d.ts +0 -6
- package/entities/src/updaters/remove-entities.d.ts +0 -10
- package/entities/src/updaters/remove-entity.d.ts +0 -6
- package/entities/src/updaters/set-all-entities.d.ts +0 -17
- package/entities/src/updaters/set-entities.d.ts +0 -17
- package/entities/src/updaters/set-entity.d.ts +0 -17
- package/entities/src/updaters/update-all-entities.d.ts +0 -17
- package/entities/src/updaters/update-entities.d.ts +0 -56
- package/entities/src/updaters/update-entity.d.ts +0 -29
- package/entities/src/updaters/upsert-entities.d.ts +0 -17
- package/entities/src/updaters/upsert-entity.d.ts +0 -17
- package/entities/src/with-entities.d.ts +0 -22
- package/events/index.d.ts +0 -1
- package/events/src/case-reducer.d.ts +0 -20
- package/events/src/dispatcher.d.ts +0 -33
- package/events/src/event-creator-group.d.ts +0 -33
- package/events/src/event-creator.d.ts +0 -9
- package/events/src/event-instance.d.ts +0 -8
- package/events/src/events-service.d.ts +0 -47
- package/events/src/index.d.ts +0 -9
- package/events/src/inject-dispatch.d.ts +0 -46
- package/events/src/with-effects.d.ts +0 -28
- package/events/src/with-reducer.d.ts +0 -30
- package/index.d.ts +0 -1
- package/rxjs-interop/index.d.ts +0 -1
- package/rxjs-interop/src/index.d.ts +0 -1
- package/rxjs-interop/src/rx-method.d.ts +0 -12
- package/src/deep-computed.d.ts +0 -2
- package/src/deep-signal.d.ts +0 -6
- package/src/index.d.ts +0 -16
- package/src/signal-method.d.ts +0 -7
- package/src/signal-state.d.ts +0 -4
- package/src/signal-store-assertions.d.ts +0 -2
- package/src/signal-store-feature.d.ts +0 -29
- package/src/signal-store-models.d.ts +0 -30
- package/src/signal-store.d.ts +0 -115
- package/src/state-source.d.ts +0 -23
- package/src/ts-helpers.d.ts +0 -11
- package/src/with-computed.d.ts +0 -12
- package/src/with-feature.d.ts +0 -26
- package/src/with-hooks.d.ts +0 -14
- package/src/with-linked-state.d.ts +0 -52
- package/src/with-methods.d.ts +0 -8
- package/src/with-props.d.ts +0 -8
- package/src/with-state.d.ts +0 -11
- package/testing/index.d.ts +0 -1
- package/testing/src/index.d.ts +0 -1
|
@@ -1,40 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
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]; } };
|
|
35
7
|
}
|
|
36
|
-
|
|
37
|
-
}
|
|
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
|
+
})();
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
36
|
exports.addReducerToState = addReducerToState;
|
|
40
37
|
exports.addReducerToStateInterface = addReducerToStateInterface;
|
|
@@ -42,54 +39,43 @@ exports.addReducerToActionReducerMap = addReducerToActionReducerMap;
|
|
|
42
39
|
exports.addReducerImportToNgModule = addReducerImportToNgModule;
|
|
43
40
|
exports.omit = omit;
|
|
44
41
|
exports.getPrefix = getPrefix;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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");
|
|
52
49
|
function addReducerToState(options) {
|
|
53
|
-
return
|
|
54
|
-
var e_1, _a;
|
|
50
|
+
return (host) => {
|
|
55
51
|
if (!options.reducers) {
|
|
56
52
|
return host;
|
|
57
53
|
}
|
|
58
|
-
|
|
54
|
+
const reducersPath = (0, core_1.normalize)(`/${options.path}/${options.reducers}`);
|
|
59
55
|
if (!host.exists(reducersPath)) {
|
|
60
|
-
throw new Error(
|
|
56
|
+
throw new Error(`Specified reducers path ${reducersPath} does not exist`);
|
|
61
57
|
}
|
|
62
|
-
|
|
58
|
+
const text = host.read(reducersPath);
|
|
63
59
|
if (text === null) {
|
|
64
|
-
throw new schematics_1.SchematicsException(
|
|
60
|
+
throw new schematics_1.SchematicsException(`File ${reducersPath} does not exist.`);
|
|
65
61
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
const sourceText = text.toString('utf-8');
|
|
63
|
+
const source = ts.createSourceFile(reducersPath, sourceText, ts.ScriptTarget.Latest, true);
|
|
64
|
+
const reducerPath = `/${options.path}/` +
|
|
69
65
|
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
|
|
70
66
|
(options.group ? 'reducers/' : '') +
|
|
71
67
|
stringUtils.dasherize(options.name) +
|
|
72
68
|
'.reducer';
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (change instanceof change_1.InsertChange) {
|
|
83
|
-
recorder.insertLeft(change.pos, change.toAdd);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
88
|
-
finally {
|
|
89
|
-
try {
|
|
90
|
-
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);
|
|
91
78
|
}
|
|
92
|
-
finally { if (e_1) throw e_1.error; }
|
|
93
79
|
}
|
|
94
80
|
host.commitUpdate(recorder);
|
|
95
81
|
return host;
|
|
@@ -99,33 +85,33 @@ function addReducerToState(options) {
|
|
|
99
85
|
* Insert the reducer into the first defined top level interface
|
|
100
86
|
*/
|
|
101
87
|
function addReducerToStateInterface(source, reducersPath, options) {
|
|
102
|
-
|
|
103
|
-
|
|
88
|
+
const stateInterface = source.statements.find((stm) => stm.kind === ts.SyntaxKind.InterfaceDeclaration);
|
|
89
|
+
let node = stateInterface;
|
|
104
90
|
if (!node) {
|
|
105
91
|
return new change_1.NoopChange();
|
|
106
92
|
}
|
|
107
|
-
|
|
93
|
+
const state = options.plural
|
|
108
94
|
? stringUtils.pluralize(options.name)
|
|
109
95
|
: stringUtils.camelize(options.name);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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;
|
|
114
100
|
if (expr.members.length === 0) {
|
|
115
101
|
position = expr.getEnd() - 1;
|
|
116
|
-
toInsert =
|
|
102
|
+
toInsert = ` ${keyInsert}\n`;
|
|
117
103
|
}
|
|
118
104
|
else {
|
|
119
105
|
node = expr.members[expr.members.length - 1];
|
|
120
106
|
position = node.getEnd() + 1;
|
|
121
107
|
// Get the indentation of the last element, if any.
|
|
122
|
-
|
|
123
|
-
|
|
108
|
+
const text = node.getFullText(source);
|
|
109
|
+
const matches = text.match(/^\r?\n+(\s*)/);
|
|
124
110
|
if (matches && matches.length > 0) {
|
|
125
|
-
toInsert =
|
|
111
|
+
toInsert = `${matches[1]}${keyInsert}\n`;
|
|
126
112
|
}
|
|
127
113
|
else {
|
|
128
|
-
toInsert =
|
|
114
|
+
toInsert = `\n${keyInsert}`;
|
|
129
115
|
}
|
|
130
116
|
}
|
|
131
117
|
return new change_1.InsertChange(reducersPath, position, toInsert);
|
|
@@ -134,47 +120,44 @@ function addReducerToStateInterface(source, reducersPath, options) {
|
|
|
134
120
|
* Insert the reducer into the ActionReducerMap
|
|
135
121
|
*/
|
|
136
122
|
function addReducerToActionReducerMap(source, reducersPath, options) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
.filter(
|
|
140
|
-
.filter(
|
|
141
|
-
.map(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return { initializer: variable.initializer, type
|
|
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 };
|
|
146
132
|
})
|
|
147
|
-
.filter(
|
|
148
|
-
.find(
|
|
149
|
-
var type = _a.type;
|
|
150
|
-
return type.typeName.text === 'ActionReducerMap';
|
|
151
|
-
});
|
|
133
|
+
.filter((initWithType) => initWithType.type !== undefined)
|
|
134
|
+
.find(({ type }) => type.typeName.text === 'ActionReducerMap');
|
|
152
135
|
if (!actionReducerMap || !actionReducerMap.initializer) {
|
|
153
136
|
return new change_1.NoopChange();
|
|
154
137
|
}
|
|
155
|
-
|
|
156
|
-
|
|
138
|
+
let node = actionReducerMap.initializer;
|
|
139
|
+
const state = options.plural
|
|
157
140
|
? stringUtils.pluralize(options.name)
|
|
158
141
|
: stringUtils.camelize(options.name);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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;
|
|
163
146
|
if (expr.properties.length === 0) {
|
|
164
147
|
position = expr.getEnd() - 1;
|
|
165
|
-
toInsert =
|
|
148
|
+
toInsert = ` ${keyInsert}\n`;
|
|
166
149
|
}
|
|
167
150
|
else {
|
|
168
151
|
node = expr.properties[expr.properties.length - 1];
|
|
169
152
|
position = node.getEnd() + 1;
|
|
170
153
|
// Get the indentation of the last element, if any.
|
|
171
|
-
|
|
172
|
-
|
|
154
|
+
const text = node.getFullText(source);
|
|
155
|
+
const matches = text.match(/^\r?\n+(\s*)/);
|
|
173
156
|
if (matches && matches.length > 0) {
|
|
174
|
-
toInsert =
|
|
157
|
+
toInsert = `\n${matches[1]}${keyInsert}`;
|
|
175
158
|
}
|
|
176
159
|
else {
|
|
177
|
-
toInsert =
|
|
160
|
+
toInsert = `\n${keyInsert}`;
|
|
178
161
|
}
|
|
179
162
|
}
|
|
180
163
|
return new change_1.InsertChange(reducersPath, position, toInsert);
|
|
@@ -183,51 +166,40 @@ function addReducerToActionReducerMap(source, reducersPath, options) {
|
|
|
183
166
|
* Add reducer feature to NgModule
|
|
184
167
|
*/
|
|
185
168
|
function addReducerImportToNgModule(options) {
|
|
186
|
-
return
|
|
187
|
-
var e_2, _a;
|
|
169
|
+
return (host) => {
|
|
188
170
|
if (!options.module) {
|
|
189
171
|
return host;
|
|
190
172
|
}
|
|
191
|
-
|
|
173
|
+
const modulePath = options.module;
|
|
192
174
|
if (!host.exists(options.module)) {
|
|
193
|
-
throw new Error(
|
|
175
|
+
throw new Error(`Specified module path ${modulePath} does not exist`);
|
|
194
176
|
}
|
|
195
|
-
|
|
177
|
+
const text = host.read(modulePath);
|
|
196
178
|
if (text === null) {
|
|
197
|
-
throw new schematics_1.SchematicsException(
|
|
179
|
+
throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
|
|
198
180
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
181
|
+
const sourceText = text.toString('utf-8');
|
|
182
|
+
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
183
|
+
const commonImports = [
|
|
202
184
|
(0, ast_utils_1.insertImport)(source, modulePath, 'StoreModule', '@ngrx/store'),
|
|
203
185
|
];
|
|
204
|
-
|
|
186
|
+
const reducerPath = `/${options.path}/` +
|
|
205
187
|
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
|
|
206
188
|
(options.group ? 'reducers/' : '') +
|
|
207
189
|
stringUtils.dasherize(options.name) +
|
|
208
190
|
'.reducer';
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
|
212
194
|
? stringUtils.pluralize(options.name)
|
|
213
195
|
: stringUtils.camelize(options.name);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (change instanceof change_1.InsertChange) {
|
|
221
|
-
recorder.insertLeft(change.pos, change.toAdd);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
226
|
-
finally {
|
|
227
|
-
try {
|
|
228
|
-
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);
|
|
229
202
|
}
|
|
230
|
-
finally { if (e_2) throw e_2.error; }
|
|
231
203
|
}
|
|
232
204
|
host.commitUpdate(recorder);
|
|
233
205
|
return host;
|
|
@@ -235,11 +207,8 @@ function addReducerImportToNgModule(options) {
|
|
|
235
207
|
}
|
|
236
208
|
function omit(object, keyToRemove) {
|
|
237
209
|
return Object.keys(object)
|
|
238
|
-
.filter(
|
|
239
|
-
.reduce(
|
|
240
|
-
var _a;
|
|
241
|
-
return Object.assign(result, (_a = {}, _a[key] = object[key], _a));
|
|
242
|
-
}, {});
|
|
210
|
+
.filter((key) => key !== keyToRemove)
|
|
211
|
+
.reduce((result, key) => Object.assign(result, { [key]: object[key] }), {});
|
|
243
212
|
}
|
|
244
213
|
function getPrefix(options) {
|
|
245
214
|
return stringUtils.camelize(options.prefix || 'load');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngrx-utils.js","sourceRoot":"","sources":["../../../../../modules/signals/schematics-core/utility/ngrx-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,8CAgEC;AAKD,gEA6CC;AAKD,oEA8DC;AAKD,gEAkEC;AAED,oBAOC;AAED,8BAEC;AAjRD,+BAAiC;AACjC,uCAAyC;AACzC,mCAA4D;AAC5D,yDAA6E;AAC7E,6CAAiD;AACjD,6CAAkD;AAClD,yCAA8D;AAE9D,SAAgB,iBAAiB,CAAC,OAAY;IAC5C,OAAO,UAAC,IAAU;;QAChB,IAAI,CAAC,OAAO,C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AM,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,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
|
+
{"version":3,"file":"ngrx-utils.js","sourceRoot":"","sources":["../../../../../modules/signals/schematics-core/utility/ngrx-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,8CAgEC;AAKD,gEA6CC;AAKD,oEA8DC;AAKD,gEAkEC;AAED,oBAOC;AAED,8BAEC;AAjRD,+CAAiC;AACjC,uDAAyC;AACzC,qCAA4D;AAC5D,2DAA6E;AAC7E,+CAAiD;AACjD,+CAAkD;AAClD,2CAA8D;AAE9D,SAAgB,iBAAiB,CAAC,OAAY;IAC5C,OAAO,CAAC,IAAU,EAAE,EAAE;QACpB,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,YAAY,GAAG,IAAA,gBAAS,EAAC,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEvE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,2BAA2B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EACV,8BAA8B,WAAW,CAAC,QAAQ,CAChD,OAAO,CAAC,IAAI,CACb,IAAI,KAAK,mBAAmB,WAAW,CAAC,QAAQ,CAC/C,OAAO,CAAC,IAAI,CACb,WAAW,EACZ,YAAY,CACb,CAAC;QACF,MAAM,OAAO,GAAG,CAAC,GAAG,aAAa,EAAE,aAAa,EAAE,mBAAmB,CAAC,CAAC;QACvE,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAC9C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,MAAM,YAAY,qBAAY,EAAE,CAAC;gBACnC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAE5B,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB,IAAI,CAClB,MAAS,EACT,WAAoB;IAEpB,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SACvB,MAAM,CAAC,CAAC,GAAG,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"]}
|
|
@@ -5,10 +5,9 @@ exports.addPackageToPackageJson = addPackageToPackageJson;
|
|
|
5
5
|
* Adds a package to the package.json
|
|
6
6
|
*/
|
|
7
7
|
function addPackageToPackageJson(host, type, pkg, version) {
|
|
8
|
-
var _a, _b;
|
|
9
8
|
if (host.exists('package.json')) {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const sourceText = host.read('package.json')?.toString('utf-8') ?? '{}';
|
|
10
|
+
const json = JSON.parse(sourceText);
|
|
12
11
|
if (!json[type]) {
|
|
13
12
|
json[type] = {};
|
|
14
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.js","sourceRoot":"","sources":["../../../../../modules/signals/schematics-core/utility/package.ts"],"names":[],"mappings":";;AAKA,0DAqBC;AAxBD;;GAEG;AACH,SAAgB,uBAAuB,CACrC,IAAU,EACV,IAAY,EACZ,GAAW,EACX,OAAe
|
|
1
|
+
{"version":3,"file":"package.js","sourceRoot":"","sources":["../../../../../modules/signals/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,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseName = parseName;
|
|
4
|
-
|
|
4
|
+
const core_1 = require("@angular-devkit/core");
|
|
5
5
|
function parseName(path, name) {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const nameWithoutPath = (0, core_1.basename)(name);
|
|
7
|
+
const namePath = (0, core_1.dirname)((path + '/' + name));
|
|
8
8
|
return {
|
|
9
9
|
name: nameWithoutPath,
|
|
10
10
|
path: (0, core_1.normalize)('/' + namePath),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-name.js","sourceRoot":"","sources":["../../../../../modules/signals/schematics-core/utility/parse-name.ts"],"names":[],"mappings":";;AAOA,8BAQC;AAfD
|
|
1
|
+
{"version":3,"file":"parse-name.js","sourceRoot":"","sources":["../../../../../modules/signals/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"]}
|
|
@@ -4,12 +4,12 @@ exports.getProject = getProject;
|
|
|
4
4
|
exports.getProjectPath = getProjectPath;
|
|
5
5
|
exports.isLib = isLib;
|
|
6
6
|
exports.getProjectMainFile = getProjectMainFile;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const config_1 = require("./config");
|
|
8
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
9
9
|
function getProject(host, options) {
|
|
10
|
-
|
|
10
|
+
const workspace = (0, config_1.getWorkspace)(host);
|
|
11
11
|
if (!options.project) {
|
|
12
|
-
|
|
12
|
+
const defaultProject = workspace
|
|
13
13
|
.defaultProject;
|
|
14
14
|
options.project =
|
|
15
15
|
defaultProject !== undefined
|
|
@@ -19,28 +19,28 @@ function getProject(host, options) {
|
|
|
19
19
|
return workspace.projects[options.project];
|
|
20
20
|
}
|
|
21
21
|
function getProjectPath(host, options) {
|
|
22
|
-
|
|
22
|
+
const project = getProject(host, options);
|
|
23
23
|
if (project.root.slice(-1) === '/') {
|
|
24
24
|
project.root = project.root.substring(0, project.root.length - 1);
|
|
25
25
|
}
|
|
26
26
|
if (options.path === undefined) {
|
|
27
|
-
|
|
28
|
-
return
|
|
27
|
+
const projectDirName = project.projectType === 'application' ? 'app' : 'lib';
|
|
28
|
+
return `${project.root ? `/${project.root}` : ''}/src/${projectDirName}`;
|
|
29
29
|
}
|
|
30
30
|
return options.path;
|
|
31
31
|
}
|
|
32
32
|
function isLib(host, options) {
|
|
33
|
-
|
|
33
|
+
const project = getProject(host, options);
|
|
34
34
|
return project.projectType === 'library';
|
|
35
35
|
}
|
|
36
36
|
function getProjectMainFile(host, options) {
|
|
37
37
|
if (isLib(host, options)) {
|
|
38
|
-
throw new schematics_1.SchematicsException(
|
|
38
|
+
throw new schematics_1.SchematicsException(`Invalid project type`);
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!
|
|
43
|
-
throw new schematics_1.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}`);
|
|
44
44
|
}
|
|
45
45
|
return (projectOptions.browser || projectOptions.main);
|
|
46
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../../../../modules/signals/schematics-core/utility/project.ts"],"names":[],"mappings":";;AAYA,gCAgBC;AAED,wCAkBC;AAED,sBAOC;AAED,gDAeC;AAzED,
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../../../../modules/signals/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;Q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E,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"]}
|
|
@@ -16,11 +16,11 @@ exports.featurePath = featurePath;
|
|
|
16
16
|
* Use of this source code is governed by an MIT-style license that can be
|
|
17
17
|
* found in the LICENSE file at https://angular.io/license
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const STRING_DASHERIZE_REGEXP = /[ _]/g;
|
|
20
|
+
const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g;
|
|
21
|
+
const STRING_CAMELIZE_REGEXP = /(-|_|\.|\s)+(.)?/g;
|
|
22
|
+
const STRING_UNDERSCORE_REGEXP_1 = /([a-z\d])([A-Z]+)/g;
|
|
23
|
+
const STRING_UNDERSCORE_REGEXP_2 = /-|\s+/g;
|
|
24
24
|
/**
|
|
25
25
|
* Converts a camelized string into all lower case separated by underscores.
|
|
26
26
|
*
|
|
@@ -60,10 +60,10 @@ function dasherize(str) {
|
|
|
60
60
|
*/
|
|
61
61
|
function camelize(str) {
|
|
62
62
|
return str
|
|
63
|
-
.replace(STRING_CAMELIZE_REGEXP,
|
|
63
|
+
.replace(STRING_CAMELIZE_REGEXP, (_match, _separator, chr) => {
|
|
64
64
|
return chr ? chr.toUpperCase() : '';
|
|
65
65
|
})
|
|
66
|
-
.replace(/^([A-Z])/,
|
|
66
|
+
.replace(/^([A-Z])/, (match) => match.toLowerCase());
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
Returns the UpperCamelCase form of a string.
|
|
@@ -78,7 +78,7 @@ function camelize(str) {
|
|
|
78
78
|
function classify(str) {
|
|
79
79
|
return str
|
|
80
80
|
.split('.')
|
|
81
|
-
.map(
|
|
81
|
+
.map((part) => capitalize(camelize(part)))
|
|
82
82
|
.join('.');
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
@@ -123,15 +123,15 @@ function capitalize(str) {
|
|
|
123
123
|
```
|
|
124
124
|
*/
|
|
125
125
|
function pluralize(str) {
|
|
126
|
-
return camelize([/([^aeiou])y$/, /()fe?$/, /([^aeiou]o|[sxz]|[cs]h)$/].map(
|
|
126
|
+
return camelize([/([^aeiou])y$/, /()fe?$/, /([^aeiou]o|[sxz]|[cs]h)$/].map((c, i) => (str = str.replace(c, `$1${'iv'[i] || ''}e`))) && str + 's');
|
|
127
127
|
}
|
|
128
128
|
function group(name, group) {
|
|
129
|
-
return group ?
|
|
129
|
+
return group ? `${group}/${name}` : name;
|
|
130
130
|
}
|
|
131
131
|
function featurePath(group, flat, path, name) {
|
|
132
132
|
if (group && !flat) {
|
|
133
|
-
return
|
|
133
|
+
return `../../${path}/${name}/`;
|
|
134
134
|
}
|
|
135
|
-
return group ?
|
|
135
|
+
return group ? `../${path}/` : './';
|
|
136
136
|
}
|
|
137
137
|
//# sourceMappingURL=strings.js.map
|