@nstudio/xplat 15.0.4-rc.1 → 16.5.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/README.md CHANGED
@@ -24,13 +24,19 @@
24
24
 
25
25
  ```
26
26
  npx create-nx-workspace@latest
27
- ```
28
27
 
29
- At the prompts:
28
+ // Choose "Integrated monorepo" at the prompt:
30
29
 
31
- > What to create in the new workspace
30
+ ? Choose what to create
31
+ > Integrated monorepo: Nx configures your favorite frameworks and lets you focus on shipping features.
32
32
 
33
- > choose `apps`
33
+ // Choose "apps" at the prompt:
34
+
35
+ ? What to create in the new workspace …
36
+ > apps [an empty monorepo with no plugins with a layout that works best for building apps]
37
+ ```
38
+
39
+ Install the tools:
34
40
 
35
41
  ```
36
42
  npm i @nstudio/xplat -D
@@ -39,15 +45,13 @@ npm i @nstudio/xplat -D
39
45
  You are now ready to create apps:
40
46
 
41
47
  ```
42
- nx g app
48
+ npx nx g @nstudio/xplat:app
43
49
  ```
44
50
 
45
- **NOTE:** If you encounter any issue, you can try creating an Nx workspace with a version specified.
46
-
47
- We have tested with the following, for example:
51
+ **NOTE:** If you encounter any issue, you can try creating an Nx workspace with version specified, for example:
48
52
 
49
53
  ```
50
- npx create-nx-workspace@15.9.2
54
+ npx create-nx-workspace@14.1.7
51
55
  ```
52
56
 
53
57
  ## App generation examples
@@ -61,7 +65,7 @@ Electron app generator can use any web app in the workspace as it's target.
61
65
  If you don't have a web app yet, create one first:
62
66
 
63
67
  ```
64
- nx g app sample
68
+ npx nx g @nstudio/xplat:app sample
65
69
  ```
66
70
 
67
71
  > choose `web`
@@ -69,7 +73,7 @@ nx g app sample
69
73
  You can now use the web app as the Electron target:
70
74
 
71
75
  ```
72
- nx g app desktop --target=web-sample
76
+ npx nx g @nstudio/xplat:app desktop --target=web-sample
73
77
  ```
74
78
 
75
79
  > choose `electron`
@@ -83,7 +87,7 @@ npm run start.electron.desktop
83
87
  ### Ionic
84
88
 
85
89
  ```
86
- nx g app sample
90
+ npx nx g @nstudio/xplat:app sample
87
91
  ```
88
92
 
89
93
  > choose `ionic`
@@ -91,13 +95,13 @@ nx g app sample
91
95
  Develop in browser with:
92
96
 
93
97
  ```
94
- nx serve ionic-sample
98
+ npx nx serve ionic-sample
95
99
  ```
96
100
 
97
101
  Build Ionic app:
98
102
 
99
103
  ```
100
- nx build ionic-sample
104
+ npx nx build ionic-sample
101
105
  ```
102
106
 
103
107
  A. **Capacitor iOS** - Prepare for development
@@ -127,7 +131,7 @@ npm run open.ionic.sample.android
127
131
  ### NativeScript
128
132
 
129
133
  ```
130
- nx g app mobile
134
+ nx g @nstudio/xplat:app mobile
131
135
  ```
132
136
 
133
137
  > choose `nativescript`
@@ -135,13 +139,13 @@ nx g app mobile
135
139
  A. **iOS**
136
140
 
137
141
  ```
138
- nx run nativescript-mobile:ios
142
+ npx nx run nativescript-mobile:ios
139
143
  ```
140
144
 
141
145
  B. **Android**
142
146
 
143
147
  ```
144
- nx run nativescript-mobile:android
148
+ npx nx run nativescript-mobile:android
145
149
  ```
146
150
 
147
151
  ## Documentation
package/collection.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nstudio/xplat",
3
3
  "version": "0.1",
4
- "extends": ["@nrwl/workspace"],
4
+ "extends": ["@nx/workspace"],
5
5
  "schematics": {
6
6
  "ng-add": {
7
7
  "factory": "./src/schematics/ng-add",
@@ -262,7 +262,7 @@ function updateRootPackage(tree, context) {
262
262
  json.dependencies = json.dependencies || {};
263
263
  json.dependencies = Object.assign(Object.assign(Object.assign({}, json.dependencies), (hasNativeScriptApps ? nativeScriptDeps : {})), { '@ngx-translate/core': ngxTranslateVersion });
264
264
  let ngToolsDeps = {
265
- '@ngtools/webpack': angularVersion,
265
+ '@ngtools/webpack': angularVersion
266
266
  };
267
267
  if (json.dependencies['@angular/core']) {
268
268
  // make sure in sync with current angular versions
@@ -289,7 +289,7 @@ function default_1() {
289
289
  updateRootPackage,
290
290
  (tree) => {
291
291
  return (0, schematics_1.externalSchematic)('@nrwl/workspace', 'convert-to-nx-project', {
292
- all: true,
292
+ all: true
293
293
  });
294
294
  },
295
295
  ]);
package/migrations.json CHANGED
@@ -12,47 +12,6 @@
12
12
  }
13
13
  },
14
14
  "packageJsonUpdates": {
15
- "11.0.21": {
16
- "version": "11.0.21",
17
- "packages": {
18
- "@nstudio/angular": {
19
- "version": "11.0.21",
20
- "alwaysAddToPackageJson": false
21
- },
22
- "@nstudio/electron": {
23
- "version": "11.0.21",
24
- "alwaysAddToPackageJson": false
25
- },
26
- "@nstudio/electron-angular": {
27
- "version": "11.0.21",
28
- "alwaysAddToPackageJson": false
29
- },
30
- "@nstudio/ionic": {
31
- "version": "11.0.21",
32
- "alwaysAddToPackageJson": false
33
- },
34
- "@nstudio/ionic-angular": {
35
- "version": "11.0.21",
36
- "alwaysAddToPackageJson": false
37
- },
38
- "@nstudio/nativescript": {
39
- "version": "11.0.21",
40
- "alwaysAddToPackageJson": false
41
- },
42
- "@nstudio/nativescript-angular": {
43
- "version": "11.0.21",
44
- "alwaysAddToPackageJson": false
45
- },
46
- "@nstudio/web": {
47
- "version": "11.0.21",
48
- "alwaysAddToPackageJson": false
49
- },
50
- "@nstudio/web-angular": {
51
- "version": "11.0.21",
52
- "alwaysAddToPackageJson": false
53
- }
54
- }
55
- },
56
15
  "12.4.3": {
57
16
  "version": "12.4.3",
58
17
  "packages": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nstudio/xplat",
3
- "version": "15.0.4-rc.1",
3
+ "version": "16.5.0",
4
4
  "description": "Cross-platform (xplat) tools for Nx workspaces.",
5
5
  "homepage": "https://nstudio.io/xplat",
6
6
  "repository": {
@@ -41,8 +41,10 @@
41
41
  "postinstall": "node src/utils/postinstall.js"
42
42
  },
43
43
  "dependencies": {
44
- "@nstudio/focus": "15.0.4-rc.1",
45
- "@nstudio/xplat-utils": "15.0.4-rc.1"
44
+ "@nx/devkit": "^16.0.0",
45
+ "@nx/js": "^16.0.0",
46
+ "@nstudio/focus": "16.5.0",
47
+ "@nstudio/xplat-utils": "16.5.0"
46
48
  },
47
49
  "author": "Nathan Walker",
48
50
  "license": "MIT",
@@ -13,7 +13,7 @@ const schematics_1 = require("@angular-devkit/schematics");
13
13
  const xplat_utils_1 = require("@nstudio/xplat-utils");
14
14
  const testing_1 = require("@nstudio/xplat/testing");
15
15
  const testing_2 = require("../../utils/testing");
16
- const testing_3 = require("@nrwl/workspace/testing");
16
+ const testing_3 = require("@nx/workspace/testing");
17
17
  (0, xplat_utils_1.setTest)();
18
18
  describe('xplat schematic', () => {
19
19
  let appTree;
@@ -14,7 +14,7 @@ const xplat_utils_1 = require("@nstudio/xplat-utils");
14
14
  const testing_1 = require("@nstudio/xplat/testing");
15
15
  const testing_2 = require("../../utils/testing");
16
16
  const utils_1 = require("../../utils");
17
- const testing_3 = require("@nrwl/workspace/testing");
17
+ const testing_3 = require("@nx/workspace/testing");
18
18
  (0, xplat_utils_1.setTest)();
19
19
  describe('xplat init', () => {
20
20
  let appTree;
@@ -36,7 +36,7 @@ describe('xplat init', () => {
36
36
  let packageJson = JSON.parse((0, testing_3.getFileContent)(tree, 'package.json'));
37
37
  // console.log(packageJson);
38
38
  const devDeps = [
39
- '@nrwl/angular',
39
+ '@nx/angular',
40
40
  '@nstudio/angular',
41
41
  '@nstudio/web-angular',
42
42
  '@nstudio/web',
@@ -1,77 +1,5 @@
1
- /**
2
- * @license
3
- * Copyright Google Inc. All Rights Reserved.
4
- *
5
- * Use of this source code is governed by an MIT- style license that can be
6
- * found in the LICENSE file at https://angular.io/license
7
- */
8
- import { Tree } from '@angular-devkit/schematics';
9
1
  import * as ts from 'typescript';
10
- export declare function findNodes(node: ts.Node, kind: ts.SyntaxKind | ts.SyntaxKind[], max?: number): ts.Node[];
11
- export declare function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[];
12
- export interface Change {
13
- apply(host: any): Promise<void>;
14
- readonly type: string;
15
- readonly path: string | null;
16
- readonly order: number;
17
- readonly description: string;
18
- }
19
- export declare class NoopChange implements Change {
20
- type: string;
21
- description: string;
22
- order: number;
23
- path: any;
24
- apply(): Promise<void>;
25
- }
26
- export declare class InsertChange implements Change {
27
- path: string;
28
- pos: number;
29
- toAdd: string;
30
- type: string;
31
- order: number;
32
- description: string;
33
- constructor(path: string, pos: number, toAdd: string);
34
- apply(host: any): any;
35
- }
36
- export declare class RemoveChange implements Change {
37
- path: string;
38
- private pos;
39
- private toRemove;
40
- type: string;
41
- order: number;
42
- description: string;
43
- constructor(path: string, pos: number, toRemove: string);
44
- apply(host: any): Promise<void>;
45
- }
46
- export declare class ReplaceChange implements Change {
47
- path: string;
48
- pos: number;
49
- oldText: string;
50
- newText: string;
51
- type: string;
52
- order: number;
53
- description: string;
54
- constructor(path: string, pos: number, oldText: string, newText: string);
55
- apply(host: any): Promise<void>;
56
- }
57
- export declare function addParameterToConstructor(source: ts.SourceFile, modulePath: string, opts: {
58
- className: string;
59
- param: string;
60
- }): Change[];
61
- export declare function addMethod(source: ts.SourceFile, modulePath: string, opts: {
62
- className: string;
63
- methodHeader: string;
64
- body: string;
65
- }): Change[];
66
- export declare function findClass(source: ts.SourceFile, className: string, silent?: boolean): ts.ClassDeclaration;
67
- export declare function offset(text: string, numberOfTabs: number, wrap: boolean): string;
68
- export declare function addIncludeToTsConfig(tsConfigPath: string, source: ts.SourceFile, include: string): Change[];
69
- export declare function getImport(source: ts.SourceFile, predicate: (a: any) => boolean): {
70
- moduleSpec: string;
71
- bindings: string[];
72
- }[];
73
- export declare function addGlobal(source: ts.SourceFile, modulePath: string, statement: string, isExport?: boolean): Change[];
74
- export declare function insert(host: Tree, modulePath: string, changes: Change[]): void;
75
- export declare function getProjectConfig(tree: Tree, name: string): any;
76
- export declare function insertImport(source: ts.SourceFile, fileToEdit: string, symbolName: string, fileName: string, isDefault?: boolean): Change;
77
- export declare function replaceNodeValue(host: Tree, modulePath: string, node: ts.Node, content: string): void;
2
+ import { Tree } from '@nx/devkit';
3
+ import { Tree as NgTree } from '@angular-devkit/schematics';
4
+ export declare function addGlobal(tree: Tree, source: ts.SourceFile, modulePath: string, statement: string, isExport?: boolean): ts.SourceFile;
5
+ export declare function insert(host: NgTree, modulePath: string, changes: any[]): void;
package/src/utils/ast.js CHANGED
@@ -1,255 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.replaceNodeValue = exports.insertImport = exports.getProjectConfig = exports.insert = exports.addGlobal = exports.getImport = exports.addIncludeToTsConfig = exports.offset = exports.findClass = exports.addMethod = exports.addParameterToConstructor = exports.ReplaceChange = exports.RemoveChange = exports.InsertChange = exports.NoopChange = exports.getSourceNodes = exports.findNodes = void 0;
3
+ exports.insert = exports.addGlobal = void 0;
4
+ const js_1 = require("@nx/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 nodesByPosition(first, second) {
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 [new InsertChange(modulePath, lastExport.end, `\n${statement}\n`)];
15
+ return (0, js_1.insertChange)(tree, source, modulePath, lastExport.end, `\n${statement}\n`);
238
16
  }
239
17
  else {
240
- return [new InsertChange(modulePath, 0, `${statement}\n`)];
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
- return [
248
- new InsertChange(modulePath, lastImport.end + 1, `\n${statement}\n`),
249
- ];
25
+ return (0, js_1.insertChange)(tree, source, modulePath, lastImport.end + 1, `\n${statement}\n`);
250
26
  }
251
27
  else {
252
- return [new InsertChange(modulePath, 0, `${statement}\n`)];
28
+ return (0, js_1.insertChange)(tree, source, modulePath, 0, `${statement}\n`);
253
29
  }
254
30
  }
255
31
  }
@@ -262,17 +38,22 @@ function insert(host, modulePath, changes) {
262
38
  const orderedChanges = changes.sort((a, b) => b.order - a.order);
263
39
  const recorder = host.beginUpdate(modulePath);
264
40
  for (const change of orderedChanges) {
265
- if (change.type == 'insert') {
41
+ // console.log('change.type:', change, ' -change.kind:', change.kind)
42
+ let type = change.type;
43
+ if (change.kind === 'c' || change.kind === 'o') {
44
+ type = general_1.actionToFileChangeMap[change.kind];
45
+ }
46
+ if (type == 'insert') {
266
47
  recorder.insertLeft(change.pos, change.toAdd);
267
48
  }
268
- else if (change.type == 'remove') {
49
+ else if (type == 'remove') {
269
50
  recorder.remove(change.pos - 1, change.toRemove.length + 1);
270
51
  }
271
- else if (change.type == 'replace') {
52
+ else if (type == 'replace') {
272
53
  recorder.remove(change.pos, change.oldText.length);
273
54
  recorder.insertLeft(change.pos, change.newText);
274
55
  }
275
- else if (change.type === 'noop') {
56
+ else if (type === 'noop') {
276
57
  // do nothing
277
58
  }
278
59
  else {
@@ -282,71 +63,3 @@ function insert(host, modulePath, changes) {
282
63
  host.commitUpdate(recorder);
283
64
  }
284
65
  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;
@@ -3,7 +3,7 @@
3
3
  import { Tree as NgTree } from '@angular-devkit/schematics';
4
4
  import { PlatformTypes, FrameworkTypes, ITargetPlatforms } from '@nstudio/xplat-utils';
5
5
  import type { Mode } from 'fs';
6
- import type { FileChange, Tree as DevKitTree, TreeWriteOptions } from 'nx/src/generators/tree';
6
+ import { FileChange, Tree as DevKitTree } from '@nx/devkit';
7
7
  export interface NodeDependency {
8
8
  name: string;
9
9
  version: string;
@@ -106,7 +106,7 @@ export declare class DevkitTreeFromAngularDevkitTree implements DevKitTree {
106
106
  read(filePath: string): Buffer;
107
107
  read(filePath: string, encoding: BufferEncoding): string;
108
108
  rename(from: string, to: string): void;
109
- write(filePath: string, content: Buffer | string, options?: TreeWriteOptions): void;
109
+ write(filePath: string, content: Buffer | string, options?: Parameters<DevKitTree['write']>[2]): void;
110
110
  changePermissions(filePath: string, mode: Mode): void;
111
111
  private warnUnsupportedFilePermissionsChange;
112
112
  }
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
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;
13
- const workspace_1 = require("@nrwl/workspace");
13
+ const workspace_1 = require("@nx/workspace");
14
14
  const xplat_utils_1 = require("@nstudio/xplat-utils");
15
15
  const path_1 = require("path");
16
16
  // list of all supported helpers
@@ -282,7 +282,7 @@ class DevkitTreeFromAngularDevkitTree {
282
282
  }
283
283
  warnUnsupportedFilePermissionsChange(filePath, mode) {
284
284
  console.log(`The Angular DevKit tree does not support changing a file permissions.
285
- Ignoring changing ${filePath} permissions to ${mode}.`);
285
+ Ignoring changing ${filePath} permissions to ${mode}.`);
286
286
  }
287
287
  }
288
288
  exports.DevkitTreeFromAngularDevkitTree = DevkitTreeFromAngularDevkitTree;
@@ -1,6 +1,6 @@
1
1
  import { Tree } from '@angular-devkit/schematics';
2
2
  import { FrameworkTypes } from '@nstudio/xplat-utils';
3
- export { getFileContent } from '@nrwl/workspace/testing';
3
+ export { getFileContent } from '@nx/workspace/testing';
4
4
  export declare function createEmptyWorkspace(tree: Tree, framework?: FrameworkTypes): Tree;
5
5
  export declare function createXplatWithAppsForElectron(tree: Tree): Tree;
6
6
  export declare function createXplatWithApps(tree: Tree, framework?: FrameworkTypes): Tree;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isInDecoratorMetadata = exports.isInComponentMetadata = exports.isInModuleMetadata = exports.createNativeScriptAngularApp = exports.createWebAngularApp = exports.createXplatWebAngular = exports.createXplatNativeScriptAngular = exports.createXplatLibs = exports.createNxLib = exports.createXplatWithNativeScriptWeb = exports.createXplatWithApps = exports.createXplatWithAppsForElectron = exports.createEmptyWorkspace = exports.getFileContent = void 0;
4
- var testing_1 = require("@nrwl/workspace/testing");
4
+ var testing_1 = require("@nx/workspace/testing");
5
5
  Object.defineProperty(exports, "getFileContent", { enumerable: true, get: function () { return testing_1.getFileContent; } });
6
6
  function createEmptyWorkspace(tree, framework) {
7
7
  tree.create('/.gitignore', '');
@@ -1,2 +1,2 @@
1
1
  export declare const xplatVersion = "*";
2
- export declare const nxVersion = "^15.0.0";
2
+ export declare const nxVersion = "^16.0.0";
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nxVersion = exports.xplatVersion = void 0;
4
- exports.xplatVersion = '15.0.4-rc.1';
5
- exports.nxVersion = '^15.0.0';
4
+ exports.xplatVersion = '16.5.0';
5
+ exports.nxVersion = '^16.0.0';
@@ -11,24 +11,24 @@ const tasks_1 = require("@angular-devkit/schematics/tasks");
11
11
  const versions_1 = require("./versions");
12
12
  const output_1 = require("./output");
13
13
  exports.packageInnerDependencies = {
14
- '@nstudio/angular': ['@nrwl/angular'],
14
+ '@nstudio/angular': ['@nx/angular'],
15
15
  '@nstudio/electron-angular': [
16
- '@nrwl/angular',
16
+ '@nx/angular',
17
17
  '@nstudio/electron',
18
18
  '@nstudio/angular',
19
19
  ],
20
20
  '@nstudio/ionic-angular': [
21
- '@nrwl/angular',
21
+ '@nx/angular',
22
22
  '@nstudio/ionic',
23
23
  '@nstudio/angular',
24
24
  '@nstudio/web-angular',
25
25
  ],
26
26
  '@nstudio/nativescript-angular': [
27
- '@nrwl/angular',
27
+ '@nx/angular',
28
28
  '@nstudio/nativescript',
29
29
  '@nstudio/angular',
30
30
  ],
31
- '@nstudio/web-angular': ['@nrwl/angular', '@nstudio/web', '@nstudio/angular'],
31
+ '@nstudio/web-angular': ['@nx/angular', '@nstudio/web', '@nstudio/angular'],
32
32
  };
33
33
  var XplatHelpers;
34
34
  (function (XplatHelpers) {
@@ -42,8 +42,7 @@ var XplatHelpers;
42
42
  */
43
43
  function addPackageWithNgAdd(packageName, options, callSchematicIfAdded) {
44
44
  return (host) => {
45
- const json = (0, xplat_utils_1.getJsonFromFile)(host, 'package.json');
46
- const { dependencies, devDependencies } = json;
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, {
@@ -198,7 +197,7 @@ var XplatHelpers;
198
197
  xplat_utils_1.supportedNxExtraPlatforms.includes(platform)) {
199
198
  // platforms that are supported directly via Nx only right now
200
199
  // 'app'/'application' is only schematic supported via xplat proxy at moment
201
- const packageName = `@nrwl/${platform}`;
200
+ const packageName = `@nx/${platform}`;
202
201
  devDependencies[packageName] = versions_1.nxVersion;
203
202
  packagesToRunXplat.push(packageName);
204
203
  }
@@ -228,7 +227,7 @@ var XplatHelpers;
228
227
  xplat_utils_1.supportedNxExtraPlatforms.includes(platform)) {
229
228
  // platforms supported directly via Nx only right now
230
229
  // 'app'/'application' is only schematic supported via xplat proxy at moment
231
- const packageName = `@nrwl/${platform}`;
230
+ const packageName = `@nx/${platform}`;
232
231
  devDependencies[packageName] = versions_1.nxVersion;
233
232
  packagesToRunXplat.push(packageName);
234
233
  }
@@ -317,7 +316,7 @@ var XplatHelpers;
317
316
  else if (xplat_utils_1.supportedNxExtraPlatforms.includes(platform)) {
318
317
  // platforms supported directly via Nx only right now
319
318
  // 'app'/'application' is only schematic supported via xplat proxy at moment
320
- const packageName = `@nrwl/${platform}`;
319
+ const packageName = `@nx/${platform}`;
321
320
  devDependencies[packageName] = versions_1.nxVersion;
322
321
  packagesToRun.push(packageName);
323
322
  }
@@ -374,7 +373,7 @@ var XplatHelpers;
374
373
  }
375
374
  if (packagesToRun.length) {
376
375
  for (const packageName of packagesToRun) {
377
- const nxPlatform = (packageName.replace('@nrwl/', ''));
376
+ const nxPlatform = (packageName.replace('@nx/', ''));
378
377
  const { name, directory } = getAppNamingConvention(options, nxPlatform);
379
378
  output_1.output.log({
380
379
  title: 'Note:',
@@ -399,7 +398,7 @@ var XplatHelpers;
399
398
  // console.log('devDependencies:', devDependencies);
400
399
  // console.log('packagesToRunXplat:', packagesToRunXplat);
401
400
  for (const packageName of packagesToRun) {
402
- const nxPlatform = (packageName.replace('@nrwl/', ''));
401
+ const nxPlatform = (packageName.replace('@nx/', ''));
403
402
  const { name, directory } = getAppNamingConvention(options, nxPlatform);
404
403
  output_1.output.log({
405
404
  title: 'Note:',
@@ -453,7 +452,7 @@ var XplatHelpers;
453
452
  directory = `${directory}-${framework}`;
454
453
  }
455
454
  if (tree.exists(`libs/${directory ? directory + '/' : ''}${libName}/tsconfig.json`)) {
456
- // console.log(`externalSchematic('@nrwl/workspace', 'lib') ALREADY EXISTS for:`, `libs/${directory ? directory + '/' : ''}${libName}`)
455
+ // console.log(`externalSchematic('@nx/workspace', 'lib') ALREADY EXISTS for:`, `libs/${directory ? directory + '/' : ''}${libName}`)
457
456
  return (0, schematics_1.noop)()(tree, context);
458
457
  }
459
458
  const libOptions = {
@@ -465,8 +464,8 @@ var XplatHelpers;
465
464
  if (libName === 'scss') {
466
465
  libOptions.skipTsConfig = true;
467
466
  }
468
- // console.log(`CALLING externalSchematic('@nrwl/workspace', 'lib') for:`, `libs/${directory ? directory + '/' : ''}${libName}`)
469
- return (0, schematics_1.chain)([(0, schematics_1.externalSchematic)('@nrwl/workspace', 'lib', libOptions)]);
467
+ // console.log(`CALLING externalSchematic('@nx/workspace', 'lib') for:`, `libs/${directory ? directory + '/' : ''}${libName}`)
468
+ return (0, schematics_1.chain)([(0, schematics_1.externalSchematic)('@nx/js', 'library', libOptions)]);
470
469
  };
471
470
  }
472
471
  XplatHelpers.generateLib = generateLib;
@@ -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
- (0, ast_1.insert)(tree, indexFilePath, [
778
- ...(0, ast_1.addGlobal)(indexSourceFile, indexFilePath, `export * from './${options.directory ? options.directory + '/' : ''}${options.name.toLowerCase()}';`, true),
779
- ]);
780
- return tree;
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;