@ronas-it/nx-generators 0.10.4 → 0.10.6

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 (217) hide show
  1. package/package.json +4 -3
  2. package/src/generators/code-checks/config.d.ts +18 -0
  3. package/src/generators/code-checks/config.js +20 -0
  4. package/src/generators/code-checks/config.js.map +1 -0
  5. package/src/generators/code-checks/generator.d.ts +4 -0
  6. package/src/generators/code-checks/generator.js +53 -0
  7. package/src/generators/code-checks/generator.js.map +1 -0
  8. package/src/generators/code-checks/scripts.d.ts +6 -0
  9. package/src/generators/code-checks/scripts.js +8 -0
  10. package/src/generators/code-checks/scripts.js.map +1 -0
  11. package/src/generators/entity-api/generator.d.ts +4 -0
  12. package/src/generators/entity-api/generator.js +87 -0
  13. package/src/generators/entity-api/generator.js.map +1 -0
  14. package/src/generators/expo-app/generator.d.ts +4 -0
  15. package/src/generators/expo-app/generator.js +93 -0
  16. package/src/generators/expo-app/generator.js.map +1 -0
  17. package/src/generators/expo-app/scripts.d.ts +13 -0
  18. package/src/generators/expo-app/scripts.js +15 -0
  19. package/src/generators/expo-app/scripts.js.map +1 -0
  20. package/src/generators/form/generator.d.ts +4 -0
  21. package/src/generators/form/generator.js +55 -0
  22. package/src/generators/form/generator.js.map +1 -0
  23. package/src/generators/form/utils/add-form-usage.d.ts +1 -0
  24. package/src/generators/form/utils/add-form-usage.js +71 -0
  25. package/src/generators/form/utils/add-form-usage.js.map +1 -0
  26. package/src/generators/form/utils/get-app-name.d.ts +1 -0
  27. package/src/generators/form/utils/get-app-name.js +8 -0
  28. package/src/generators/form/utils/get-app-name.js.map +1 -0
  29. package/src/generators/form/utils/get-form-utils-directory.d.ts +2 -0
  30. package/src/generators/form/utils/get-form-utils-directory.js +35 -0
  31. package/src/generators/form/utils/get-form-utils-directory.js.map +1 -0
  32. package/src/generators/form/utils/index.js +8 -0
  33. package/src/generators/form/utils/index.js.map +1 -0
  34. package/src/generators/form/utils/update-index.d.ts +2 -0
  35. package/src/generators/form/utils/update-index.js +18 -0
  36. package/src/generators/form/utils/update-index.js.map +1 -0
  37. package/src/generators/lib-move/generator.d.ts +4 -0
  38. package/src/generators/lib-move/generator.js +37 -0
  39. package/src/generators/lib-move/generator.js.map +1 -0
  40. package/src/generators/lib-remove/generator.d.ts +4 -0
  41. package/src/generators/lib-remove/generator.js +22 -0
  42. package/src/generators/lib-remove/generator.js.map +1 -0
  43. package/src/generators/lib-rename/generator.d.ts +4 -0
  44. package/src/generators/lib-rename/generator.js +22 -0
  45. package/src/generators/lib-rename/generator.js.map +1 -0
  46. package/src/generators/lib-tags/generator.d.ts +4 -0
  47. package/src/generators/lib-tags/generator.js +56 -0
  48. package/src/generators/lib-tags/generator.js.map +1 -0
  49. package/src/generators/lib-tags/interfaces/context.d.ts +8 -0
  50. package/src/generators/lib-tags/interfaces/context.js +3 -0
  51. package/src/generators/lib-tags/interfaces/context.js.map +1 -0
  52. package/src/generators/lib-tags/interfaces/index.js +6 -0
  53. package/src/generators/lib-tags/interfaces/index.js.map +1 -0
  54. package/src/generators/lib-tags/interfaces/{verify-tag-config.ts → verify-tag-config.d.ts} +6 -7
  55. package/src/generators/lib-tags/interfaces/verify-tag-config.js +3 -0
  56. package/src/generators/lib-tags/interfaces/verify-tag-config.js.map +1 -0
  57. package/src/generators/lib-tags/types/index.js +5 -0
  58. package/src/generators/lib-tags/types/index.js.map +1 -0
  59. package/src/generators/lib-tags/types/tag.js +3 -0
  60. package/src/generators/lib-tags/types/tag.js.map +1 -0
  61. package/src/generators/lib-tags/utils/check-lib-tags.d.ts +4 -0
  62. package/src/generators/lib-tags/utils/check-lib-tags.js +113 -0
  63. package/src/generators/lib-tags/utils/check-lib-tags.js.map +1 -0
  64. package/src/generators/lib-tags/utils/index.js +5 -0
  65. package/src/generators/lib-tags/utils/index.js.map +1 -0
  66. package/src/generators/next-app/generator.d.ts +4 -0
  67. package/src/generators/next-app/generator.js +71 -0
  68. package/src/generators/next-app/generator.js.map +1 -0
  69. package/src/generators/react-component/generator.d.ts +4 -0
  70. package/src/generators/react-component/generator.js +60 -0
  71. package/src/generators/react-component/generator.js.map +1 -0
  72. package/src/generators/react-lib/generator.d.ts +4 -0
  73. package/src/generators/react-lib/generator.js +61 -0
  74. package/src/generators/react-lib/generator.js.map +1 -0
  75. package/src/generators/repo-config/generator.d.ts +3 -0
  76. package/src/generators/repo-config/generator.js +36 -0
  77. package/src/generators/repo-config/generator.js.map +1 -0
  78. package/src/generators/repo-config/scripts.d.ts +4 -0
  79. package/src/generators/repo-config/scripts.js +6 -0
  80. package/src/generators/repo-config/scripts.js.map +1 -0
  81. package/src/index.js +2 -0
  82. package/src/index.js.map +1 -0
  83. package/src/shared/dependencies.d.ts +74 -0
  84. package/src/shared/dependencies.js +80 -0
  85. package/src/shared/dependencies.js.map +1 -0
  86. package/src/shared/enums/base-generator-type.d.ts +4 -0
  87. package/src/shared/enums/base-generator-type.js +9 -0
  88. package/src/shared/enums/base-generator-type.js.map +1 -0
  89. package/src/shared/enums/index.js +5 -0
  90. package/src/shared/enums/index.js.map +1 -0
  91. package/src/shared/generators/api-client/generator.d.ts +6 -0
  92. package/src/shared/generators/api-client/generator.js +37 -0
  93. package/src/shared/generators/api-client/generator.js.map +1 -0
  94. package/src/shared/generators/api-client/index.js +5 -0
  95. package/src/shared/generators/api-client/index.js.map +1 -0
  96. package/src/shared/generators/app-env/generator.d.ts +8 -0
  97. package/src/shared/generators/app-env/generator.js +28 -0
  98. package/src/shared/generators/app-env/generator.js.map +1 -0
  99. package/src/shared/generators/app-env/index.js +5 -0
  100. package/src/shared/generators/app-env/index.js.map +1 -0
  101. package/src/shared/generators/auth/generator.d.ts +4 -0
  102. package/src/shared/generators/auth/generator.js +82 -0
  103. package/src/shared/generators/auth/generator.js.map +1 -0
  104. package/src/shared/generators/auth/index.js +5 -0
  105. package/src/shared/generators/auth/index.js.map +1 -0
  106. package/src/shared/generators/form-utils/generator.d.ts +5 -0
  107. package/src/shared/generators/form-utils/generator.js +24 -0
  108. package/src/shared/generators/form-utils/generator.js.map +1 -0
  109. package/src/shared/generators/form-utils/index.js +5 -0
  110. package/src/shared/generators/form-utils/index.js.map +1 -0
  111. package/src/shared/generators/index.js +12 -0
  112. package/src/shared/generators/index.js.map +1 -0
  113. package/src/shared/generators/rn-styles/generator.d.ts +6 -0
  114. package/src/shared/generators/rn-styles/generator.js +36 -0
  115. package/src/shared/generators/rn-styles/generator.js.map +1 -0
  116. package/src/shared/generators/rn-styles/index.js +5 -0
  117. package/src/shared/generators/rn-styles/index.js.map +1 -0
  118. package/src/shared/generators/storage/generator.d.ts +6 -0
  119. package/src/shared/generators/storage/generator.js +27 -0
  120. package/src/shared/generators/storage/generator.js.map +1 -0
  121. package/src/shared/generators/storage/index.js +5 -0
  122. package/src/shared/generators/storage/index.js.map +1 -0
  123. package/src/shared/generators/store/generator.d.ts +4 -0
  124. package/src/shared/generators/store/generator.js +36 -0
  125. package/src/shared/generators/store/generator.js.map +1 -0
  126. package/src/shared/generators/store/index.js +5 -0
  127. package/src/shared/generators/store/index.js.map +1 -0
  128. package/src/shared/generators/ui-kitten/generator.d.ts +6 -0
  129. package/src/shared/generators/ui-kitten/generator.js +40 -0
  130. package/src/shared/generators/ui-kitten/generator.js.map +1 -0
  131. package/src/shared/generators/ui-kitten/index.js +5 -0
  132. package/src/shared/generators/ui-kitten/index.js.map +1 -0
  133. package/src/shared/utils/cli-utils.d.ts +31 -0
  134. package/src/shared/utils/cli-utils.js +129 -0
  135. package/src/shared/utils/cli-utils.js.map +1 -0
  136. package/src/shared/utils/config-utils.d.ts +19 -0
  137. package/src/shared/utils/config-utils.js +124 -0
  138. package/src/shared/utils/config-utils.js.map +1 -0
  139. package/src/shared/utils/constants.d.ts +3 -0
  140. package/src/shared/utils/constants.js +7 -0
  141. package/src/shared/utils/constants.js.map +1 -0
  142. package/src/shared/utils/dynamic-import.d.ts +1 -0
  143. package/src/shared/utils/dynamic-import.js +5 -0
  144. package/src/shared/utils/dynamic-import.js.map +1 -0
  145. package/src/shared/utils/format-utils.d.ts +4 -0
  146. package/src/shared/utils/format-utils.js +18 -0
  147. package/src/shared/utils/format-utils.js.map +1 -0
  148. package/src/shared/utils/get-lib-directory-name.d.ts +1 -0
  149. package/src/shared/utils/get-lib-directory-name.js +15 -0
  150. package/src/shared/utils/get-lib-directory-name.js.map +1 -0
  151. package/src/shared/utils/index.js +11 -0
  152. package/src/shared/utils/index.js.map +1 -0
  153. package/src/shared/utils/ts-utils.d.ts +2 -0
  154. package/src/shared/utils/ts-utils.js +22 -0
  155. package/src/shared/utils/ts-utils.js.map +1 -0
  156. package/.eslintrc.json +0 -37
  157. package/jest.config.ts +0 -10
  158. package/project.json +0 -61
  159. package/src/generators/code-checks/config.ts +0 -17
  160. package/src/generators/code-checks/generator.ts +0 -68
  161. package/src/generators/code-checks/scripts.ts +0 -5
  162. package/src/generators/entity-api/generator.ts +0 -127
  163. package/src/generators/expo-app/generator.ts +0 -152
  164. package/src/generators/expo-app/scripts.ts +0 -12
  165. package/src/generators/form/generator.ts +0 -61
  166. package/src/generators/form/utils/add-form-usage.ts +0 -99
  167. package/src/generators/form/utils/get-app-name.ts +0 -3
  168. package/src/generators/form/utils/get-form-utils-directory.ts +0 -59
  169. package/src/generators/form/utils/update-index.ts +0 -15
  170. package/src/generators/lib-move/generator.ts +0 -57
  171. package/src/generators/lib-remove/generator.ts +0 -22
  172. package/src/generators/lib-rename/generator.ts +0 -25
  173. package/src/generators/lib-tags/generator.ts +0 -66
  174. package/src/generators/lib-tags/interfaces/context.ts +0 -9
  175. package/src/generators/lib-tags/utils/check-lib-tags.ts +0 -145
  176. package/src/generators/next-app/generator.ts +0 -104
  177. package/src/generators/react-component/generator.ts +0 -80
  178. package/src/generators/react-lib/generator.ts +0 -86
  179. package/src/generators/repo-config/generator.ts +0 -44
  180. package/src/generators/repo-config/scripts.ts +0 -3
  181. package/src/shared/dependencies.ts +0 -76
  182. package/src/shared/enums/base-generator-type.ts +0 -4
  183. package/src/shared/generators/api-client/generator.ts +0 -43
  184. package/src/shared/generators/app-env/generator.ts +0 -35
  185. package/src/shared/generators/auth/generator.ts +0 -100
  186. package/src/shared/generators/form-utils/generator.ts +0 -22
  187. package/src/shared/generators/rn-styles/generator.ts +0 -44
  188. package/src/shared/generators/storage/generator.ts +0 -29
  189. package/src/shared/generators/store/generator.ts +0 -42
  190. package/src/shared/generators/ui-kitten/generator.ts +0 -51
  191. package/src/shared/utils/cli-utils.ts +0 -164
  192. package/src/shared/utils/config-utils.ts +0 -159
  193. package/src/shared/utils/constants.ts +0 -3
  194. package/src/shared/utils/dynamic-import.ts +0 -3
  195. package/src/shared/utils/format-utils.ts +0 -15
  196. package/src/shared/utils/get-lib-directory-name.ts +0 -13
  197. package/src/shared/utils/ts-utils.ts +0 -20
  198. package/tsconfig.json +0 -16
  199. package/tsconfig.lib.json +0 -10
  200. package/tsconfig.spec.json +0 -9
  201. /package/src/generators/form/utils/{index.ts → index.d.ts} +0 -0
  202. /package/src/generators/lib-tags/interfaces/{index.ts → index.d.ts} +0 -0
  203. /package/src/generators/lib-tags/types/{index.ts → index.d.ts} +0 -0
  204. /package/src/generators/lib-tags/types/{tag.ts → tag.d.ts} +0 -0
  205. /package/src/generators/lib-tags/utils/{index.ts → index.d.ts} +0 -0
  206. /package/src/{index.ts → index.d.ts} +0 -0
  207. /package/src/shared/enums/{index.ts → index.d.ts} +0 -0
  208. /package/src/shared/generators/api-client/{index.ts → index.d.ts} +0 -0
  209. /package/src/shared/generators/app-env/{index.ts → index.d.ts} +0 -0
  210. /package/src/shared/generators/auth/{index.ts → index.d.ts} +0 -0
  211. /package/src/shared/generators/form-utils/{index.ts → index.d.ts} +0 -0
  212. /package/src/shared/generators/{index.ts → index.d.ts} +0 -0
  213. /package/src/shared/generators/rn-styles/{index.ts → index.d.ts} +0 -0
  214. /package/src/shared/generators/storage/{index.ts → index.d.ts} +0 -0
  215. /package/src/shared/generators/store/{index.ts → index.d.ts} +0 -0
  216. /package/src/shared/generators/ui-kitten/{index.ts → index.d.ts} +0 -0
  217. /package/src/shared/utils/{index.ts → index.d.ts} +0 -0
@@ -1,99 +0,0 @@
1
- import {
2
- ArrowFunction,
3
- FunctionDeclaration,
4
- FunctionExpression,
5
- IndentationText,
6
- Project,
7
- QuoteKind,
8
- SourceFile,
9
- SyntaxKind,
10
- VariableDeclaration,
11
- } from 'ts-morph';
12
- import { addNamedImport } from '../../../shared/utils';
13
-
14
- function getFormUsageCode(formClassName: string): string {
15
- return `const formSchema = new ${formClassName}();
16
- const form = useForm({
17
- defaultValues: formSchema.formValues,
18
- resolver: yupResolver(${formClassName}.validationSchema)
19
- });\n\n`;
20
- }
21
-
22
- function getForwardRefFunction(variable: VariableDeclaration): FunctionExpression | ArrowFunction {
23
- const callExpressionInitializer = variable.getInitializerIfKind(SyntaxKind.CallExpression);
24
- const hasForwardRef = callExpressionInitializer?.getExpression().getText() === 'forwardRef';
25
-
26
- if (!hasForwardRef) {
27
- throw new Error('Could not find forwardRef');
28
- }
29
-
30
- const argument = callExpressionInitializer.getArguments()[0];
31
- const hasComponentFunction =
32
- argument && [SyntaxKind.FunctionExpression, SyntaxKind.ArrowFunction].includes(argument.getKind());
33
-
34
- if (!hasComponentFunction) {
35
- throw new Error('Could not find a component function in forwardRef');
36
- }
37
-
38
- const functionExpression = argument.asKind(
39
- argument.getKind() === SyntaxKind.FunctionExpression ? SyntaxKind.FunctionExpression : SyntaxKind.ArrowFunction,
40
- );
41
-
42
- if (!functionExpression) {
43
- throw new Error('Could not get a component function in forwardRef');
44
- }
45
-
46
- return functionExpression;
47
- }
48
-
49
- function getPlaceOfUse(
50
- file: SourceFile,
51
- placeOfUseName: string,
52
- ): FunctionExpression | ArrowFunction | FunctionDeclaration {
53
- const placeOfUseFunction = file.getFunction(placeOfUseName);
54
-
55
- if (placeOfUseFunction) {
56
- return placeOfUseFunction;
57
- }
58
-
59
- const variable = file.getVariableDeclaration(placeOfUseName);
60
-
61
- if (!variable) {
62
- throw new Error(`Could not find the place where the form should be used (${placeOfUseName}).`);
63
- }
64
-
65
- return (
66
- variable.getInitializerIfKind(SyntaxKind.FunctionExpression) ||
67
- variable.getInitializerIfKind(SyntaxKind.ArrowFunction) ||
68
- getForwardRefFunction(variable)
69
- );
70
- }
71
-
72
- export async function addFormUsage(libPath: string, placeOfUseName: string, formClassName: string): Promise<void> {
73
- const project = new Project({
74
- manipulationSettings: {
75
- indentationText: IndentationText.TwoSpaces,
76
- quoteKind: QuoteKind.Single,
77
- },
78
- });
79
- const files = project.addSourceFilesAtPaths([`${libPath}/lib/**/*.tsx`, `${libPath}/lib/**/*.ts`]);
80
- const file = files.find((file) => file.getFunction(placeOfUseName) || file.getVariableDeclaration(placeOfUseName));
81
-
82
- if (!file) {
83
- throw new Error('Could not find the place where the form should be used.');
84
- }
85
-
86
- const pathToForm = file.getFilePath().includes('components')
87
- ? '../../forms'
88
- : file.getFilePath().includes('hooks')
89
- ? '../forms'
90
- : './forms';
91
- addNamedImport(formClassName, pathToForm, file);
92
- addNamedImport('useForm', 'react-hook-form', file);
93
- addNamedImport('yupResolver', '@hookform/resolvers/yup', file);
94
-
95
- const placeOfUse = getPlaceOfUse(file, placeOfUseName);
96
- placeOfUse.setBodyText(`${getFormUsageCode(formClassName)}${placeOfUse.getBodyText()}`);
97
-
98
- project.saveSync();
99
- }
@@ -1,3 +0,0 @@
1
- export function getAppName(path: string): string {
2
- return path.split('/')[1];
3
- }
@@ -1,59 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- import { runFormUtilsGenerator } from '../../../shared/generators';
3
- import {
4
- constants,
5
- dynamicImport,
6
- filterSource,
7
- getNxLibsPaths,
8
- LibraryType,
9
- searchAliasPath,
10
- searchNxLibsPaths,
11
- selectProject,
12
- } from '../../../shared/utils';
13
- import { getAppName } from './get-app-name';
14
-
15
- function getFormUtilsPaths(): Array<string> {
16
- const utilsLibsPaths = getNxLibsPaths([LibraryType.UTILS]);
17
-
18
- return searchNxLibsPaths(utilsLibsPaths, 'utils/form/src', 'endsWith');
19
- }
20
-
21
- export async function getFormUtilsDirectory(tree: Tree, appName: string): Promise<string> {
22
- const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>(
23
- 'inquirer-autocomplete-standalone',
24
- );
25
-
26
- const formUtilsLibsPaths = getFormUtilsPaths();
27
-
28
- if (!formUtilsLibsPaths.length) {
29
- const formUtilsAppDirectory = (
30
- await selectProject(
31
- tree,
32
- 'application',
33
- 'It\'s necessary to generate form utilities. What application should they be in?',
34
- )
35
- ).name;
36
- await runFormUtilsGenerator(tree, { directory: formUtilsAppDirectory });
37
-
38
- return searchAliasPath(getFormUtilsPaths()[0]) as string;
39
- }
40
-
41
- if (formUtilsLibsPaths.length > 1) {
42
- if (appName === constants.sharedValue) {
43
- const path = formUtilsLibsPaths.find((path) => getAppName(path) === constants.sharedValue) as string;
44
-
45
- return searchAliasPath(path) as string;
46
- }
47
-
48
- formUtilsLibsPaths[0] = await autocomplete({
49
- message: 'Select the path of the library with the form utilities: ',
50
- source: (input) =>
51
- filterSource(
52
- input as string,
53
- formUtilsLibsPaths.filter((path) => [appName, constants.sharedValue].includes(getAppName(path))),
54
- ),
55
- });
56
- }
57
-
58
- return searchAliasPath(formUtilsLibsPaths[0]) as string;
59
- }
@@ -1,15 +0,0 @@
1
- import { existsSync } from 'fs';
2
- import { Tree } from '@nx/devkit';
3
- import { kebabCase } from 'lodash';
4
- import { appendFileContent } from '../../../shared/utils';
5
-
6
- export function updateIndex(formsPath: string, fileName: string, tree: Tree): void {
7
- const formsIndexFilePath = `${formsPath}/index.ts`;
8
- const newIndexContent = `export * from './${kebabCase(fileName)}';\n`;
9
-
10
- if (!existsSync(formsIndexFilePath)) {
11
- tree.write(formsIndexFilePath, newIndexContent);
12
- } else {
13
- appendFileContent(formsIndexFilePath, newIndexContent, tree);
14
- }
15
- }
@@ -1,57 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import * as path from 'path';
3
- import { Tree } from '@nx/devkit';
4
- import {
5
- LibraryType,
6
- askQuestion,
7
- constants,
8
- dynamicImport,
9
- filterSource,
10
- getLibraryDetailsByName,
11
- selectProject,
12
- validateLibraryType,
13
- getLibDirectoryName,
14
- } from '../../shared/utils';
15
- import { LibMoveGeneratorSchema } from './schema';
16
-
17
- export async function libMoveGenerator(tree: Tree, options: LibMoveGeneratorSchema) {
18
- const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>(
19
- 'inquirer-autocomplete-standalone',
20
- );
21
-
22
- const { name: srcLibraryName, path: srcLibraryPath } = await getLibraryDetailsByName(tree, options.srcLibName);
23
-
24
- const libPathSegments = srcLibraryPath.split('/');
25
- const defaultLibraryName = libPathSegments.pop();
26
-
27
- options.app = options.app || (await selectProject(tree, 'application', 'Select the application: ')).name;
28
-
29
- const isSharedLib = options.app === constants.sharedValue;
30
-
31
- options.scope =
32
- options.scope ||
33
- (isSharedLib ? '' : await askQuestion(`Enter the scope (e.g: profile) or '${constants.sharedValue}': `));
34
- options.type = options.type
35
- ? validateLibraryType(options.type)
36
- : await autocomplete({
37
- message: 'Select the library type: ',
38
- source: (input) => filterSource(input as string, Object.values(LibraryType)),
39
- });
40
-
41
- const libraryName =
42
- options.name ||
43
- (await askQuestion(
44
- 'If you want to rename the library, enter its new name. Otherwise just press Enter: ',
45
- defaultLibraryName,
46
- ));
47
- const libDirectoryName = getLibDirectoryName(libraryName, options.scope);
48
- const libPath = `libs/${path.normalize(`${options.app}/${options.scope}/${options.type}/${libDirectoryName}`)}`;
49
-
50
- execSync(`npx nx g mv --project=${srcLibraryName} --destination=${libPath}`, { stdio: 'inherit' });
51
-
52
- return (): void => {
53
- execSync('npx nx g lib-tags --skipRepoCheck', { stdio: 'inherit' });
54
- };
55
- }
56
-
57
- export default libMoveGenerator;
@@ -1,22 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import { Tree } from '@nx/devkit';
3
- import { askQuestion, selectProject } from '../../shared/utils';
4
- import { LibRemoveGeneratorSchema } from './schema';
5
-
6
- export async function libRemoveGenerator(tree: Tree, options: LibRemoveGeneratorSchema): Promise<void> {
7
- const libraryName = options.libName || (await selectProject(tree, 'library', 'Select the library to remove: ')).name;
8
-
9
- if (!libraryName) {
10
- throw new Error('No library found!');
11
- }
12
-
13
- const isConfirmed = await askQuestion(`Are you sure you want to remove ${libraryName} (y/n)?`);
14
-
15
- if (!isConfirmed) {
16
- return;
17
- }
18
-
19
- execSync(`npx nx g rm --project=${libraryName}`, { stdio: 'inherit' });
20
- }
21
-
22
- export default libRemoveGenerator;
@@ -1,25 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import { Tree } from '@nx/devkit';
3
- import { askQuestion, getLibraryDetailsByName } from '../../shared/utils';
4
- import { LibRenameGeneratorSchema } from './schema';
5
-
6
- export async function libRenameGenerator(tree: Tree, options: LibRenameGeneratorSchema): Promise<void> {
7
- const { name: currentLibraryName, path: currentLibraryPath } = await getLibraryDetailsByName(
8
- tree,
9
- options.currentLibName,
10
- );
11
-
12
- const libPathSegments = currentLibraryPath.split('/');
13
- const defaultDestLibraryName = libPathSegments.pop();
14
- const destLibraryName =
15
- options.newLibName || (await askQuestion('Enter a new library name: ', defaultDestLibraryName));
16
-
17
- // Remove `libs` path fragment
18
- libPathSegments.shift();
19
- libPathSegments.push(destLibraryName);
20
-
21
- const destLibraryPath = `libs/${libPathSegments.join('/')}`;
22
- execSync(`npx nx g mv --project=${currentLibraryName} --destination=${destLibraryPath}`, { stdio: 'inherit' });
23
- }
24
-
25
- export default libRenameGenerator;
@@ -1,66 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import { Tree, getProjects, ProjectConfiguration, formatFiles, output } from '@nx/devkit';
3
- import { noop } from 'lodash';
4
- import { askQuestion, getNxRules, readESLintConfig, verifyEsLintConfig } from '../../shared/utils';
5
- import { LibTagsContext } from './interfaces';
6
- import { LibTagsGeneratorSchema } from './schema';
7
- import { checkApplicationTags, checkLibraryTags } from './utils';
8
-
9
- const context: LibTagsContext = {
10
- config: {},
11
- rules: [],
12
- log: console.log,
13
- reload: (tree: Tree) => {
14
- context.config = readESLintConfig(tree).config;
15
- context.rules = getNxRules(context.config);
16
- },
17
- };
18
-
19
- export async function libTagsGenerator(tree: Tree, options: LibTagsGeneratorSchema): Promise<void> {
20
- const hasUnstagedChanges = !options.skipRepoCheck && execSync('git status -s').toString('utf8');
21
-
22
- if (hasUnstagedChanges) {
23
- const shouldContinue =
24
- (await askQuestion('You have unstaged changes. Are you sure you want to continue? (y/n): ')) === 'y';
25
-
26
- if (!shouldContinue) {
27
- return;
28
- }
29
- }
30
-
31
- if (options.silent) {
32
- context.log = noop;
33
- }
34
-
35
- // #1 Check eslint config nx-boundaries rule
36
- output.log({ title: output.bold('1. Checking eslint config nx-boundaries rule...') });
37
- context.config = verifyEsLintConfig(tree);
38
-
39
- // #2 Check projects tags
40
- output.log({ title: output.bold('2. Checking projects tags...') });
41
- const projects = getProjects(tree);
42
- const applications: Array<ProjectConfiguration> = [];
43
- const libraries: Array<ProjectConfiguration> = [];
44
-
45
- context.rules = getNxRules(context.config);
46
-
47
- projects.forEach((project) => {
48
- if (project.projectType === 'application') {
49
- applications.push(project);
50
- }
51
-
52
- if (project.projectType === 'library' && project.root.startsWith('libs')) {
53
- libraries.push(project);
54
- }
55
- });
56
-
57
- applications.forEach((application) => checkApplicationTags(application, tree, context));
58
-
59
- context.reload(tree);
60
-
61
- libraries.forEach((library) => checkLibraryTags(library, tree, context));
62
-
63
- await formatFiles(tree);
64
- }
65
-
66
- export default libTagsGenerator;
@@ -1,9 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- import { Constraint } from '../../../shared/utils';
3
-
4
- export interface LibTagsContext {
5
- config: Record<string, any>;
6
- rules: Array<Constraint>;
7
- log: (message: any, ...optionalParams: Array<any>) => void;
8
- reload: (tree: Tree) => void;
9
- }
@@ -1,145 +0,0 @@
1
- import { ProjectConfiguration, Tree, readProjectConfiguration, updateProjectConfiguration } from '@nx/devkit';
2
- import { addNxAppTag, addNxScopeTag, constants } from '../../../shared/utils';
3
- import { LibTagsContext, VerifyTagConfig } from '../interfaces';
4
- import { TagType } from '../types';
5
-
6
- const getTagFromLibPath = (libPath: string, type: TagType): string => {
7
- const projectAppTag = libPath.split('/')[1];
8
-
9
- switch (type) {
10
- case 'app':
11
- return projectAppTag;
12
- case 'scope':
13
- return projectAppTag === constants.sharedValue ? constants.sharedValue : libPath.split('/')[2];
14
- case 'type':
15
- return projectAppTag === constants.sharedValue ? libPath.split('/')[2] : libPath.split('/')[3];
16
- }
17
- };
18
-
19
- const verifyLibraryTag = ({ project, tree, tag, tagType, context, ruleNotFoundCallback }: VerifyTagConfig): void => {
20
- const defaultRuleNotFoundCallback = (): void => {
21
- throw new Error(`Missing ${tagType} tag rule for ${tag}. Please add it to the ESLint config file.`);
22
- };
23
-
24
- if (tag) {
25
- const tagRule = context.rules.find((rule) => rule.sourceTag === tag);
26
-
27
- if (!tagRule) {
28
- const callback = ruleNotFoundCallback || defaultRuleNotFoundCallback;
29
-
30
- callback();
31
- }
32
-
33
- const tagFromLibPath = getTagFromLibPath(project.root, tagType);
34
- const isInvalidTag = tag !== `${tagType}:${tagFromLibPath}`;
35
-
36
- if (isInvalidTag) {
37
- context.log(`Invalid tag ${tag}. Updating...\n`);
38
-
39
- project = readProjectConfiguration(tree, project.name as string);
40
-
41
- const filteredTags = project.tags?.filter((item) => item !== tag) || [];
42
-
43
- project.tags = [...filteredTags, `${tagType}:${tagFromLibPath}`];
44
-
45
- updateProjectConfiguration(tree, project.name as string, project);
46
-
47
- if (tagType === 'scope') {
48
- addNxScopeTag(tree, tagFromLibPath);
49
- context.reload(tree);
50
- }
51
-
52
- verifyLibraryTag({
53
- project,
54
- tree,
55
- tag: `${tagType}:${tagFromLibPath}`,
56
- tagType,
57
- context,
58
- });
59
- }
60
- } else {
61
- context.log(`Missing ${tagType} tag for ${project.name}. Adding...`);
62
-
63
- project = readProjectConfiguration(tree, project.name as string);
64
-
65
- const tag = getTagFromLibPath(project.root, tagType);
66
-
67
- if (tagType === 'type') {
68
- const typeTagRule = context.rules.find((rule) => rule.sourceTag === `type:${tag}`);
69
-
70
- if (!typeTagRule) {
71
- throw new Error(`Missing type tag rule for ${tag}. Please add it to the ESLint config file.`);
72
- }
73
- }
74
-
75
- updateProjectConfiguration(tree, project.name as string, {
76
- ...project,
77
- tags: [...(project.tags || []), `${tagType}:${tag}`],
78
- });
79
-
80
- if (tagType === 'scope') {
81
- addNxScopeTag(tree, tag);
82
- context.reload(tree);
83
- }
84
- }
85
- };
86
-
87
- export const checkApplicationTags = (project: ProjectConfiguration, tree: Tree, context: LibTagsContext): void => {
88
- const { tags } = project;
89
- const appTag = tags?.find((tag) => tag.startsWith('app:'));
90
- const hasTypeTag = tags?.includes('type:app');
91
-
92
- if (appTag) {
93
- const appTagRule = context.rules.find((rule) => rule.sourceTag === appTag);
94
-
95
- if (!appTagRule) {
96
- context.log(`Missing app tag rule for ${appTag}. Adding...\n`);
97
- addNxAppTag(tree, appTag.replace('app:', ''));
98
- context.reload(tree);
99
- }
100
- } else {
101
- context.log(`Missing app tag for ${project.name}. Adding...`);
102
-
103
- const projectAppTag = project.root.split('/').pop() as string;
104
-
105
- updateProjectConfiguration(tree, project.name as string, {
106
- ...project,
107
- tags: [...(project.tags || []), `app:${projectAppTag}`],
108
- });
109
- addNxAppTag(tree, projectAppTag);
110
- context.reload(tree);
111
- }
112
-
113
- if (!hasTypeTag) {
114
- context.log(`Missing type tag for ${project.name}. Adding...`);
115
-
116
- project = readProjectConfiguration(tree, project.name as string);
117
-
118
- updateProjectConfiguration(tree, project.name as string, {
119
- ...project,
120
- tags: [...(project.tags || []), 'type:app'],
121
- });
122
- }
123
- };
124
-
125
- export const checkLibraryTags = (project: ProjectConfiguration, tree: Tree, context: LibTagsContext): void => {
126
- const { tags } = project;
127
- const appTag = tags?.find((tag) => tag.startsWith('app:'));
128
- const scopeTag = tags?.find((tag) => tag.startsWith('scope:'));
129
- const typeTag = tags?.find((tag) => tag.startsWith('type:'));
130
-
131
- verifyLibraryTag({ project, tree, tag: appTag, tagType: 'app', context });
132
- verifyLibraryTag({
133
- project,
134
- tree,
135
- tag: scopeTag,
136
- tagType: 'scope',
137
- context,
138
- ruleNotFoundCallback: () => {
139
- context.log(`Missing scope tag rule for ${scopeTag}. Adding...`);
140
- addNxScopeTag(tree, scopeTag?.replace('scope:', '') as string);
141
- context.reload(tree);
142
- },
143
- });
144
- verifyLibraryTag({ project, tree, tag: typeTag, tagType: 'type', context });
145
- };
@@ -1,104 +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
- installPackagesTask,
9
- readJson,
10
- Tree,
11
- writeJson,
12
- } from '@nx/devkit';
13
- import { dependencies } from '../../shared/dependencies';
14
- import { BaseGeneratorType } from '../../shared/enums';
15
- import {
16
- runApiClientGenerator,
17
- runAppEnvGenerator,
18
- runFormUtilsGenerator,
19
- runStoreGenerator,
20
- } from '../../shared/generators';
21
- import { addNxAppTag, askQuestion, formatName } from '../../shared/utils';
22
- import { NextAppGeneratorSchema } from './schema';
23
-
24
- export async function nextAppGenerator(tree: Tree, options: NextAppGeneratorSchema) {
25
- const shouldGenerateStoreLib = (await askQuestion('Do you want to create store lib? (y/n): ')) === 'y';
26
- const shouldGenerateApiClientLib =
27
- shouldGenerateStoreLib && (await askQuestion('Do you want to create api client lib? (y/n): ')) === 'y';
28
- const shouldGenerateFormUtilsLib =
29
- (await askQuestion('Do you want to create a lib with the form utils? (y/n): ')) === 'y';
30
-
31
- const appRoot = `apps/${options.directory}`;
32
- const tags = [`app:${options.directory}`, 'type:app'];
33
-
34
- // Install @nx/next plugin
35
- execSync('npx nx add @nx/next', { stdio: 'inherit' });
36
-
37
- if (!existsSync(appRoot)) {
38
- execSync(
39
- `npx nx g @nx/next:app ${options.name} --directory=apps/${options.directory} --tags="${tags.join(', ')}" --linter=eslint --appDir=true --style=scss --src=false --unitTestRunner=none --e2eTestRunner=none`,
40
- { stdio: 'inherit' },
41
- );
42
- }
43
-
44
- // Install @nx/expo to generate libs
45
- const packageJson = readJson(tree, 'package.json');
46
- const hasNxExpo = !!packageJson.devDependencies['@nx/expo'];
47
-
48
- if (!hasNxExpo) {
49
- execSync('npx nx add @nx/expo', { stdio: 'inherit' });
50
- }
51
-
52
- await runAppEnvGenerator(tree, { ...options, baseGeneratorType: BaseGeneratorType.NEXT_APP });
53
-
54
- if (shouldGenerateStoreLib) {
55
- await runStoreGenerator(tree, { ...options, baseGeneratorType: BaseGeneratorType.NEXT_APP });
56
- }
57
-
58
- if (shouldGenerateApiClientLib) {
59
- await runApiClientGenerator(tree, options);
60
- }
61
-
62
- if (shouldGenerateFormUtilsLib) {
63
- await runFormUtilsGenerator(tree, options);
64
- }
65
-
66
- // Remove unnecessary files and files that will be replaced
67
- tree.delete(`${appRoot}/public/.gitkeep`);
68
- tree.delete(`${appRoot}/app/api`);
69
- tree.delete(`${appRoot}/app/page.tsx`);
70
- tree.delete(`${appRoot}/app/page.module.scss`);
71
- tree.delete(`${appRoot}/app/global.css`);
72
- tree.delete(`${appRoot}/app/layout.tsx`);
73
- tree.delete(`${appRoot}/specs`);
74
- tree.delete(`${appRoot}/.eslintrc.json`);
75
-
76
- // Update app tsconfig.json to skip automatic reconfiguration during the first application run
77
- const appTsconfigPath = `${appRoot}/tsconfig.json`;
78
- const appTsconfigJson = readJson(tree, appTsconfigPath);
79
- const nextTypesInclude = '.next/types/**/*.ts';
80
-
81
- if (!appTsconfigJson.include.includes(nextTypesInclude)) {
82
- appTsconfigJson.include.push(nextTypesInclude);
83
- writeJson(tree, appTsconfigPath, appTsconfigJson);
84
- }
85
-
86
- // Add app files
87
- generateFiles(tree, path.join(__dirname, 'files'), appRoot, {
88
- ...options,
89
- formatName,
90
- });
91
-
92
- addNxAppTag(tree, options.directory);
93
-
94
- // Add dependencies
95
- addDependenciesToPackageJson(tree, dependencies['next-app'], {});
96
-
97
- await formatFiles(tree);
98
-
99
- return (): void => {
100
- installPackagesTask(tree);
101
- };
102
- }
103
-
104
- export default nextAppGenerator;