@ronas-it/nx-generators 0.10.3 → 0.10.5

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.
Files changed (220) hide show
  1. package/README.md +10 -1
  2. package/package.json +4 -3
  3. package/src/generators/code-checks/config.d.ts +18 -0
  4. package/src/generators/code-checks/config.js +20 -0
  5. package/src/generators/code-checks/config.js.map +1 -0
  6. package/src/generators/code-checks/files/.eslintrc.json.template +173 -1
  7. package/src/generators/code-checks/generator.d.ts +4 -0
  8. package/src/generators/code-checks/generator.js +53 -0
  9. package/src/generators/code-checks/generator.js.map +1 -0
  10. package/src/generators/code-checks/scripts.d.ts +6 -0
  11. package/src/generators/code-checks/scripts.js +8 -0
  12. package/src/generators/code-checks/scripts.js.map +1 -0
  13. package/src/generators/entity-api/generator.d.ts +4 -0
  14. package/src/generators/entity-api/generator.js +87 -0
  15. package/src/generators/entity-api/generator.js.map +1 -0
  16. package/src/generators/expo-app/generator.d.ts +4 -0
  17. package/src/generators/expo-app/generator.js +93 -0
  18. package/src/generators/expo-app/generator.js.map +1 -0
  19. package/src/generators/expo-app/scripts.d.ts +13 -0
  20. package/src/generators/expo-app/scripts.js +15 -0
  21. package/src/generators/expo-app/scripts.js.map +1 -0
  22. package/src/generators/form/generator.d.ts +4 -0
  23. package/src/generators/form/generator.js +55 -0
  24. package/src/generators/form/generator.js.map +1 -0
  25. package/src/generators/form/utils/add-form-usage.d.ts +1 -0
  26. package/src/generators/form/utils/add-form-usage.js +71 -0
  27. package/src/generators/form/utils/add-form-usage.js.map +1 -0
  28. package/src/generators/form/utils/get-app-name.d.ts +1 -0
  29. package/src/generators/form/utils/get-app-name.js +8 -0
  30. package/src/generators/form/utils/get-app-name.js.map +1 -0
  31. package/src/generators/form/utils/get-form-utils-directory.d.ts +2 -0
  32. package/src/generators/form/utils/get-form-utils-directory.js +35 -0
  33. package/src/generators/form/utils/get-form-utils-directory.js.map +1 -0
  34. package/src/generators/form/utils/index.js +8 -0
  35. package/src/generators/form/utils/index.js.map +1 -0
  36. package/src/generators/form/utils/update-index.d.ts +2 -0
  37. package/src/generators/form/utils/update-index.js +18 -0
  38. package/src/generators/form/utils/update-index.js.map +1 -0
  39. package/src/generators/lib-move/generator.d.ts +4 -0
  40. package/src/generators/lib-move/generator.js +37 -0
  41. package/src/generators/lib-move/generator.js.map +1 -0
  42. package/src/generators/lib-remove/generator.d.ts +4 -0
  43. package/src/generators/lib-remove/generator.js +22 -0
  44. package/src/generators/lib-remove/generator.js.map +1 -0
  45. package/src/generators/lib-rename/generator.d.ts +4 -0
  46. package/src/generators/lib-rename/generator.js +22 -0
  47. package/src/generators/lib-rename/generator.js.map +1 -0
  48. package/src/generators/lib-tags/generator.d.ts +4 -0
  49. package/src/generators/lib-tags/generator.js +56 -0
  50. package/src/generators/lib-tags/generator.js.map +1 -0
  51. package/src/generators/lib-tags/interfaces/context.d.ts +8 -0
  52. package/src/generators/lib-tags/interfaces/context.js +3 -0
  53. package/src/generators/lib-tags/interfaces/context.js.map +1 -0
  54. package/src/generators/lib-tags/interfaces/index.js +6 -0
  55. package/src/generators/lib-tags/interfaces/index.js.map +1 -0
  56. package/src/generators/lib-tags/interfaces/{verify-tag-config.ts → verify-tag-config.d.ts} +6 -7
  57. package/src/generators/lib-tags/interfaces/verify-tag-config.js +3 -0
  58. package/src/generators/lib-tags/interfaces/verify-tag-config.js.map +1 -0
  59. package/src/generators/lib-tags/types/index.js +5 -0
  60. package/src/generators/lib-tags/types/index.js.map +1 -0
  61. package/src/generators/lib-tags/types/tag.js +3 -0
  62. package/src/generators/lib-tags/types/tag.js.map +1 -0
  63. package/src/generators/lib-tags/utils/check-lib-tags.d.ts +4 -0
  64. package/src/generators/lib-tags/utils/check-lib-tags.js +113 -0
  65. package/src/generators/lib-tags/utils/check-lib-tags.js.map +1 -0
  66. package/src/generators/lib-tags/utils/index.js +5 -0
  67. package/src/generators/lib-tags/utils/index.js.map +1 -0
  68. package/src/generators/next-app/generator.d.ts +4 -0
  69. package/src/generators/next-app/generator.js +71 -0
  70. package/src/generators/next-app/generator.js.map +1 -0
  71. package/src/generators/react-component/generator.d.ts +4 -0
  72. package/src/generators/react-component/generator.js +60 -0
  73. package/src/generators/react-component/generator.js.map +1 -0
  74. package/src/generators/react-lib/generator.d.ts +4 -0
  75. package/src/generators/react-lib/generator.js +61 -0
  76. package/src/generators/react-lib/generator.js.map +1 -0
  77. package/src/generators/repo-config/generator.d.ts +3 -0
  78. package/src/generators/repo-config/generator.js +36 -0
  79. package/src/generators/repo-config/generator.js.map +1 -0
  80. package/src/generators/repo-config/scripts.d.ts +4 -0
  81. package/src/generators/repo-config/scripts.js +6 -0
  82. package/src/generators/repo-config/scripts.js.map +1 -0
  83. package/src/index.js +2 -0
  84. package/src/index.js.map +1 -0
  85. package/src/shared/dependencies.d.ts +73 -0
  86. package/src/shared/dependencies.js +79 -0
  87. package/src/shared/dependencies.js.map +1 -0
  88. package/src/shared/enums/base-generator-type.d.ts +4 -0
  89. package/src/shared/enums/base-generator-type.js +9 -0
  90. package/src/shared/enums/base-generator-type.js.map +1 -0
  91. package/src/shared/enums/index.js +5 -0
  92. package/src/shared/enums/index.js.map +1 -0
  93. package/src/shared/generators/api-client/generator.d.ts +6 -0
  94. package/src/shared/generators/api-client/generator.js +37 -0
  95. package/src/shared/generators/api-client/generator.js.map +1 -0
  96. package/src/shared/generators/api-client/index.js +5 -0
  97. package/src/shared/generators/api-client/index.js.map +1 -0
  98. package/src/shared/generators/app-env/generator.d.ts +8 -0
  99. package/src/shared/generators/app-env/generator.js +28 -0
  100. package/src/shared/generators/app-env/generator.js.map +1 -0
  101. package/src/shared/generators/app-env/index.js +5 -0
  102. package/src/shared/generators/app-env/index.js.map +1 -0
  103. package/src/shared/generators/auth/generator.d.ts +4 -0
  104. package/src/shared/generators/auth/generator.js +82 -0
  105. package/src/shared/generators/auth/generator.js.map +1 -0
  106. package/src/shared/generators/auth/index.js +5 -0
  107. package/src/shared/generators/auth/index.js.map +1 -0
  108. package/src/shared/generators/form-utils/generator.d.ts +5 -0
  109. package/src/shared/generators/form-utils/generator.js +24 -0
  110. package/src/shared/generators/form-utils/generator.js.map +1 -0
  111. package/src/shared/generators/form-utils/index.js +5 -0
  112. package/src/shared/generators/form-utils/index.js.map +1 -0
  113. package/src/shared/generators/index.js +12 -0
  114. package/src/shared/generators/index.js.map +1 -0
  115. package/src/shared/generators/rn-styles/generator.d.ts +6 -0
  116. package/src/shared/generators/rn-styles/generator.js +36 -0
  117. package/src/shared/generators/rn-styles/generator.js.map +1 -0
  118. package/src/shared/generators/rn-styles/index.js +5 -0
  119. package/src/shared/generators/rn-styles/index.js.map +1 -0
  120. package/src/shared/generators/storage/generator.d.ts +6 -0
  121. package/src/shared/generators/storage/generator.js +27 -0
  122. package/src/shared/generators/storage/generator.js.map +1 -0
  123. package/src/shared/generators/storage/index.js +5 -0
  124. package/src/shared/generators/storage/index.js.map +1 -0
  125. package/src/shared/generators/store/generator.d.ts +4 -0
  126. package/src/shared/generators/store/generator.js +36 -0
  127. package/src/shared/generators/store/generator.js.map +1 -0
  128. package/src/shared/generators/store/index.js +5 -0
  129. package/src/shared/generators/store/index.js.map +1 -0
  130. package/src/shared/generators/ui-kitten/generator.d.ts +6 -0
  131. package/src/shared/generators/ui-kitten/generator.js +40 -0
  132. package/src/shared/generators/ui-kitten/generator.js.map +1 -0
  133. package/src/shared/generators/ui-kitten/index.js +5 -0
  134. package/src/shared/generators/ui-kitten/index.js.map +1 -0
  135. package/src/shared/templates/config-template.json +2 -12
  136. package/src/shared/utils/cli-utils.d.ts +31 -0
  137. package/src/shared/utils/cli-utils.js +129 -0
  138. package/src/shared/utils/cli-utils.js.map +1 -0
  139. package/src/shared/utils/config-utils.d.ts +19 -0
  140. package/src/shared/utils/config-utils.js +124 -0
  141. package/src/shared/utils/config-utils.js.map +1 -0
  142. package/src/shared/utils/constants.d.ts +3 -0
  143. package/src/shared/utils/constants.js +7 -0
  144. package/src/shared/utils/constants.js.map +1 -0
  145. package/src/shared/utils/dynamic-import.d.ts +1 -0
  146. package/src/shared/utils/dynamic-import.js +5 -0
  147. package/src/shared/utils/dynamic-import.js.map +1 -0
  148. package/src/shared/utils/format-utils.d.ts +4 -0
  149. package/src/shared/utils/format-utils.js +18 -0
  150. package/src/shared/utils/format-utils.js.map +1 -0
  151. package/src/shared/utils/get-lib-directory-name.d.ts +1 -0
  152. package/src/shared/utils/get-lib-directory-name.js +15 -0
  153. package/src/shared/utils/get-lib-directory-name.js.map +1 -0
  154. package/src/shared/utils/index.js +11 -0
  155. package/src/shared/utils/index.js.map +1 -0
  156. package/src/shared/utils/ts-utils.d.ts +2 -0
  157. package/src/shared/utils/ts-utils.js +22 -0
  158. package/src/shared/utils/ts-utils.js.map +1 -0
  159. package/.eslintrc.json +0 -37
  160. package/jest.config.ts +0 -10
  161. package/project.json +0 -61
  162. package/src/generators/code-checks/config.ts +0 -17
  163. package/src/generators/code-checks/generator.ts +0 -72
  164. package/src/generators/code-checks/scripts.ts +0 -5
  165. package/src/generators/entity-api/generator.ts +0 -127
  166. package/src/generators/expo-app/generator.ts +0 -152
  167. package/src/generators/expo-app/scripts.ts +0 -12
  168. package/src/generators/form/generator.ts +0 -53
  169. package/src/generators/form/utils/add-form-usage.ts +0 -86
  170. package/src/generators/form/utils/get-app-name.ts +0 -3
  171. package/src/generators/form/utils/get-form-utils-directory.ts +0 -46
  172. package/src/generators/form/utils/update-index.ts +0 -14
  173. package/src/generators/lib-move/generator.ts +0 -57
  174. package/src/generators/lib-remove/generator.ts +0 -25
  175. package/src/generators/lib-rename/generator.ts +0 -25
  176. package/src/generators/lib-tags/generator.ts +0 -68
  177. package/src/generators/lib-tags/interfaces/context.ts +0 -9
  178. package/src/generators/lib-tags/utils/check-lib-tags.ts +0 -143
  179. package/src/generators/next-app/generator.ts +0 -99
  180. package/src/generators/react-component/generator.ts +0 -80
  181. package/src/generators/react-lib/generator.ts +0 -86
  182. package/src/generators/repo-config/generator.ts +0 -44
  183. package/src/generators/repo-config/scripts.ts +0 -3
  184. package/src/shared/dependencies.ts +0 -76
  185. package/src/shared/enums/base-generator-type.ts +0 -4
  186. package/src/shared/generators/api-client/generator.ts +0 -49
  187. package/src/shared/generators/app-env/generator.ts +0 -37
  188. package/src/shared/generators/auth/generator.ts +0 -107
  189. package/src/shared/generators/form-utils/generator.ts +0 -23
  190. package/src/shared/generators/rn-styles/generator.ts +0 -49
  191. package/src/shared/generators/storage/generator.ts +0 -34
  192. package/src/shared/generators/store/generator.ts +0 -48
  193. package/src/shared/generators/ui-kitten/generator.ts +0 -55
  194. package/src/shared/utils/cli-utils.ts +0 -149
  195. package/src/shared/utils/config-utils.ts +0 -146
  196. package/src/shared/utils/constants.ts +0 -3
  197. package/src/shared/utils/dynamic-import.ts +0 -4
  198. package/src/shared/utils/format-utils.ts +0 -16
  199. package/src/shared/utils/get-lib-directory-name.ts +0 -12
  200. package/src/shared/utils/ts-utils.ts +0 -17
  201. package/tsconfig.json +0 -16
  202. package/tsconfig.lib.json +0 -10
  203. package/tsconfig.spec.json +0 -14
  204. /package/src/generators/form/utils/{index.ts → index.d.ts} +0 -0
  205. /package/src/generators/lib-tags/interfaces/{index.ts → index.d.ts} +0 -0
  206. /package/src/generators/lib-tags/types/{index.ts → index.d.ts} +0 -0
  207. /package/src/generators/lib-tags/types/{tag.ts → tag.d.ts} +0 -0
  208. /package/src/generators/lib-tags/utils/{index.ts → index.d.ts} +0 -0
  209. /package/src/{index.ts → index.d.ts} +0 -0
  210. /package/src/shared/enums/{index.ts → index.d.ts} +0 -0
  211. /package/src/shared/generators/api-client/{index.ts → index.d.ts} +0 -0
  212. /package/src/shared/generators/app-env/{index.ts → index.d.ts} +0 -0
  213. /package/src/shared/generators/auth/{index.ts → index.d.ts} +0 -0
  214. /package/src/shared/generators/form-utils/{index.ts → index.d.ts} +0 -0
  215. /package/src/shared/generators/{index.ts → index.d.ts} +0 -0
  216. /package/src/shared/generators/rn-styles/{index.ts → index.d.ts} +0 -0
  217. /package/src/shared/generators/storage/{index.ts → index.d.ts} +0 -0
  218. /package/src/shared/generators/store/{index.ts → index.d.ts} +0 -0
  219. /package/src/shared/generators/ui-kitten/{index.ts → index.d.ts} +0 -0
  220. /package/src/shared/utils/{index.ts → index.d.ts} +0 -0
@@ -1,107 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import * as path from 'path';
3
- import {
4
- addDependenciesToPackageJson,
5
- formatFiles,
6
- generateFiles,
7
- installPackagesTask,
8
- Tree
9
- } from '@nx/devkit';
10
- import { dependencies, devDependencies } from '../../dependencies';
11
- import { formatName, formatAppIdentifier, searchAliasPath, getImportPathPrefix } from '../../utils';
12
- import { existsSync } from 'fs';
13
- import { IndentationText, Project, QuoteKind, StructureKind, SyntaxKind } from 'ts-morph';
14
- import { AuthGeneratorSchema } from './schema';
15
-
16
- const updateStore = (libRoot: string): void => {
17
- const project = new Project({
18
- manipulationSettings: {
19
- indentationText: IndentationText.TwoSpaces,
20
- quoteKind: QuoteKind.Single
21
- }
22
- });
23
-
24
- const storePath = `${libRoot}/shared/data-access/store/src`;
25
- const apiPath = `${libRoot}/shared/data-access/api/src`;
26
- const authPath = `${libRoot}/shared/data-access/auth/src`;
27
- const store = project.addSourceFileAtPath(`${storePath}/store.ts`);
28
- const apiAlias = searchAliasPath(apiPath);
29
- const authAlias = searchAliasPath(authPath);
30
-
31
- if (!apiAlias) {
32
- throw new Error('Could not find API library.');
33
- }
34
-
35
- if (!authAlias) {
36
- throw new Error('Could not find Auth library.');
37
- }
38
-
39
- store.addImportDeclarations([
40
- { moduleSpecifier: apiAlias, namedImports: ['authApi', 'profileApi'] },
41
- { moduleSpecifier: authAlias, namedImports: [ 'authListenerMiddleware', 'authReducer', 'authReducerPath'] }
42
- ]);
43
-
44
- const rootReducer = store.getVariableDeclarationOrThrow('rootReducer');
45
-
46
- rootReducer.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression)
47
- .addProperties([
48
- { name: '[authApi.reducerPath]', initializer: 'authApi.reducer', kind: StructureKind.PropertyAssignment },
49
- { name: '[authReducerPath]', initializer: 'authReducer', kind: StructureKind.PropertyAssignment },
50
- { name: '[profileApi.reducerPath]', initializer: 'profileApi.reducer', kind: StructureKind.PropertyAssignment }
51
- ]);
52
-
53
- const middlewares = store.getVariableDeclarationOrThrow('middlewares');
54
-
55
- middlewares.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression)
56
- .addElements([
57
- 'authApi.middleware',
58
- 'authListenerMiddleware.middleware',
59
- 'profileApi.middleware'
60
- ], { useNewLines: true });
61
-
62
- project.saveSync();
63
- };
64
-
65
- export async function runAuthGenerator(
66
- tree: Tree,
67
- options: AuthGeneratorSchema
68
- ) {
69
- const appRoot = `apps/${options.directory}`;
70
- const libRoot = `libs/${options.directory}`;
71
- const libPath = `${getImportPathPrefix(tree)}/${options.directory}`;
72
-
73
- // Generate shared libs
74
- execSync(`npx nx g react-lib --app=${options.directory} --scope=shared --type=data-access --name=api`, { stdio: 'inherit' });
75
- execSync(`npx nx g react-lib --app=${options.directory} --scope=shared --type=data-access --name=auth`, { stdio: 'inherit' });
76
-
77
- const appPackagePath = `${appRoot}/package.json`;
78
-
79
- // Remove unnecessary files and files that will be replaced
80
- tree.delete(`${libRoot}/shared/data-access/api/src/index.ts`);
81
- tree.delete(`${libRoot}/shared/data-access/auth/src/index.ts`);
82
-
83
- // Add lib files
84
- generateFiles(tree, path.join(__dirname, '/lib-files'), libRoot, {
85
- ...options,
86
- formatName,
87
- formatAppIdentifier,
88
- formatDirectory: () => libPath
89
- });
90
-
91
- updateStore(libRoot);
92
-
93
- // Add dependencies
94
- addDependenciesToPackageJson(tree, dependencies['auth'], devDependencies['auth']);
95
-
96
- if (existsSync(appPackagePath)) {
97
- addDependenciesToPackageJson(tree, dependencies['auth'], devDependencies['auth'], appPackagePath);
98
- }
99
-
100
- await formatFiles(tree);
101
-
102
- return () => {
103
- installPackagesTask(tree);
104
- };
105
- }
106
-
107
- export default runAuthGenerator;
@@ -1,23 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import * as path from 'path';
3
- import { formatFiles, generateFiles, Tree } from '@nx/devkit';
4
-
5
- export async function runFormUtilsGenerator(
6
- tree: Tree,
7
- options: { directory: string }
8
- ) {
9
- const libRoot = `libs/${options.directory}`;
10
-
11
- // Generate shared libs
12
- execSync(`npx nx g react-lib --app=${options.directory} --scope=shared --type=utils --name=form`, { stdio: 'inherit' });
13
-
14
- // Remove unnecessary files and files that will be replaced
15
- tree.delete(`${libRoot}/shared/utils/form/src/index.ts`);
16
-
17
- // Add lib files
18
- generateFiles(tree, path.join(__dirname, '/lib-files'), libRoot, {});
19
-
20
- await formatFiles(tree);
21
- }
22
-
23
- export default runFormUtilsGenerator;
@@ -1,49 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import { existsSync } from 'fs';
3
- import * as path from 'path';
4
- import {
5
- addDependenciesToPackageJson,
6
- formatFiles,
7
- generateFiles,
8
- Tree,
9
- } from '@nx/devkit';
10
- import { dependencies } from '../../dependencies';
11
- import { formatName, formatAppIdentifier, getImportPathPrefix } from '../../utils';
12
-
13
- export async function runRNStylesGenerator(
14
- tree: Tree,
15
- options: { name: string; directory: string },
16
- ) {
17
- const appRoot = `apps/${options.directory}`;
18
- const libRoot = `libs/${options.directory}`;
19
- const libPath = `${getImportPathPrefix(tree)}/${options.directory}`;
20
-
21
- // Generate shared libs
22
- execSync(`npx nx g react-lib --app=${options.directory} --scope=shared --type=ui --name=styles --withComponent=false`, {
23
- stdio: 'inherit',
24
- });
25
-
26
- const appPackagePath = `${appRoot}/package.json`;
27
-
28
- // Remove unnecessary files and files that will be replaced
29
- tree.delete(`${libRoot}/shared/ui/styles/src/index.ts`);
30
-
31
- // Add lib files
32
- generateFiles(tree, path.join(__dirname, 'lib-files'), libRoot, {
33
- ...options,
34
- formatName,
35
- formatAppIdentifier,
36
- formatDirectory: () => libPath,
37
- });
38
-
39
- // Add dependencies
40
- addDependenciesToPackageJson(tree, dependencies['rn-styles'], {});
41
-
42
- if (existsSync(appPackagePath)) {
43
- addDependenciesToPackageJson(tree, dependencies['rn-styles'], {}, appPackagePath);
44
- }
45
-
46
- await formatFiles(tree);
47
- }
48
-
49
- export default runRNStylesGenerator;
@@ -1,34 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import * as path from 'path';
3
- import {
4
- formatFiles,
5
- generateFiles,
6
- Tree
7
- } from '@nx/devkit';
8
- import { formatName, formatAppIdentifier, getImportPathPrefix } from '../../utils';
9
-
10
- export async function runStorageGenerator(
11
- tree: Tree,
12
- options: { name: string; directory: string }
13
- ) {
14
- const libRoot = `libs/${options.directory}`;
15
- const libPath = `${getImportPathPrefix(tree)}/${options.directory}`;
16
-
17
- // Generate shared libs
18
- execSync(`npx nx g react-lib --app=${options.directory} --scope=shared --type=data-access --name=storage`, { stdio: 'inherit' });
19
-
20
- // Remove unnecessary files and files that will be replaced
21
- tree.delete(`${libRoot}/shared/data-access/storage/src/index.ts`);
22
-
23
- // Add lib files
24
- generateFiles(tree, path.join(__dirname, '/lib-files'), libRoot, {
25
- ...options,
26
- formatName,
27
- formatAppIdentifier,
28
- formatDirectory: () => libPath
29
- });
30
-
31
- await formatFiles(tree);
32
- }
33
-
34
- export default runStorageGenerator;
@@ -1,48 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import { existsSync } from 'fs';
3
- import * as path from 'path';
4
- import {
5
- addDependenciesToPackageJson,
6
- formatFiles,
7
- generateFiles,
8
- Tree
9
- } from '@nx/devkit';
10
- import { dependencies } from '../../dependencies';
11
- import { formatName, formatAppIdentifier, getImportPathPrefix } from '../../utils';
12
- import { StoreGeneratorSchema } from './schema';
13
-
14
- export async function runStoreGenerator(
15
- tree: Tree,
16
- options: StoreGeneratorSchema
17
- ) {
18
- const appRoot = `apps/${options.directory}`;
19
- const libRoot = `libs/${options.directory}`;
20
- const libPath = `${getImportPathPrefix(tree)}/${options.directory}`;
21
-
22
- // Generate shared libs
23
- execSync(`npx nx g react-lib --app=${options.directory} --scope=shared --type=data-access --name=store`, { stdio: 'inherit' });
24
-
25
- const appPackagePath = `${appRoot}/package.json`;
26
-
27
- // Remove unnecessary files and files that will be replaced
28
- tree.delete(`${libRoot}/shared/data-access/store/src/index.ts`);
29
-
30
- // Add lib files
31
- generateFiles(tree, path.join(__dirname, `${options.baseGeneratorType}/lib-files`), libRoot, {
32
- ...options,
33
- formatName,
34
- formatAppIdentifier,
35
- formatDirectory: () => libPath
36
- });
37
-
38
- // Add dependencies
39
- addDependenciesToPackageJson(tree, dependencies['store'], {});
40
-
41
- if (existsSync(appPackagePath)) {
42
- addDependenciesToPackageJson(tree, dependencies['store'], {}, appPackagePath);
43
- }
44
-
45
- await formatFiles(tree);
46
- }
47
-
48
- export default runStoreGenerator;
@@ -1,55 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import { existsSync } from 'fs';
3
- import * as path from 'path';
4
- import {
5
- addDependenciesToPackageJson,
6
- formatFiles,
7
- generateFiles,
8
- Tree,
9
- } from '@nx/devkit';
10
- import { dependencies } from '../../dependencies';
11
- import { formatName, formatAppIdentifier, getImportPathPrefix, LibraryType } from '../../utils';
12
-
13
- export async function runUIKittenGenerator(
14
- tree: Tree,
15
- options: { name: string; directory: string }
16
- ) {
17
- const appRoot = `apps/${options.directory}`;
18
- const libRoot = `libs/${options.directory}`;
19
- const libPath = `${getImportPathPrefix(tree)}/${options.directory}`;
20
-
21
- // Generate shared libs
22
- execSync(`npx nx g react-lib --app=${options.directory} --scope=shared --type=${LibraryType.FEATURES} --name=user-theme-provider --withComponent=false`, {
23
- stdio: 'inherit',
24
- });
25
-
26
- const appPackagePath = `${appRoot}/package.json`;
27
-
28
- // Remove unnecessary files and files that will be replaced
29
- tree.delete(`${libRoot}/shared/features/user-theme-provider/src/index.ts`);
30
-
31
- // Add lib files
32
- generateFiles(tree, path.join(__dirname, 'lib-files'), libRoot, {
33
- ...options,
34
- formatName,
35
- formatAppIdentifier,
36
- formatDirectory: () => libPath,
37
- });
38
-
39
- // Update styles lib exports
40
- const stylesLibIndexData = tree.read(`${libRoot}/shared/ui/styles/src/lib/index.ts`);
41
- const newStylesLibIndexData = stylesLibIndexData + `export * from './create-adaptive-styles';\nexport * from './eva-theme';\n`;
42
-
43
- tree.write(`${libRoot}/shared/ui/styles/src/lib/index.ts`, newStylesLibIndexData);
44
-
45
- // Add dependencies
46
- addDependenciesToPackageJson(tree, dependencies['ui-kitten'], {});
47
-
48
- if (existsSync(appPackagePath)) {
49
- addDependenciesToPackageJson(tree, dependencies['ui-kitten'], {}, appPackagePath);
50
- }
51
-
52
- await formatFiles(tree);
53
- }
54
-
55
- export default runUIKittenGenerator;
@@ -1,149 +0,0 @@
1
- import * as readline from 'readline';
2
- import * as fs from 'fs';
3
- import { getProjects, ProjectType, Tree } from '@nx/devkit';
4
- import { dynamicImport } from './dynamic-import';
5
- import { constants } from './constants';
6
-
7
- export const createCliReadline = (): readline.Interface => readline.createInterface({
8
- input: process.stdin,
9
- output: process.stdout,
10
- })
11
-
12
- export const askQuestion = (question: string, defaultAnswer?: string, cliReadline?: readline.Interface): Promise<string> => {
13
- const rl = cliReadline || createCliReadline();
14
-
15
- if (defaultAnswer) {
16
- rl.write(defaultAnswer);
17
- // Move cursor to end of the line
18
- setTimeout(() => rl.write(null, { ctrl: true, name: 'e' }));
19
- }
20
-
21
- return new Promise((resolve) =>
22
- rl.question(question, (answer) => {
23
- if (!cliReadline) {
24
- rl.close();
25
- }
26
- resolve(answer);
27
- }),
28
- );
29
- };
30
-
31
- export enum LibraryType {
32
- UI = 'ui',
33
- DATA_ACCESS = 'data-access',
34
- FEATURES = 'features',
35
- UTILS = 'utils',
36
- }
37
-
38
- const parseLibsPaths = (): Record<string, Array<string>> => {
39
- let tsconfig;
40
-
41
- if (fs.existsSync('tsconfig.base.json')) {
42
- tsconfig = JSON.parse(fs.readFileSync('tsconfig.base.json', 'utf8'));
43
- } else {
44
- tsconfig = JSON.parse(fs.readFileSync('tsconfig.json', 'utf8'));
45
- }
46
-
47
- return tsconfig.compilerOptions.paths;
48
- };
49
-
50
- export const validateLibraryType = (type: string): string => {
51
- const allLibraryTypes = Object.values(LibraryType);
52
-
53
- if (!allLibraryTypes.includes(type as LibraryType)) {
54
- throw new Error(`Invalid library type: ${type}.\nAvailable types: ${allLibraryTypes.join(', ')}`);
55
- }
56
-
57
- return type;
58
- }
59
-
60
- export const getNxLibsPaths = (types: Array<LibraryType>) => {
61
- const libs = parseLibsPaths();
62
-
63
- return Object.values(libs)
64
- .map((value) => value[0].replace('/index.ts', ''))
65
- .filter((value) => types.some((type) => value.includes(type)));
66
- };
67
-
68
- export const searchNxLibsPaths = (
69
- paths: Array<string>,
70
- input: string,
71
- method: 'includes' | 'startsWith' | 'endsWith' = 'includes',
72
- ) => {
73
- return paths.filter((path) => path[method](input));
74
- };
75
-
76
- export const searchAliasPath = (input: string) => {
77
- const libs = parseLibsPaths();
78
- const path = Object.keys(libs).find((key) => libs[key][0].includes(input));
79
-
80
- return path;
81
- };
82
-
83
- export const filterSource = async (input: string, source: Array<string>) => {
84
- const filteredData = input
85
- ? source.filter((pathname) => pathname.toLowerCase().includes(input.toLowerCase()))
86
- : source;
87
-
88
- return filteredData.map((path) => ({ value: path }));
89
- };
90
-
91
- export const appendFileContent = (path: string, endContent: string, tree: Tree) => {
92
- const content = tree.read(path, 'utf-8');
93
- const contentUpdate = (content || '') + endContent;
94
-
95
- tree.write(path, contentUpdate);
96
- };
97
-
98
- export const getProjectsDetails = (tree: Tree, projectType: ProjectType) => Array.from(getProjects(tree))
99
- .filter(([_, project]) => project.projectType === projectType)
100
- .map(([name, project]) => ({ name, path: project.root }));
101
-
102
- export const selectProject = async (tree: Tree, projectType: ProjectType, message: string): Promise<{ name: string, path: string }> => {
103
- const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>('inquirer-autocomplete-standalone');
104
- const projects = getProjectsDetails(tree, projectType);
105
-
106
- if (!projects.length) {
107
- throw new Error(`No projects of type ${projectType} found.`);
108
- }
109
-
110
- return autocomplete({
111
- message,
112
- source: async (input) => {
113
- const entries = [...projects, { name: constants.sharedValue, path: constants.sharedValue }].map((project) => ({
114
- name: `${project.name} (${project.path})`,
115
- value: { ...project, name: projectType === 'application' ? project.path.replace('apps/', '') : project.name }
116
- }));
117
-
118
- if (!input) {
119
- return entries;
120
- }
121
-
122
- return entries.filter((entry) => entry.name.toLowerCase().includes(input.toLowerCase()));
123
- }
124
- });
125
- };
126
-
127
- export const getLibraryDetailsByName = async (tree: Tree, libraryName?: string): Promise<{ name: string; path: string }> => {
128
- let selectedLibraryName: string;
129
- let selectedLibraryPath: string;
130
-
131
- if (libraryName) {
132
- selectedLibraryName = libraryName;
133
-
134
- const library = getProjectsDetails(tree, 'library').find((library) => library.name === selectedLibraryName);
135
-
136
- if (!library) {
137
- throw new Error(`Library ${selectedLibraryName} not found`);
138
- }
139
-
140
- selectedLibraryPath = library.path;
141
- } else {
142
- const selectedLibrary = await selectProject(tree, 'library', 'Select the library to move: ');
143
-
144
- selectedLibraryName = selectedLibrary.name;
145
- selectedLibraryPath = selectedLibrary.path;
146
- }
147
-
148
- return { name: selectedLibraryName, path: selectedLibraryPath };
149
- };
@@ -1,146 +0,0 @@
1
- import { Tree, output, readJson, writeJson } from '@nx/devkit';
2
- import { isEmpty } from 'lodash';
3
-
4
- const defaultEsLintConfigPath = '.eslintrc.json';
5
-
6
- export interface Constraint {
7
- sourceTag: string;
8
- onlyDependOnLibsWithTags: Array<string>;
9
- }
10
-
11
- const getNxRulesEntry = (config: Record<string, any>): { files: Array<string>, rules: Record<string, any> } =>
12
- config.overrides?.find((entry: { rules: { [x: string]: any; }; }) => !!entry.rules['@nx/enforce-module-boundaries']);
13
-
14
- export const getNxRulesEntryOrThrowError = (config: Record<string, any>): { files: Array<string>, rules: Record<string, any> } => {
15
- if (!config) {
16
- throw new Error('ESLint config not found');
17
- }
18
-
19
- const entryWithRules = getNxRulesEntry(config);
20
-
21
- if (!entryWithRules) {
22
- throw new Error(`ESLint: can't find '@nx/enforce-module-boundaries' rule`);
23
- }
24
-
25
- return entryWithRules;
26
- }
27
-
28
- export const getNxRulesStatus = (config: Record<string, any>): string => {
29
- return getNxRulesEntryOrThrowError(config).rules['@nx/enforce-module-boundaries'][0];
30
- }
31
-
32
- export const getNxRules = (config: Record<string, any>): Array<Constraint> => {
33
- return getNxRulesEntryOrThrowError(config).rules['@nx/enforce-module-boundaries'][1].depConstraints;
34
- };
35
-
36
- export const readESLintConfig = (tree: Tree): { config: Record<string, any>, path: string } => {
37
- let path = defaultEsLintConfigPath;
38
-
39
- const checkConfigExists = (path: string): void => {
40
- if (!tree.exists(path)) {
41
- throw new Error(`ESLint config not found: ${path}`);
42
- }
43
- };
44
-
45
- checkConfigExists(path);
46
-
47
- let config = readJson(tree, path);
48
-
49
- if (getNxRulesEntry(config)) {
50
- return { config, path };
51
- }
52
-
53
- if (config.extends?.length) {
54
- path = config.extends[0];
55
-
56
- checkConfigExists(path);
57
-
58
- config = readJson(tree, config.extends[0]);
59
- }
60
-
61
- return { config, path };
62
- };
63
-
64
- const getNpmScope = (tree: Tree): string | undefined => {
65
- const { name } = tree.exists('package.json')
66
- ? readJson<{ name?: string }>(tree, 'package.json')
67
- : { name: null };
68
-
69
- return name?.startsWith('@') ? name.split('/')[0].substring(1) : undefined;
70
- };
71
-
72
- export const addNxAppTag = (tree: Tree, appDirectory: string): void => {
73
- const { config, path } = readESLintConfig(tree);
74
- const constraints = getNxRules(config);
75
- const doesTagExist = !!constraints.find((constraint) => constraint.sourceTag === `app:${appDirectory}`);
76
-
77
- if (doesTagExist) {
78
- return;
79
- }
80
-
81
- constraints.push({ sourceTag: `app:${appDirectory}`, onlyDependOnLibsWithTags: [`app:${appDirectory}`, 'app:shared'] });
82
-
83
- writeJson(tree, path, config);
84
- };
85
-
86
- export const addNxScopeTag = (tree: Tree, scope: string): void => {
87
- const { config, path } = readESLintConfig(tree);
88
- const constraints = getNxRules(config);
89
- const doesTagExist = !!constraints.find((constraint) => constraint.sourceTag === `scope:${scope}`);
90
-
91
- if (doesTagExist) {
92
- return;
93
- }
94
-
95
- constraints.push({ sourceTag: `scope:${scope}`, onlyDependOnLibsWithTags: [`scope:${scope}`, 'scope:shared'] });
96
-
97
- writeJson(tree, path, config);
98
- };
99
-
100
- export const getImportPathPrefix = (tree: Tree): string => {
101
- const npmScope = getNpmScope(tree);
102
-
103
- return npmScope ? `${npmScope === '@' ? '' : '@'}${npmScope}` : '';
104
- };
105
-
106
- export const verifyEsLintConfig = (tree: Tree): Record<string, any> => {
107
- const { config, path } = readESLintConfig(tree);
108
- const importantTags = ['app:shared', 'scope:shared', 'type:app', 'type:data-access', 'type:features', 'type:ui', 'type:utils'];
109
-
110
- if (!config || isEmpty(config)) {
111
- throw new Error(`Failed to load ESLint config: ${path}`);
112
- }
113
-
114
- try {
115
- const rulesEntry = getNxRulesEntryOrThrowError(config).rules['@nx/enforce-module-boundaries'];
116
- const tags = rulesEntry[1].depConstraints.map((rule: Constraint) => rule.sourceTag);
117
- const areRulesDisabled = rulesEntry[1].depConstraints.find((rule: Constraint) => rule.sourceTag === '*' && rule.onlyDependOnLibsWithTags.includes('*'));
118
- const areRulesBroken = !importantTags.every((tag) => tags.includes(tag));
119
-
120
- if (rulesEntry[0] !== 'error') {
121
- rulesEntry[0] = 'error';
122
- }
123
-
124
- if (areRulesDisabled || areRulesBroken) {
125
- // eslint-disable-next-line @typescript-eslint/no-var-requires
126
- const esLintConfigTemplate = require('../templates/config-template.json');
127
- const templateRules = esLintConfigTemplate.rules['@nx/enforce-module-boundaries'];
128
-
129
- rulesEntry[0] = templateRules[0];
130
- rulesEntry[1] = templateRules[1];
131
-
132
- writeJson(tree, path, config);
133
- }
134
- // TODO: use custom errors
135
- } catch {
136
- output.warn({ title: output.bold('ESLint config has no @nx/enforce-module-boundaries rule. Updating rules...') });
137
- // eslint-disable-next-line @typescript-eslint/no-var-requires
138
- const esLintConfigRulesTemplate = require('../templates/config-template.json');
139
-
140
- config.overrides.push(esLintConfigRulesTemplate);
141
-
142
- writeJson(tree, path, config);
143
- }
144
-
145
- return config;
146
- };
@@ -1,3 +0,0 @@
1
- export const constants = {
2
- sharedValue: 'shared'
3
- };
@@ -1,4 +0,0 @@
1
- export const dynamicImport = new Function(
2
- 'specifier',
3
- 'return import(specifier)'
4
- ) as <T = never>(specifier: string) => Promise<T>;
@@ -1,16 +0,0 @@
1
- export const formatName = (value: string, withoutSpaces = false) =>
2
- value
3
- .split('-')
4
- .map((word) => `${word.charAt(0).toUpperCase()}${word.substring(1)}`)
5
- .join(withoutSpaces ? '' : ' ');
6
-
7
- export const formatAppIdentifier = (value: string) =>
8
- value.toLowerCase().replace(/-/g, '.');
9
-
10
- export const getProjectName = (str: string) => {
11
- const parts = str.split('@');
12
-
13
- return parts.length > 1 ? parts[1].split('/')[0] : parts[0];
14
- };
15
-
16
- export const getLibName = (path: string) => path.split('/').pop();
@@ -1,12 +0,0 @@
1
- export function getLibDirectoryName(libName: string, scopeName: string): string {
2
- const libWords = libName.split('-');
3
- const scopeWords = scopeName.split('-');
4
- let newLibWords = libWords;
5
-
6
- const startsWithScopeWords = scopeWords.every((word, index) => libWords[index] === word);
7
- if (startsWithScopeWords && libWords.length > scopeWords.length) {
8
- newLibWords = libWords.slice(scopeWords.length);
9
- }
10
-
11
- return newLibWords.join('-');
12
- }
@@ -1,17 +0,0 @@
1
- import { SourceFile } from 'ts-morph';
2
-
3
- export const addNamedImport = (namedImport: string, moduleSpecifier: string, file: SourceFile): void => {
4
- const importDeclaration = file.getImportDeclaration(moduleSpecifier);
5
- if (importDeclaration) {
6
- const hasNamedImport = importDeclaration.getNamedImports()
7
- .find((declaration) => declaration.getName() === namedImport);
8
- if (!hasNamedImport) {
9
- importDeclaration.addNamedImport(namedImport);
10
- }
11
- } else {
12
- file.addImportDeclaration({
13
- namedImports: [namedImport],
14
- moduleSpecifier
15
- })
16
- }
17
- }