@nstudio/xplat 15.0.2 → 15.0.4-rc.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/migrations/update-12-4-3/update-12-4-3.js +31 -33
- package/migrations/update-13-0-0/update-13-0-0.js +38 -40
- package/migrations.json +0 -66
- package/package.json +3 -3
- package/src/schematics/feature/index.spec.js +2 -2
- package/src/utils/ast.d.ts +4 -76
- package/src/utils/ast.js +19 -304
- package/src/utils/general.d.ts +35 -6
- package/src/utils/general.js +155 -11
- package/src/utils/versions.js +1 -1
- package/src/utils/xplat.js +16 -7
- package/migrations/update-10-2-0/update-10-2-0.d.ts +0 -2
- package/migrations/update-10-2-0/update-10-2-0.js +0 -11
- package/migrations/update-11-0-0/clean-old-dirs.d.ts +0 -2
- package/migrations/update-11-0-0/clean-old-dirs.js +0 -57
- package/migrations/update-11-0-0/update-11-0-0.d.ts +0 -5
- package/migrations/update-11-0-0/update-11-0-0.js +0 -594
- package/migrations/update-11-0-0/update-to-11-env-base.d.ts +0 -5
- package/migrations/update-11-0-0/update-to-11-env-base.js +0 -289
- package/migrations/update-11-0-0/update-to-11-imports.d.ts +0 -6
- package/migrations/update-11-0-0/update-to-11-imports.js +0 -173
package/src/utils/ast.js
CHANGED
@@ -1,255 +1,33 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.insert = exports.addGlobal = void 0;
|
4
|
+
const js_1 = require("@nrwl/js");
|
5
|
+
const typescript_1 = require("nx/src/utils/typescript");
|
4
6
|
const ts = require("typescript");
|
5
7
|
const general_1 = require("./general");
|
6
|
-
function
|
7
|
-
return first.getStart() - second.getStart();
|
8
|
-
}
|
9
|
-
function insertAfterLastOccurrence(nodes, toInsert, file, fallbackPos, syntaxKind) {
|
10
|
-
// sort() has a side effect, so make a copy so that we won't overwrite the parent's object.
|
11
|
-
let lastItem = [...nodes].sort(nodesByPosition).pop();
|
12
|
-
if (!lastItem) {
|
13
|
-
throw new Error();
|
14
|
-
}
|
15
|
-
if (syntaxKind) {
|
16
|
-
lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop();
|
17
|
-
}
|
18
|
-
if (!lastItem && fallbackPos == undefined) {
|
19
|
-
throw new Error(`tried to insert ${toInsert} as first occurence with no fallback position`);
|
20
|
-
}
|
21
|
-
const lastItemPosition = lastItem ? lastItem.getEnd() : fallbackPos;
|
22
|
-
return new InsertChange(file, lastItemPosition, toInsert);
|
23
|
-
}
|
24
|
-
function findNodes(node, kind, max = Infinity) {
|
25
|
-
if (!node || max == 0) {
|
26
|
-
return [];
|
27
|
-
}
|
28
|
-
const arr = [];
|
29
|
-
const hasMatch = Array.isArray(kind)
|
30
|
-
? kind.includes(node.kind)
|
31
|
-
: node.kind === kind;
|
32
|
-
if (hasMatch) {
|
33
|
-
arr.push(node);
|
34
|
-
max--;
|
35
|
-
}
|
36
|
-
if (max > 0) {
|
37
|
-
for (const child of node.getChildren()) {
|
38
|
-
findNodes(child, kind, max).forEach((node) => {
|
39
|
-
if (max > 0) {
|
40
|
-
arr.push(node);
|
41
|
-
}
|
42
|
-
max--;
|
43
|
-
});
|
44
|
-
if (max <= 0) {
|
45
|
-
break;
|
46
|
-
}
|
47
|
-
}
|
48
|
-
}
|
49
|
-
return arr;
|
50
|
-
}
|
51
|
-
exports.findNodes = findNodes;
|
52
|
-
function getSourceNodes(sourceFile) {
|
53
|
-
const nodes = [sourceFile];
|
54
|
-
const result = [];
|
55
|
-
while (nodes.length > 0) {
|
56
|
-
const node = nodes.shift();
|
57
|
-
if (node) {
|
58
|
-
result.push(node);
|
59
|
-
if (node.getChildCount(sourceFile) >= 0) {
|
60
|
-
nodes.unshift(...node.getChildren());
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|
64
|
-
return result;
|
65
|
-
}
|
66
|
-
exports.getSourceNodes = getSourceNodes;
|
67
|
-
class NoopChange {
|
68
|
-
constructor() {
|
69
|
-
this.type = 'noop';
|
70
|
-
this.description = 'No operation.';
|
71
|
-
this.order = Infinity;
|
72
|
-
this.path = null;
|
73
|
-
}
|
74
|
-
apply() {
|
75
|
-
return Promise.resolve();
|
76
|
-
}
|
77
|
-
}
|
78
|
-
exports.NoopChange = NoopChange;
|
79
|
-
class InsertChange {
|
80
|
-
constructor(path, pos, toAdd) {
|
81
|
-
this.path = path;
|
82
|
-
this.pos = pos;
|
83
|
-
this.toAdd = toAdd;
|
84
|
-
this.type = 'insert';
|
85
|
-
if (pos < 0) {
|
86
|
-
throw new Error('Negative positions are invalid');
|
87
|
-
}
|
88
|
-
this.description = `Inserted ${toAdd} into position ${pos} of ${path}`;
|
89
|
-
this.order = pos;
|
90
|
-
}
|
91
|
-
apply(host) {
|
92
|
-
return host.read(this.path).then((content) => {
|
93
|
-
const prefix = content.substring(0, this.pos);
|
94
|
-
const suffix = content.substring(this.pos);
|
95
|
-
return host.write(this.path, `${prefix}${this.toAdd}${suffix}`);
|
96
|
-
});
|
97
|
-
}
|
98
|
-
}
|
99
|
-
exports.InsertChange = InsertChange;
|
100
|
-
class RemoveChange {
|
101
|
-
constructor(path, pos, toRemove) {
|
102
|
-
this.path = path;
|
103
|
-
this.pos = pos;
|
104
|
-
this.toRemove = toRemove;
|
105
|
-
this.type = 'remove';
|
106
|
-
if (pos < 0) {
|
107
|
-
throw new Error('Negative positions are invalid');
|
108
|
-
}
|
109
|
-
this.description = `Removed ${toRemove} into position ${pos} of ${path}`;
|
110
|
-
this.order = pos;
|
111
|
-
}
|
112
|
-
apply(host) {
|
113
|
-
return host.read(this.path).then((content) => {
|
114
|
-
const prefix = content.substring(0, this.pos);
|
115
|
-
const suffix = content.substring(this.pos + this.toRemove.length);
|
116
|
-
return host.write(this.path, `${prefix}${suffix}`);
|
117
|
-
});
|
118
|
-
}
|
119
|
-
}
|
120
|
-
exports.RemoveChange = RemoveChange;
|
121
|
-
class ReplaceChange {
|
122
|
-
constructor(path, pos, oldText, newText) {
|
123
|
-
this.path = path;
|
124
|
-
this.pos = pos;
|
125
|
-
this.oldText = oldText;
|
126
|
-
this.newText = newText;
|
127
|
-
this.type = 'replace';
|
128
|
-
if (pos < 0) {
|
129
|
-
throw new Error('Negative positions are invalid');
|
130
|
-
}
|
131
|
-
this.description = `Replaced ${oldText} into position ${pos} of ${path} with ${newText}`;
|
132
|
-
this.order = pos;
|
133
|
-
}
|
134
|
-
apply(host) {
|
135
|
-
return host.read(this.path).then((content) => {
|
136
|
-
const prefix = content.substring(0, this.pos);
|
137
|
-
const suffix = content.substring(this.pos + this.oldText.length);
|
138
|
-
const text = content.substring(this.pos, this.pos + this.oldText.length);
|
139
|
-
if (text !== this.oldText) {
|
140
|
-
return Promise.reject(new Error(`Invalid replace: "${text}" != "${this.oldText}".`));
|
141
|
-
}
|
142
|
-
return host.write(this.path, `${prefix}${this.newText}${suffix}`);
|
143
|
-
});
|
144
|
-
}
|
145
|
-
}
|
146
|
-
exports.ReplaceChange = ReplaceChange;
|
147
|
-
function addParameterToConstructor(source, modulePath, opts) {
|
148
|
-
const clazz = findClass(source, opts.className);
|
149
|
-
const constructor = clazz.members.filter((m) => m.kind === ts.SyntaxKind.Constructor)[0];
|
150
|
-
if (constructor) {
|
151
|
-
throw new Error('Should be tested');
|
152
|
-
}
|
153
|
-
else {
|
154
|
-
const methodHeader = `constructor(${opts.param})`;
|
155
|
-
return addMethod(source, modulePath, {
|
156
|
-
className: opts.className,
|
157
|
-
methodHeader,
|
158
|
-
body: null,
|
159
|
-
});
|
160
|
-
}
|
161
|
-
}
|
162
|
-
exports.addParameterToConstructor = addParameterToConstructor;
|
163
|
-
function addMethod(source, modulePath, opts) {
|
164
|
-
const clazz = findClass(source, opts.className);
|
165
|
-
const body = opts.body
|
166
|
-
? `
|
167
|
-
${opts.methodHeader} {
|
168
|
-
${offset(opts.body, 1, false)}
|
169
|
-
}
|
170
|
-
`
|
171
|
-
: `
|
172
|
-
${opts.methodHeader} {}
|
173
|
-
`;
|
174
|
-
return [new InsertChange(modulePath, clazz.end - 1, offset(body, 1, true))];
|
175
|
-
}
|
176
|
-
exports.addMethod = addMethod;
|
177
|
-
function findClass(source, className, silent = false) {
|
178
|
-
const nodes = getSourceNodes(source);
|
179
|
-
const clazz = (nodes.filter((n) => n.kind === ts.SyntaxKind.ClassDeclaration &&
|
180
|
-
n.name.text === className)[0]);
|
181
|
-
if (!clazz && !silent) {
|
182
|
-
throw new Error(`Cannot find class '${className}'`);
|
183
|
-
}
|
184
|
-
return clazz;
|
185
|
-
}
|
186
|
-
exports.findClass = findClass;
|
187
|
-
function offset(text, numberOfTabs, wrap) {
|
188
|
-
const lines = text
|
189
|
-
.trim()
|
190
|
-
.split('\n')
|
191
|
-
.map((line) => {
|
192
|
-
let tabs = '';
|
193
|
-
for (let c = 0; c < numberOfTabs; ++c) {
|
194
|
-
tabs += ' ';
|
195
|
-
}
|
196
|
-
return `${tabs}${line}`;
|
197
|
-
})
|
198
|
-
.join('\n');
|
199
|
-
return wrap ? `\n${lines}\n` : lines;
|
200
|
-
}
|
201
|
-
exports.offset = offset;
|
202
|
-
function addIncludeToTsConfig(tsConfigPath, source, include) {
|
203
|
-
const includeKeywordPos = source.text.indexOf('"include":');
|
204
|
-
if (includeKeywordPos > -1) {
|
205
|
-
const includeArrayEndPos = source.text.indexOf(']', includeKeywordPos);
|
206
|
-
return [new InsertChange(tsConfigPath, includeArrayEndPos, include)];
|
207
|
-
}
|
208
|
-
else {
|
209
|
-
return [];
|
210
|
-
}
|
211
|
-
}
|
212
|
-
exports.addIncludeToTsConfig = addIncludeToTsConfig;
|
213
|
-
function getImport(source, predicate) {
|
214
|
-
const allImports = findNodes(source, ts.SyntaxKind.ImportDeclaration);
|
215
|
-
const matching = allImports.filter((i) => predicate(i.moduleSpecifier.getText()));
|
216
|
-
return matching.map((i) => {
|
217
|
-
const moduleSpec = i.moduleSpecifier
|
218
|
-
.getText()
|
219
|
-
.substring(1, i.moduleSpecifier.getText().length - 1);
|
220
|
-
const t = i.importClause.namedBindings.getText();
|
221
|
-
const bindings = t
|
222
|
-
.replace('{', '')
|
223
|
-
.replace('}', '')
|
224
|
-
.split(',')
|
225
|
-
.map((q) => q.trim());
|
226
|
-
return { moduleSpec, bindings };
|
227
|
-
});
|
228
|
-
}
|
229
|
-
exports.getImport = getImport;
|
230
|
-
function addGlobal(source, modulePath, statement, isExport) {
|
8
|
+
function addGlobal(tree, source, modulePath, statement, isExport) {
|
231
9
|
if (isExport) {
|
232
|
-
const allExports = findNodes(source, ts.SyntaxKind.ExportDeclaration);
|
10
|
+
const allExports = (0, typescript_1.findNodes)(source, ts.SyntaxKind.ExportDeclaration);
|
233
11
|
// console.log('allExports:', allExports.length);
|
234
12
|
if (allExports.length > 0) {
|
235
13
|
const lastExport = allExports[allExports.length - 1];
|
236
14
|
// console.log('lastExport.end:', lastExport.end);
|
237
|
-
return [
|
15
|
+
return [(0, js_1.insertChange)(tree, source, modulePath, lastExport.end, `\n${statement}\n`)];
|
238
16
|
}
|
239
17
|
else {
|
240
|
-
return [
|
18
|
+
return [(0, js_1.insertChange)(tree, source, modulePath, 0, `${statement}\n`)];
|
241
19
|
}
|
242
20
|
}
|
243
21
|
else {
|
244
|
-
const allImports = findNodes(source, ts.SyntaxKind.ImportDeclaration);
|
22
|
+
const allImports = (0, typescript_1.findNodes)(source, ts.SyntaxKind.ImportDeclaration);
|
245
23
|
if (allImports.length > 0) {
|
246
24
|
const lastImport = allImports[allImports.length - 1];
|
247
25
|
return [
|
248
|
-
|
26
|
+
(0, js_1.insertChange)(tree, source, modulePath, lastImport.end + 1, `\n${statement}\n`),
|
249
27
|
];
|
250
28
|
}
|
251
29
|
else {
|
252
|
-
return [
|
30
|
+
return [(0, js_1.insertChange)(tree, source, modulePath, 0, `${statement}\n`)];
|
253
31
|
}
|
254
32
|
}
|
255
33
|
}
|
@@ -262,17 +40,22 @@ function insert(host, modulePath, changes) {
|
|
262
40
|
const orderedChanges = changes.sort((a, b) => b.order - a.order);
|
263
41
|
const recorder = host.beginUpdate(modulePath);
|
264
42
|
for (const change of orderedChanges) {
|
265
|
-
|
43
|
+
// console.log('change.type:', change, ' -change.kind:', change.kind)
|
44
|
+
let type = change.type;
|
45
|
+
if (change.kind === 'c' || change.kind === 'o') {
|
46
|
+
type = general_1.actionToFileChangeMap[change.kind];
|
47
|
+
}
|
48
|
+
if (type == 'insert') {
|
266
49
|
recorder.insertLeft(change.pos, change.toAdd);
|
267
50
|
}
|
268
|
-
else if (
|
51
|
+
else if (type == 'remove') {
|
269
52
|
recorder.remove(change.pos - 1, change.toRemove.length + 1);
|
270
53
|
}
|
271
|
-
else if (
|
54
|
+
else if (type == 'replace') {
|
272
55
|
recorder.remove(change.pos, change.oldText.length);
|
273
56
|
recorder.insertLeft(change.pos, change.newText);
|
274
57
|
}
|
275
|
-
else if (
|
58
|
+
else if (type === 'noop') {
|
276
59
|
// do nothing
|
277
60
|
}
|
278
61
|
else {
|
@@ -282,71 +65,3 @@ function insert(host, modulePath, changes) {
|
|
282
65
|
host.commitUpdate(recorder);
|
283
66
|
}
|
284
67
|
exports.insert = insert;
|
285
|
-
function getProjectConfig(tree, name) {
|
286
|
-
const workspaceJson = (0, general_1.readWorkspaceJson)(tree);
|
287
|
-
const projectConfig = workspaceJson.projects[name];
|
288
|
-
if (!projectConfig) {
|
289
|
-
throw new Error(`Cannot find project '${name}'`);
|
290
|
-
}
|
291
|
-
else {
|
292
|
-
return projectConfig;
|
293
|
-
}
|
294
|
-
}
|
295
|
-
exports.getProjectConfig = getProjectConfig;
|
296
|
-
function insertImport(source, fileToEdit, symbolName, fileName, isDefault = false) {
|
297
|
-
const rootNode = source;
|
298
|
-
const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
|
299
|
-
// get nodes that map to import statements from the file fileName
|
300
|
-
const relevantImports = allImports.filter((node) => {
|
301
|
-
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
302
|
-
const importFiles = node
|
303
|
-
.getChildren()
|
304
|
-
.filter((child) => child.kind === ts.SyntaxKind.StringLiteral)
|
305
|
-
.map((n) => n.text);
|
306
|
-
return importFiles.filter((file) => file === fileName).length === 1;
|
307
|
-
});
|
308
|
-
if (relevantImports.length > 0) {
|
309
|
-
let importsAsterisk = false;
|
310
|
-
// imports from import file
|
311
|
-
const imports = [];
|
312
|
-
relevantImports.forEach((n) => {
|
313
|
-
Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
|
314
|
-
if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
|
315
|
-
importsAsterisk = true;
|
316
|
-
}
|
317
|
-
});
|
318
|
-
// if imports * from fileName, don't add symbolName
|
319
|
-
if (importsAsterisk) {
|
320
|
-
return new NoopChange();
|
321
|
-
}
|
322
|
-
const importTextNodes = imports.filter((n) => n.text === symbolName);
|
323
|
-
// insert import if it's not there
|
324
|
-
if (importTextNodes.length === 0) {
|
325
|
-
const fallbackPos = findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
326
|
-
findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
|
327
|
-
return insertAfterLastOccurrence(imports, `, ${symbolName}`, fileToEdit, fallbackPos);
|
328
|
-
}
|
329
|
-
return new NoopChange();
|
330
|
-
}
|
331
|
-
// no such import declaration exists
|
332
|
-
const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral).filter((n) => n.text === 'use strict');
|
333
|
-
let fallbackPos = 0;
|
334
|
-
if (useStrict.length > 0) {
|
335
|
-
fallbackPos = useStrict[0].end;
|
336
|
-
}
|
337
|
-
const open = isDefault ? '' : '{ ';
|
338
|
-
const close = isDefault ? '' : ' }';
|
339
|
-
// if there are no imports or 'use strict' statement, insert import at beginning of file
|
340
|
-
const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
|
341
|
-
const separator = insertAtBeginning ? '' : ';\n';
|
342
|
-
const toInsert = `${separator}import ${open}${symbolName}${close}` +
|
343
|
-
` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
|
344
|
-
return insertAfterLastOccurrence(allImports, toInsert, fileToEdit, fallbackPos, ts.SyntaxKind.StringLiteral);
|
345
|
-
}
|
346
|
-
exports.insertImport = insertImport;
|
347
|
-
function replaceNodeValue(host, modulePath, node, content) {
|
348
|
-
insert(host, modulePath, [
|
349
|
-
new ReplaceChange(modulePath, node.getStart(node.getSourceFile()), node.getFullText(), content),
|
350
|
-
]);
|
351
|
-
}
|
352
|
-
exports.replaceNodeValue = replaceNodeValue;
|
package/src/utils/general.d.ts
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
import { Tree as NgTree } from '@angular-devkit/schematics';
|
2
4
|
import { PlatformTypes, FrameworkTypes, ITargetPlatforms } from '@nstudio/xplat-utils';
|
5
|
+
import type { Mode } from 'fs';
|
6
|
+
import type { FileChange, Tree as DevKitTree, TreeWriteOptions } from 'nx/src/generators/tree';
|
3
7
|
export interface NodeDependency {
|
4
8
|
name: string;
|
5
9
|
version: string;
|
@@ -29,11 +33,10 @@ export declare function hasFrontendPlatform(targetPlatforms: ITargetPlatforms):
|
|
29
33
|
* @param targetPlatforms
|
30
34
|
*/
|
31
35
|
export declare function hasWebPlatform(targetPlatforms: ITargetPlatforms): boolean;
|
32
|
-
export declare function updatePackageForNgrx(tree:
|
33
|
-
export declare function updateTsConfig(tree:
|
34
|
-
export declare function updatePackageScripts(tree:
|
35
|
-
export declare function readWorkspaceJson(tree:
|
36
|
-
export declare function updateWorkspace(updates: any): any;
|
36
|
+
export declare function updatePackageForNgrx(tree: NgTree, packagePath?: string): import("@angular-devkit/schematics/src/tree/interface").Tree;
|
37
|
+
export declare function updateTsConfig(tree: NgTree, callback: (data: any) => void, targetSuffix?: string, prefixPath?: string): import("@angular-devkit/schematics/src/tree/interface").Tree;
|
38
|
+
export declare function updatePackageScripts(tree: NgTree, scripts: any): import("@angular-devkit/schematics/src/tree/interface").Tree;
|
39
|
+
export declare function readWorkspaceJson(tree: NgTree): any;
|
37
40
|
export declare function getPrefixWarning(prefix: string): string;
|
38
41
|
export declare function getDefaultTemplateOptions(): {
|
39
42
|
tmpl: string;
|
@@ -81,3 +84,29 @@ export declare const stringUtils: {
|
|
81
84
|
};
|
82
85
|
export declare const toComponentClassName: (name: string) => string;
|
83
86
|
export declare const toNgModuleClassName: (name: string) => string;
|
87
|
+
export declare const actionToFileChangeMap: {
|
88
|
+
c: string;
|
89
|
+
o: string;
|
90
|
+
d: string;
|
91
|
+
};
|
92
|
+
export declare function convertNgTreeToDevKit(tree: NgTree, context: any): DevkitTreeFromAngularDevkitTree;
|
93
|
+
export declare class DevkitTreeFromAngularDevkitTree implements DevKitTree {
|
94
|
+
tree: NgTree;
|
95
|
+
private _root;
|
96
|
+
private skipWritingConfigInOldFormat?;
|
97
|
+
private configFileName;
|
98
|
+
constructor(tree: NgTree, _root: any, skipWritingConfigInOldFormat?: boolean);
|
99
|
+
get root(): any;
|
100
|
+
children(dirPath: string): string[];
|
101
|
+
delete(filePath: string): void;
|
102
|
+
exists(filePath: string): boolean;
|
103
|
+
isFile(filePath: string): boolean;
|
104
|
+
listChanges(): FileChange[];
|
105
|
+
private normalize;
|
106
|
+
read(filePath: string): Buffer;
|
107
|
+
read(filePath: string, encoding: BufferEncoding): string;
|
108
|
+
rename(from: string, to: string): void;
|
109
|
+
write(filePath: string, content: Buffer | string, options?: TreeWriteOptions): void;
|
110
|
+
changePermissions(filePath: string, mode: Mode): void;
|
111
|
+
private warnUnsupportedFilePermissionsChange;
|
112
|
+
}
|
package/src/utils/general.js
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.toNgModuleClassName = exports.toComponentClassName = exports.stringUtils = exports.sanitize = exports.getDefaultTemplateOptions = exports.getPrefixWarning = exports.
|
12
|
+
exports.DevkitTreeFromAngularDevkitTree = exports.convertNgTreeToDevKit = exports.actionToFileChangeMap = exports.toNgModuleClassName = exports.toComponentClassName = exports.stringUtils = exports.sanitize = exports.getDefaultTemplateOptions = exports.getPrefixWarning = exports.readWorkspaceJson = exports.updatePackageScripts = exports.updateTsConfig = exports.updatePackageForNgrx = exports.hasWebPlatform = exports.hasFrontendPlatform = exports.supportedSandboxPlatforms = exports.supportedHelpers = void 0;
|
4
13
|
const workspace_1 = require("@nrwl/workspace");
|
5
14
|
const xplat_utils_1 = require("@nstudio/xplat-utils");
|
15
|
+
const path_1 = require("path");
|
6
16
|
// list of all supported helpers
|
7
17
|
// TODO: add more convenient helpers (like firebase or Travis ci support files)
|
8
18
|
exports.supportedHelpers = ['imports', 'applitools'];
|
@@ -83,18 +93,9 @@ function updatePackageScripts(tree, scripts) {
|
|
83
93
|
}
|
84
94
|
exports.updatePackageScripts = updatePackageScripts;
|
85
95
|
function readWorkspaceJson(tree) {
|
86
|
-
return (0,
|
96
|
+
return (0, xplat_utils_1.getJsonFromFile)(tree, 'workspace.json');
|
87
97
|
}
|
88
98
|
exports.readWorkspaceJson = readWorkspaceJson;
|
89
|
-
function updateWorkspace(updates) {
|
90
|
-
return (0, workspace_1.updateWorkspaceInTree)((json) => {
|
91
|
-
for (const key in updates) {
|
92
|
-
json[key] = Object.assign(Object.assign({}, (json[key] || {})), updates[key]);
|
93
|
-
}
|
94
|
-
return json;
|
95
|
-
});
|
96
|
-
}
|
97
|
-
exports.updateWorkspace = updateWorkspace;
|
98
99
|
// export function persistPrefix(prefix: string) {
|
99
100
|
// return (tree: Tree) => {
|
100
101
|
// const nxConfig = getNxWorkspaceConfig(tree);
|
@@ -142,3 +143,146 @@ const toComponentClassName = (name) => `${exports.stringUtils.classify(name)}Com
|
|
142
143
|
exports.toComponentClassName = toComponentClassName;
|
143
144
|
const toNgModuleClassName = (name) => `${exports.stringUtils.classify(name)}Module`;
|
144
145
|
exports.toNgModuleClassName = toNgModuleClassName;
|
146
|
+
exports.actionToFileChangeMap = {
|
147
|
+
c: 'CREATE',
|
148
|
+
o: 'UPDATE',
|
149
|
+
d: 'DELETE',
|
150
|
+
};
|
151
|
+
class RunCallbackTask {
|
152
|
+
constructor(callback) {
|
153
|
+
this.callback = callback;
|
154
|
+
}
|
155
|
+
toConfiguration() {
|
156
|
+
return {
|
157
|
+
name: 'RunCallback',
|
158
|
+
options: {
|
159
|
+
callback: this.callback,
|
160
|
+
},
|
161
|
+
};
|
162
|
+
}
|
163
|
+
}
|
164
|
+
function createRunCallbackTask() {
|
165
|
+
return {
|
166
|
+
name: 'RunCallback',
|
167
|
+
create: () => {
|
168
|
+
return Promise.resolve(({ callback }) => __awaiter(this, void 0, void 0, function* () {
|
169
|
+
yield callback();
|
170
|
+
}));
|
171
|
+
},
|
172
|
+
};
|
173
|
+
}
|
174
|
+
function convertNgTreeToDevKit(tree, context) {
|
175
|
+
if (context.engine.workflow) {
|
176
|
+
const engineHost = context.engine.workflow.engineHost;
|
177
|
+
engineHost.registerTaskExecutor(createRunCallbackTask());
|
178
|
+
}
|
179
|
+
const root = context.engine.workflow && context.engine.workflow.engineHost.paths
|
180
|
+
? context.engine.workflow.engineHost.paths[1]
|
181
|
+
: tree.root.path;
|
182
|
+
return new DevkitTreeFromAngularDevkitTree(tree, root, true);
|
183
|
+
}
|
184
|
+
exports.convertNgTreeToDevKit = convertNgTreeToDevKit;
|
185
|
+
class DevkitTreeFromAngularDevkitTree {
|
186
|
+
constructor(tree, _root, skipWritingConfigInOldFormat) {
|
187
|
+
this.tree = tree;
|
188
|
+
this._root = _root;
|
189
|
+
this.skipWritingConfigInOldFormat = skipWritingConfigInOldFormat;
|
190
|
+
/**
|
191
|
+
* When using the UnitTestTree from @angular-devkit/schematics/testing, the root is just `/`.
|
192
|
+
* This causes a massive issue if `getProjects()` is used in the underlying generator because it
|
193
|
+
* causes fast-glob to be set to work on the user's entire file system.
|
194
|
+
*
|
195
|
+
* Therefore, in this case, patch the root to match what Nx Devkit does and use /virtual instead.
|
196
|
+
*/
|
197
|
+
try {
|
198
|
+
const { UnitTestTree } = require('@angular-devkit/schematics/testing');
|
199
|
+
if (tree instanceof UnitTestTree && _root === '/') {
|
200
|
+
this._root = '/virtual';
|
201
|
+
}
|
202
|
+
}
|
203
|
+
catch (_a) { }
|
204
|
+
}
|
205
|
+
get root() {
|
206
|
+
return this._root;
|
207
|
+
}
|
208
|
+
children(dirPath) {
|
209
|
+
const { subdirs, subfiles } = this.tree.getDir(dirPath);
|
210
|
+
return [...subdirs, ...subfiles];
|
211
|
+
}
|
212
|
+
delete(filePath) {
|
213
|
+
this.tree.delete(filePath);
|
214
|
+
}
|
215
|
+
exists(filePath) {
|
216
|
+
if (this.isFile(filePath)) {
|
217
|
+
return this.tree.exists(filePath);
|
218
|
+
}
|
219
|
+
else {
|
220
|
+
return this.children(filePath).length > 0;
|
221
|
+
}
|
222
|
+
}
|
223
|
+
isFile(filePath) {
|
224
|
+
return this.tree.exists(filePath) && !!this.tree.read(filePath);
|
225
|
+
}
|
226
|
+
listChanges() {
|
227
|
+
const fileChanges = [];
|
228
|
+
for (const action of this.tree.actions) {
|
229
|
+
if (action.kind === 'r') {
|
230
|
+
fileChanges.push({
|
231
|
+
path: this.normalize(action.to),
|
232
|
+
type: 'CREATE',
|
233
|
+
content: this.read(action.to),
|
234
|
+
});
|
235
|
+
fileChanges.push({
|
236
|
+
path: this.normalize(action.path),
|
237
|
+
type: 'DELETE',
|
238
|
+
content: null,
|
239
|
+
});
|
240
|
+
}
|
241
|
+
else if (action.kind === 'c' || action.kind === 'o') {
|
242
|
+
fileChanges.push({
|
243
|
+
path: this.normalize(action.path),
|
244
|
+
type: exports.actionToFileChangeMap[action.kind],
|
245
|
+
content: action.content,
|
246
|
+
});
|
247
|
+
}
|
248
|
+
else {
|
249
|
+
fileChanges.push({
|
250
|
+
path: this.normalize(action.path),
|
251
|
+
type: 'DELETE',
|
252
|
+
content: null,
|
253
|
+
});
|
254
|
+
}
|
255
|
+
}
|
256
|
+
return fileChanges;
|
257
|
+
}
|
258
|
+
normalize(path) {
|
259
|
+
return (0, path_1.relative)(this.root, (0, path_1.join)(this.root, path));
|
260
|
+
}
|
261
|
+
read(filePath, encoding) {
|
262
|
+
return encoding
|
263
|
+
? this.tree.read(filePath).toString(encoding)
|
264
|
+
: this.tree.read(filePath);
|
265
|
+
}
|
266
|
+
rename(from, to) {
|
267
|
+
this.tree.rename(from, to);
|
268
|
+
}
|
269
|
+
write(filePath, content, options) {
|
270
|
+
if (options === null || options === void 0 ? void 0 : options.mode) {
|
271
|
+
this.warnUnsupportedFilePermissionsChange(filePath, options.mode);
|
272
|
+
}
|
273
|
+
if (this.tree.exists(filePath)) {
|
274
|
+
this.tree.overwrite(filePath, content);
|
275
|
+
}
|
276
|
+
else {
|
277
|
+
this.tree.create(filePath, content);
|
278
|
+
}
|
279
|
+
}
|
280
|
+
changePermissions(filePath, mode) {
|
281
|
+
this.warnUnsupportedFilePermissionsChange(filePath, mode);
|
282
|
+
}
|
283
|
+
warnUnsupportedFilePermissionsChange(filePath, mode) {
|
284
|
+
console.log(`The Angular DevKit tree does not support changing a file permissions.
|
285
|
+
Ignoring changing ${filePath} permissions to ${mode}.`);
|
286
|
+
}
|
287
|
+
}
|
288
|
+
exports.DevkitTreeFromAngularDevkitTree = DevkitTreeFromAngularDevkitTree;
|
package/src/utils/versions.js
CHANGED
package/src/utils/xplat.js
CHANGED
@@ -5,7 +5,6 @@ const schematics_1 = require("@angular-devkit/schematics");
|
|
5
5
|
const typescript_1 = require("typescript");
|
6
6
|
const general_1 = require("./general");
|
7
7
|
const xplat_utils_1 = require("@nstudio/xplat-utils");
|
8
|
-
const workspace_1 = require("@nrwl/workspace");
|
9
8
|
const ast_1 = require("./ast");
|
10
9
|
const errors_1 = require("./errors");
|
11
10
|
const tasks_1 = require("@angular-devkit/schematics/tasks");
|
@@ -43,7 +42,7 @@ var XplatHelpers;
|
|
43
42
|
*/
|
44
43
|
function addPackageWithNgAdd(packageName, options, callSchematicIfAdded) {
|
45
44
|
return (host) => {
|
46
|
-
const { dependencies, devDependencies } = (0,
|
45
|
+
const { dependencies, devDependencies } = (0, xplat_utils_1.getJsonFromFile)(host, 'package.json');
|
47
46
|
return dependencies[packageName] || devDependencies[packageName]
|
48
47
|
? callSchematicIfAdded
|
49
48
|
? (0, schematics_1.externalSchematic)(packageName, callSchematicIfAdded, options, {
|
@@ -769,15 +768,25 @@ var XplatFeatureHelpers;
|
|
769
768
|
}
|
770
769
|
XplatFeatureHelpers.addFiles = addFiles;
|
771
770
|
function adjustBarrelIndex(options, indexFilePath) {
|
772
|
-
return (tree) => {
|
771
|
+
return (tree, context) => {
|
772
|
+
const devKitTree = (0, general_1.convertNgTreeToDevKit)(tree, context);
|
773
773
|
// console.log('adjustBarrelIndex indexFilePath:', indexFilePath);
|
774
774
|
// console.log('tree.exists(indexFilePath):', tree.exists(indexFilePath));
|
775
775
|
const indexSource = tree.read(indexFilePath).toString('utf-8');
|
776
776
|
const indexSourceFile = (0, typescript_1.createSourceFile)(indexFilePath, indexSource, typescript_1.ScriptTarget.Latest, true);
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
777
|
+
// insert(tree, indexFilePath, [
|
778
|
+
// ...addGlobal(
|
779
|
+
// devKitTree,
|
780
|
+
// indexSourceFile,
|
781
|
+
// indexFilePath,
|
782
|
+
// `export * from './${
|
783
|
+
// options.directory ? options.directory + '/' : ''
|
784
|
+
// }${options.name.toLowerCase()}';`,
|
785
|
+
// true
|
786
|
+
// ),
|
787
|
+
// ]);
|
788
|
+
(0, ast_1.addGlobal)(devKitTree, indexSourceFile, indexFilePath, `export * from './${options.directory ? options.directory + '/' : ''}${options.name.toLowerCase()}';`, true);
|
789
|
+
return devKitTree.tree;
|
781
790
|
};
|
782
791
|
}
|
783
792
|
XplatFeatureHelpers.adjustBarrelIndex = adjustBarrelIndex;
|
@@ -1,11 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
4
|
-
function default_1() {
|
5
|
-
return (0, schematics_1.chain)([
|
6
|
-
(tree, context) => {
|
7
|
-
return (0, schematics_1.noop)();
|
8
|
-
},
|
9
|
-
]);
|
10
|
-
}
|
11
|
-
exports.default = default_1;
|