@ronas-it/nx-generators 0.10.1 → 0.10.3

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 (216) hide show
  1. package/.eslintrc.json +37 -0
  2. package/jest.config.ts +10 -0
  3. package/package.json +2 -2
  4. package/project.json +61 -0
  5. package/src/generators/code-checks/config.ts +17 -0
  6. package/src/generators/code-checks/generator.ts +72 -0
  7. package/src/generators/code-checks/scripts.ts +5 -0
  8. package/src/generators/entity-api/generator.ts +127 -0
  9. package/src/generators/expo-app/app-files/app.config.ts.template +1 -0
  10. package/src/generators/expo-app/generator.ts +152 -0
  11. package/src/generators/expo-app/scripts.ts +12 -0
  12. package/src/generators/form/generator.ts +53 -0
  13. package/src/generators/form/utils/add-form-usage.ts +86 -0
  14. package/src/generators/form/utils/get-app-name.ts +3 -0
  15. package/src/generators/form/utils/get-form-utils-directory.ts +46 -0
  16. package/src/generators/form/utils/update-index.ts +14 -0
  17. package/src/generators/lib-move/generator.ts +57 -0
  18. package/src/generators/lib-remove/generator.ts +25 -0
  19. package/src/generators/lib-rename/generator.ts +25 -0
  20. package/src/generators/lib-tags/generator.ts +68 -0
  21. package/src/generators/lib-tags/interfaces/context.ts +9 -0
  22. package/src/generators/lib-tags/interfaces/index.ts +2 -0
  23. package/src/generators/lib-tags/interfaces/verify-tag-config.ts +12 -0
  24. package/src/generators/lib-tags/types/index.ts +1 -0
  25. package/src/generators/lib-tags/types/tag.ts +1 -0
  26. package/src/generators/lib-tags/utils/check-lib-tags.ts +143 -0
  27. package/src/generators/next-app/generator.ts +99 -0
  28. package/src/generators/react-component/generator.ts +80 -0
  29. package/src/generators/react-lib/generator.ts +86 -0
  30. package/src/generators/repo-config/generator.ts +44 -0
  31. package/src/generators/repo-config/scripts.ts +3 -0
  32. package/src/shared/dependencies.ts +76 -0
  33. package/src/shared/enums/base-generator-type.ts +4 -0
  34. package/src/shared/generators/api-client/generator.ts +49 -0
  35. package/src/shared/generators/app-env/generator.ts +37 -0
  36. package/src/shared/generators/app-env/lib-files/shared/utils/app-env/src/app-env.ts.template +1 -1
  37. package/src/shared/generators/auth/generator.ts +107 -0
  38. package/src/shared/generators/form-utils/generator.ts +23 -0
  39. package/src/shared/generators/rn-styles/generator.ts +49 -0
  40. package/src/shared/generators/storage/generator.ts +34 -0
  41. package/src/shared/generators/store/generator.ts +48 -0
  42. package/src/shared/generators/store/schema.d.ts +1 -1
  43. package/src/shared/generators/ui-kitten/generator.ts +55 -0
  44. package/src/shared/utils/cli-utils.ts +149 -0
  45. package/src/shared/utils/config-utils.ts +146 -0
  46. package/src/shared/utils/constants.ts +3 -0
  47. package/src/shared/utils/dynamic-import.ts +4 -0
  48. package/src/shared/utils/format-utils.ts +16 -0
  49. package/src/shared/utils/get-lib-directory-name.ts +12 -0
  50. package/src/shared/utils/ts-utils.ts +17 -0
  51. package/tsconfig.json +16 -0
  52. package/tsconfig.lib.json +10 -0
  53. package/tsconfig.spec.json +14 -0
  54. package/src/generators/code-checks/config.d.ts +0 -18
  55. package/src/generators/code-checks/config.js +0 -20
  56. package/src/generators/code-checks/config.js.map +0 -1
  57. package/src/generators/code-checks/generator.d.ts +0 -4
  58. package/src/generators/code-checks/generator.js +0 -53
  59. package/src/generators/code-checks/generator.js.map +0 -1
  60. package/src/generators/code-checks/scripts.d.ts +0 -6
  61. package/src/generators/code-checks/scripts.js +0 -8
  62. package/src/generators/code-checks/scripts.js.map +0 -1
  63. package/src/generators/entity-api/generator.d.ts +0 -4
  64. package/src/generators/entity-api/generator.js +0 -84
  65. package/src/generators/entity-api/generator.js.map +0 -1
  66. package/src/generators/expo-app/app-files/.env.development.template +0 -1
  67. package/src/generators/expo-app/generator.d.ts +0 -4
  68. package/src/generators/expo-app/generator.js +0 -93
  69. package/src/generators/expo-app/generator.js.map +0 -1
  70. package/src/generators/expo-app/scripts.d.ts +0 -13
  71. package/src/generators/expo-app/scripts.js +0 -15
  72. package/src/generators/expo-app/scripts.js.map +0 -1
  73. package/src/generators/form/generator.d.ts +0 -4
  74. package/src/generators/form/generator.js +0 -48
  75. package/src/generators/form/generator.js.map +0 -1
  76. package/src/generators/form/utils/add-form-usage.d.ts +0 -1
  77. package/src/generators/form/utils/add-form-usage.js +0 -67
  78. package/src/generators/form/utils/add-form-usage.js.map +0 -1
  79. package/src/generators/form/utils/get-app-name.d.ts +0 -1
  80. package/src/generators/form/utils/get-app-name.js +0 -8
  81. package/src/generators/form/utils/get-app-name.js.map +0 -1
  82. package/src/generators/form/utils/get-form-utils-directory.d.ts +0 -2
  83. package/src/generators/form/utils/get-form-utils-directory.js +0 -34
  84. package/src/generators/form/utils/get-form-utils-directory.js.map +0 -1
  85. package/src/generators/form/utils/index.js +0 -8
  86. package/src/generators/form/utils/index.js.map +0 -1
  87. package/src/generators/form/utils/update-index.d.ts +0 -2
  88. package/src/generators/form/utils/update-index.js +0 -18
  89. package/src/generators/form/utils/update-index.js.map +0 -1
  90. package/src/generators/lib-move/generator.d.ts +0 -4
  91. package/src/generators/lib-move/generator.js +0 -34
  92. package/src/generators/lib-move/generator.js.map +0 -1
  93. package/src/generators/lib-remove/generator.d.ts +0 -4
  94. package/src/generators/lib-remove/generator.js +0 -22
  95. package/src/generators/lib-remove/generator.js.map +0 -1
  96. package/src/generators/lib-rename/generator.d.ts +0 -4
  97. package/src/generators/lib-rename/generator.js +0 -24
  98. package/src/generators/lib-rename/generator.js.map +0 -1
  99. package/src/generators/lib-tags/generator.d.ts +0 -4
  100. package/src/generators/lib-tags/generator.js +0 -56
  101. package/src/generators/lib-tags/generator.js.map +0 -1
  102. package/src/generators/lib-tags/interfaces/context.d.ts +0 -8
  103. package/src/generators/lib-tags/interfaces/context.js +0 -3
  104. package/src/generators/lib-tags/interfaces/context.js.map +0 -1
  105. package/src/generators/lib-tags/interfaces/index.d.ts +0 -1
  106. package/src/generators/lib-tags/interfaces/index.js +0 -5
  107. package/src/generators/lib-tags/interfaces/index.js.map +0 -1
  108. package/src/generators/lib-tags/utils/check-lib-tags.d.ts +0 -4
  109. package/src/generators/lib-tags/utils/check-lib-tags.js +0 -99
  110. package/src/generators/lib-tags/utils/check-lib-tags.js.map +0 -1
  111. package/src/generators/lib-tags/utils/index.js +0 -5
  112. package/src/generators/lib-tags/utils/index.js.map +0 -1
  113. package/src/generators/next-app/generator.d.ts +0 -4
  114. package/src/generators/next-app/generator.js +0 -71
  115. package/src/generators/next-app/generator.js.map +0 -1
  116. package/src/generators/react-component/generator.d.ts +0 -4
  117. package/src/generators/react-component/generator.js +0 -55
  118. package/src/generators/react-component/generator.js.map +0 -1
  119. package/src/generators/react-lib/generator.d.ts +0 -4
  120. package/src/generators/react-lib/generator.js +0 -49
  121. package/src/generators/react-lib/generator.js.map +0 -1
  122. package/src/generators/repo-config/generator.d.ts +0 -3
  123. package/src/generators/repo-config/generator.js +0 -36
  124. package/src/generators/repo-config/generator.js.map +0 -1
  125. package/src/generators/repo-config/scripts.d.ts +0 -4
  126. package/src/generators/repo-config/scripts.js +0 -6
  127. package/src/generators/repo-config/scripts.js.map +0 -1
  128. package/src/index.js +0 -1
  129. package/src/index.js.map +0 -1
  130. package/src/shared/dependencies.d.ts +0 -73
  131. package/src/shared/dependencies.js +0 -79
  132. package/src/shared/dependencies.js.map +0 -1
  133. package/src/shared/enums/base-generator-type.d.ts +0 -4
  134. package/src/shared/enums/base-generator-type.js +0 -9
  135. package/src/shared/enums/base-generator-type.js.map +0 -1
  136. package/src/shared/enums/index.js +0 -5
  137. package/src/shared/enums/index.js.map +0 -1
  138. package/src/shared/generators/api-client/generator.d.ts +0 -6
  139. package/src/shared/generators/api-client/generator.js +0 -35
  140. package/src/shared/generators/api-client/generator.js.map +0 -1
  141. package/src/shared/generators/api-client/index.js +0 -5
  142. package/src/shared/generators/api-client/index.js.map +0 -1
  143. package/src/shared/generators/app-env/generator.d.ts +0 -6
  144. package/src/shared/generators/app-env/generator.js +0 -25
  145. package/src/shared/generators/app-env/generator.js.map +0 -1
  146. package/src/shared/generators/app-env/index.js +0 -5
  147. package/src/shared/generators/app-env/index.js.map +0 -1
  148. package/src/shared/generators/auth/generator.d.ts +0 -4
  149. package/src/shared/generators/auth/generator.js +0 -74
  150. package/src/shared/generators/auth/generator.js.map +0 -1
  151. package/src/shared/generators/auth/index.js +0 -5
  152. package/src/shared/generators/auth/index.js.map +0 -1
  153. package/src/shared/generators/form-utils/generator.d.ts +0 -5
  154. package/src/shared/generators/form-utils/generator.js +0 -22
  155. package/src/shared/generators/form-utils/generator.js.map +0 -1
  156. package/src/shared/generators/form-utils/index.js +0 -5
  157. package/src/shared/generators/form-utils/index.js.map +0 -1
  158. package/src/shared/generators/index.js +0 -12
  159. package/src/shared/generators/index.js.map +0 -1
  160. package/src/shared/generators/rn-styles/generator.d.ts +0 -6
  161. package/src/shared/generators/rn-styles/generator.js +0 -36
  162. package/src/shared/generators/rn-styles/generator.js.map +0 -1
  163. package/src/shared/generators/rn-styles/index.js +0 -5
  164. package/src/shared/generators/rn-styles/index.js.map +0 -1
  165. package/src/shared/generators/storage/generator.d.ts +0 -6
  166. package/src/shared/generators/storage/generator.js +0 -25
  167. package/src/shared/generators/storage/generator.js.map +0 -1
  168. package/src/shared/generators/storage/index.js +0 -5
  169. package/src/shared/generators/storage/index.js.map +0 -1
  170. package/src/shared/generators/store/generator.d.ts +0 -4
  171. package/src/shared/generators/store/generator.js +0 -34
  172. package/src/shared/generators/store/generator.js.map +0 -1
  173. package/src/shared/generators/store/index.js +0 -5
  174. package/src/shared/generators/store/index.js.map +0 -1
  175. package/src/shared/generators/ui-kitten/generator.d.ts +0 -6
  176. package/src/shared/generators/ui-kitten/generator.js +0 -40
  177. package/src/shared/generators/ui-kitten/generator.js.map +0 -1
  178. package/src/shared/generators/ui-kitten/index.js +0 -5
  179. package/src/shared/generators/ui-kitten/index.js.map +0 -1
  180. package/src/shared/utils/cli-utils.d.ts +0 -28
  181. package/src/shared/utils/cli-utils.js +0 -125
  182. package/src/shared/utils/cli-utils.js.map +0 -1
  183. package/src/shared/utils/config-utils.d.ts +0 -19
  184. package/src/shared/utils/config-utils.js +0 -115
  185. package/src/shared/utils/config-utils.js.map +0 -1
  186. package/src/shared/utils/constants.d.ts +0 -3
  187. package/src/shared/utils/constants.js +0 -7
  188. package/src/shared/utils/constants.js.map +0 -1
  189. package/src/shared/utils/dynamic-import.d.ts +0 -1
  190. package/src/shared/utils/dynamic-import.js +0 -5
  191. package/src/shared/utils/dynamic-import.js.map +0 -1
  192. package/src/shared/utils/format-utils.d.ts +0 -4
  193. package/src/shared/utils/format-utils.js +0 -18
  194. package/src/shared/utils/format-utils.js.map +0 -1
  195. package/src/shared/utils/get-lib-directory-name.d.ts +0 -1
  196. package/src/shared/utils/get-lib-directory-name.js +0 -15
  197. package/src/shared/utils/get-lib-directory-name.js.map +0 -1
  198. package/src/shared/utils/index.js +0 -11
  199. package/src/shared/utils/index.js.map +0 -1
  200. package/src/shared/utils/ts-utils.d.ts +0 -2
  201. package/src/shared/utils/ts-utils.js +0 -21
  202. package/src/shared/utils/ts-utils.js.map +0 -1
  203. /package/src/generators/form/utils/{index.d.ts → index.ts} +0 -0
  204. /package/src/generators/lib-tags/utils/{index.d.ts → index.ts} +0 -0
  205. /package/src/{index.d.ts → index.ts} +0 -0
  206. /package/src/shared/enums/{index.d.ts → index.ts} +0 -0
  207. /package/src/shared/generators/api-client/{index.d.ts → index.ts} +0 -0
  208. /package/src/shared/generators/app-env/{index.d.ts → index.ts} +0 -0
  209. /package/src/shared/generators/auth/{index.d.ts → index.ts} +0 -0
  210. /package/src/shared/generators/form-utils/{index.d.ts → index.ts} +0 -0
  211. /package/src/shared/generators/{index.d.ts → index.ts} +0 -0
  212. /package/src/shared/generators/rn-styles/{index.d.ts → index.ts} +0 -0
  213. /package/src/shared/generators/storage/{index.d.ts → index.ts} +0 -0
  214. /package/src/shared/generators/store/{index.d.ts → index.ts} +0 -0
  215. /package/src/shared/generators/ui-kitten/{index.d.ts → index.ts} +0 -0
  216. /package/src/shared/utils/{index.d.ts → index.ts} +0 -0
@@ -0,0 +1,46 @@
1
+ import {
2
+ constants,
3
+ dynamicImport,
4
+ filterSource,
5
+ getNxLibsPaths,
6
+ LibraryType,
7
+ searchAliasPath,
8
+ searchNxLibsPaths,
9
+ selectProject
10
+ } from '../../../shared/utils';
11
+ import { runFormUtilsGenerator } from '../../../shared/generators';
12
+ import { Tree } from '@nx/devkit';
13
+ import { getAppName } from './get-app-name';
14
+
15
+ function getFormUtilsPaths(): Array<string> {
16
+ const utilsLibsPaths = getNxLibsPaths([LibraryType.UTILS]);
17
+ return searchNxLibsPaths(utilsLibsPaths, 'utils/form/src', 'endsWith');
18
+ }
19
+
20
+ export async function getFormUtilsDirectory(tree: Tree, appName: string): Promise<string> {
21
+ const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>('inquirer-autocomplete-standalone');
22
+
23
+ const formUtilsLibsPaths = getFormUtilsPaths();
24
+
25
+ if (!formUtilsLibsPaths.length) {
26
+ const formUtilsAppDirectory = (await selectProject(tree, 'application', 'It\'s necessary to generate form utilities. What application should they be in?')).name;
27
+ await runFormUtilsGenerator(tree, { directory: formUtilsAppDirectory });
28
+
29
+ return searchAliasPath(getFormUtilsPaths()[0]) as string;
30
+ }
31
+
32
+ if (formUtilsLibsPaths.length > 1) {
33
+ if (appName === constants.sharedValue) {
34
+ const path = formUtilsLibsPaths.find((path) => getAppName(path) === constants.sharedValue) as string;
35
+
36
+ return searchAliasPath(path) as string;
37
+ }
38
+
39
+ formUtilsLibsPaths[0] = await autocomplete({
40
+ message: 'Select the path of the library with the form utilities: ',
41
+ source: (input) => filterSource(input as string, formUtilsLibsPaths.filter((path) => [appName, constants.sharedValue].includes(getAppName(path))))
42
+ });
43
+ }
44
+
45
+ return searchAliasPath(formUtilsLibsPaths[0]) as string;
46
+ }
@@ -0,0 +1,14 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { kebabCase } from 'lodash';
3
+ import { existsSync } from 'fs';
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
+ if (!existsSync(formsIndexFilePath)) {
10
+ tree.write(formsIndexFilePath, newIndexContent);
11
+ } else {
12
+ appendFileContent(formsIndexFilePath, newIndexContent, tree);
13
+ }
14
+ }
@@ -0,0 +1,57 @@
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 () => {
53
+ execSync('npx nx g lib-tags --skipRepoCheck', { stdio: 'inherit' });
54
+ };
55
+ }
56
+
57
+ export default libMoveGenerator;
@@ -0,0 +1,25 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { LibRemoveGeneratorSchema } from './schema';
3
+ import { askQuestion, selectProject } from '../../shared/utils';
4
+ import { execSync } from 'child_process';
5
+
6
+ export async function libRemoveGenerator(
7
+ tree: Tree,
8
+ options: LibRemoveGeneratorSchema
9
+ ) {
10
+ const libraryName = options.libName || (await selectProject(tree, 'library', 'Select the library to remove: ')).name;
11
+
12
+ if (!libraryName) {
13
+ throw new Error('No library found!');
14
+ }
15
+
16
+ const isConfirmed = await askQuestion(`Are you sure you want to remove ${libraryName} (y/n)?`);
17
+
18
+ if (!isConfirmed) {
19
+ return;
20
+ }
21
+
22
+ execSync(`npx nx g rm --project=${libraryName}`, { stdio: 'inherit' });
23
+ }
24
+
25
+ export default libRemoveGenerator;
@@ -0,0 +1,25 @@
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) {
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;
@@ -0,0 +1,68 @@
1
+ import { Tree, getProjects, ProjectConfiguration, formatFiles, output } from '@nx/devkit';
2
+ import { LibTagsGeneratorSchema } from './schema';
3
+ import { execSync } from 'child_process';
4
+ import { askQuestion, getNxRules, readESLintConfig, verifyEsLintConfig } from '../../shared/utils';
5
+ import { noop } from 'lodash';
6
+ import { checkApplicationTags, checkLibraryTags } from './utils';
7
+ import { LibTagsContext } from './interfaces';
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(
20
+ tree: Tree,
21
+ options: LibTagsGeneratorSchema,
22
+ ) {
23
+ const hasUnstagedChanges = !options.skipRepoCheck && execSync('git status -s').toString('utf8');
24
+
25
+ if (hasUnstagedChanges) {
26
+ const shouldContinue = await askQuestion('You have unstaged changes. Are you sure you want to continue? (y/n): ') === 'y';
27
+
28
+ if (!shouldContinue) {
29
+ return;
30
+ }
31
+ }
32
+
33
+ if (options.silent) {
34
+ context.log = noop;
35
+ }
36
+
37
+ // #1 Check eslint config nx-boundaries rule
38
+ output.log({ title: output.bold('1. Checking eslint config nx-boundaries rule...') });
39
+ context.config = verifyEsLintConfig(tree);
40
+
41
+ // #2 Check projects tags
42
+ output.log({ title: output.bold('2. Checking projects tags...') });
43
+ const projects = getProjects(tree);
44
+ const applications: Array<ProjectConfiguration> = [];
45
+ const libraries: Array<ProjectConfiguration> = [];
46
+
47
+ context.rules = getNxRules(context.config);
48
+
49
+ projects.forEach((project) => {
50
+ if (project.projectType === 'application') {
51
+ applications.push(project);
52
+ }
53
+
54
+ if (project.projectType === 'library' && project.root.startsWith('libs')) {
55
+ libraries.push(project);
56
+ }
57
+ });
58
+
59
+ applications.forEach((application) => checkApplicationTags(application, tree, context));
60
+
61
+ context.reload(tree);
62
+
63
+ libraries.forEach((library) => checkLibraryTags(library, tree, context));
64
+
65
+ await formatFiles(tree);
66
+ }
67
+
68
+ export default libTagsGenerator;
@@ -0,0 +1,9 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ export * from './context';
2
+ export * from './verify-tag-config';
@@ -0,0 +1,12 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ import { TagType } from '../types';
3
+ import { LibTagsContext } from './context';
4
+
5
+ export interface VerifyTagConfig {
6
+ project: ProjectConfiguration,
7
+ tree: Tree,
8
+ tag?: string,
9
+ tagType: TagType,
10
+ context: LibTagsContext,
11
+ ruleNotFoundCallback?: () => void
12
+ }
@@ -0,0 +1 @@
1
+ export * from './tag';
@@ -0,0 +1 @@
1
+ export type TagType = 'app' | 'scope' | 'type';
@@ -0,0 +1,143 @@
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 = ({
20
+ project,
21
+ tree,
22
+ tag,
23
+ tagType,
24
+ context,
25
+ ruleNotFoundCallback
26
+ }: VerifyTagConfig): void => {
27
+ const defaultRuleNotFoundCallback = (): void => {
28
+ throw new Error(`Missing ${tagType} tag rule for ${tag}. Please add it to the ESLint config file.`);
29
+ };
30
+
31
+ if (tag) {
32
+ const tagRule = context.rules.find((rule) => rule.sourceTag === tag);
33
+
34
+ if (!tagRule) {
35
+ const callback = ruleNotFoundCallback || defaultRuleNotFoundCallback;
36
+
37
+ callback();
38
+ }
39
+
40
+ const tagFromLibPath = getTagFromLibPath(project.root, tagType);
41
+ const isInvalidTag = tag !== `${tagType}:${tagFromLibPath}`;
42
+
43
+ if (isInvalidTag) {
44
+ context.log(`Invalid tag ${tag}. Updating...\n`);
45
+
46
+ project = readProjectConfiguration(tree, project.name as string);
47
+
48
+ const filteredTags = project.tags?.filter((item) => item !== tag) || [];
49
+
50
+ project.tags = [...filteredTags, `${tagType}:${tagFromLibPath}`];
51
+
52
+ updateProjectConfiguration(tree, project.name as string, project);
53
+
54
+ if (tagType === 'scope') {
55
+ addNxScopeTag(tree, tagFromLibPath);
56
+ context.reload(tree);
57
+ }
58
+
59
+ verifyLibraryTag({
60
+ project,
61
+ tree,
62
+ tag:`${tagType}:${tagFromLibPath}`,
63
+ tagType,
64
+ context
65
+ });
66
+ }
67
+ } else {
68
+ context.log(`Missing ${tagType} tag for ${project.name}. Adding...`);
69
+
70
+ project = readProjectConfiguration(tree, project.name as string);
71
+
72
+ const tag = getTagFromLibPath(project.root, tagType);
73
+
74
+ if (tagType === 'type') {
75
+ const typeTagRule = context.rules.find((rule) => rule.sourceTag === `type:${tag}`);
76
+
77
+ if (!typeTagRule) {
78
+ throw new Error(`Missing type tag rule for ${tag}. Please add it to the ESLint config file.`);
79
+ }
80
+ }
81
+
82
+ updateProjectConfiguration(tree, project.name as string, { ...project, tags: [...(project.tags || []), `${tagType}:${tag}`] });
83
+
84
+ if (tagType === 'scope') {
85
+ addNxScopeTag(tree, tag);
86
+ context.reload(tree);
87
+ }
88
+ }
89
+ };
90
+
91
+ export const checkApplicationTags = (project: ProjectConfiguration, tree: Tree, context: LibTagsContext): void => {
92
+ const { tags } = project;
93
+ const appTag = tags?.find((tag) => tag.startsWith('app:'));
94
+ const hasTypeTag = tags?.includes('type:app');
95
+
96
+ if (appTag) {
97
+ const appTagRule = context.rules.find((rule) => rule.sourceTag === appTag);
98
+
99
+ if (!appTagRule) {
100
+ context.log(`Missing app tag rule for ${appTag}. Adding...\n`);
101
+ addNxAppTag(tree, appTag.replace('app:', ''));
102
+ context.reload(tree);
103
+ }
104
+ } else {
105
+ context.log(`Missing app tag for ${project.name}. Adding...`);
106
+
107
+ const projectAppTag = project.root.split('/').pop() as string;
108
+
109
+ updateProjectConfiguration(tree, project.name as string, { ...project, tags: [...(project.tags || []), `app:${projectAppTag}`] });
110
+ addNxAppTag(tree, projectAppTag);
111
+ context.reload(tree);
112
+ }
113
+
114
+ if (!hasTypeTag) {
115
+ context.log(`Missing type tag for ${project.name}. Adding...`);
116
+
117
+ project = readProjectConfiguration(tree, project.name as string);
118
+
119
+ updateProjectConfiguration(tree, project.name as string, { ...project, tags: [...(project.tags || []), 'type:app'] });
120
+ }
121
+ };
122
+
123
+ export const checkLibraryTags = (project: ProjectConfiguration, tree: Tree, context: LibTagsContext): void => {
124
+ const { tags } = project;
125
+ const appTag = tags?.find((tag) => tag.startsWith('app:'));
126
+ const scopeTag = tags?.find((tag) => tag.startsWith('scope:'));
127
+ const typeTag = tags?.find((tag) => tag.startsWith('type:'));
128
+
129
+ verifyLibraryTag({ project, tree, tag: appTag, tagType: 'app', context });
130
+ verifyLibraryTag({
131
+ project,
132
+ tree,
133
+ tag: scopeTag,
134
+ tagType:'scope',
135
+ context,
136
+ ruleNotFoundCallback:() => {
137
+ context.log(`Missing scope tag rule for ${scopeTag}. Adding...`);
138
+ addNxScopeTag(tree, scopeTag?.replace('scope:', '') as string);
139
+ context.reload(tree);
140
+ }
141
+ });
142
+ verifyLibraryTag({ project, tree, tag: typeTag, tagType: 'type', context });
143
+ };
@@ -0,0 +1,99 @@
1
+ import { execSync } from 'child_process';
2
+ import {
3
+ addDependenciesToPackageJson,
4
+ formatFiles,
5
+ generateFiles,
6
+ installPackagesTask,
7
+ readJson,
8
+ Tree,
9
+ writeJson,
10
+ } from '@nx/devkit';
11
+ import { NextAppGeneratorSchema } from './schema';
12
+ import { existsSync } from 'fs';
13
+ import { dependencies } from '../../shared/dependencies';
14
+ import { BaseGeneratorType } from '../../shared/enums';
15
+ import { runApiClientGenerator, runAppEnvGenerator, runFormUtilsGenerator, runStoreGenerator } from '../../shared/generators';
16
+ import { addNxAppTag, askQuestion, formatName } from '../../shared/utils';
17
+ import * as path from 'path';
18
+
19
+ export async function nextAppGenerator(
20
+ tree: Tree,
21
+ options: NextAppGeneratorSchema,
22
+ ) {
23
+ const shouldGenerateStoreLib = await askQuestion('Do you want to create store lib? (y/n): ') === 'y';
24
+ const shouldGenerateApiClientLib = shouldGenerateStoreLib && await askQuestion('Do you want to create api client lib? (y/n): ') === 'y';
25
+ const shouldGenerateFormUtilsLib = await askQuestion('Do you want to create a lib with the form utils? (y/n): ') === 'y';
26
+
27
+ const appRoot = `apps/${options.directory}`;
28
+ const tags = [`app:${options.directory}`, 'type:app'];
29
+
30
+ // Install @nx/next plugin
31
+ execSync('npx nx add @nx/next', { stdio: 'inherit' });
32
+
33
+ if (!existsSync(appRoot)) {
34
+ execSync(
35
+ `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`,
36
+ { stdio: 'inherit' },
37
+ );
38
+ }
39
+
40
+ // Install @nx/expo to generate libs
41
+ const packageJson = readJson(tree, 'package.json');
42
+ const hasNxExpo = !!packageJson.devDependencies['@nx/expo'];
43
+ if (!hasNxExpo) {
44
+ execSync('npx nx add @nx/expo', { stdio: 'inherit' });
45
+ }
46
+
47
+ await runAppEnvGenerator(tree, { ...options, baseGeneratorType: BaseGeneratorType.NEXT_APP });
48
+
49
+ if (shouldGenerateStoreLib) {
50
+ await runStoreGenerator(tree, { ...options, baseGeneratorType: BaseGeneratorType.NEXT_APP });
51
+ }
52
+
53
+ if (shouldGenerateApiClientLib) {
54
+ await runApiClientGenerator(tree, options);
55
+ }
56
+
57
+ if (shouldGenerateFormUtilsLib) {
58
+ await runFormUtilsGenerator(tree, options);
59
+ }
60
+
61
+ // Remove unnecessary files and files that will be replaced
62
+ tree.delete(`${appRoot}/public/.gitkeep`);
63
+ tree.delete(`${appRoot}/app/api`);
64
+ tree.delete(`${appRoot}/app/page.tsx`);
65
+ tree.delete(`${appRoot}/app/page.module.scss`);
66
+ tree.delete(`${appRoot}/app/global.css`);
67
+ tree.delete(`${appRoot}/app/layout.tsx`);
68
+ tree.delete(`${appRoot}/specs`);
69
+ tree.delete(`${appRoot}/.eslintrc.json`);
70
+
71
+ // Update app tsconfig.json to skip automatic reconfiguration during the first application run
72
+ const appTsconfigPath = `${appRoot}/tsconfig.json`;
73
+ const appTsconfigJson = readJson(tree, appTsconfigPath);
74
+ const nextTypesInclude = '.next/types/**/*.ts';
75
+
76
+ if (!appTsconfigJson.include.includes(nextTypesInclude)) {
77
+ appTsconfigJson.include.push(nextTypesInclude);
78
+ writeJson(tree, appTsconfigPath, appTsconfigJson);
79
+ }
80
+
81
+ // Add app files
82
+ generateFiles(tree, path.join(__dirname, 'files'), appRoot, {
83
+ ...options,
84
+ formatName,
85
+ });
86
+
87
+ addNxAppTag(tree, options.directory);
88
+
89
+ // Add dependencies
90
+ addDependenciesToPackageJson(tree, dependencies['next-app'], {});
91
+
92
+ await formatFiles(tree);
93
+
94
+ return () => {
95
+ installPackagesTask(tree);
96
+ };
97
+ }
98
+
99
+ export default nextAppGenerator;
@@ -0,0 +1,80 @@
1
+ import { existsSync } from 'fs';
2
+ import * as path from 'path';
3
+ import { formatFiles, generateFiles, Tree } from '@nx/devkit';
4
+ import { kebabCase } from 'lodash';
5
+ import {
6
+ appendFileContent,
7
+ askQuestion,
8
+ createCliReadline,
9
+ dynamicImport,
10
+ formatName,
11
+ getNxLibsPaths,
12
+ LibraryType,
13
+ searchNxLibsPaths
14
+ } from '../../shared/utils';
15
+ import { ReactComponentGeneratorSchema } from './schema';
16
+
17
+ export async function reactComponentGenerator(tree: Tree, options: ReactComponentGeneratorSchema) {
18
+ const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>(
19
+ 'inquirer-autocomplete-standalone',
20
+ );
21
+
22
+ const nxLibsPaths = getNxLibsPaths([LibraryType.FEATURES, LibraryType.UI]);
23
+
24
+ const libPath = await autocomplete({
25
+ message: 'Enter the library path:',
26
+ source: async (input) => {
27
+ const filteredNxLibsPaths = searchNxLibsPaths(nxLibsPaths, input as string);
28
+
29
+ return filteredNxLibsPaths.map((path) => ({ value: path }));
30
+ }
31
+ });
32
+
33
+ const cliReadline = createCliReadline();
34
+ options.name =
35
+ options.name || (await askQuestion('Enter the name of the component (e.g: AppButton): ', undefined, cliReadline));
36
+ options.subcomponent =
37
+ options.subcomponent ||
38
+ (await askQuestion('Generate component inside components folder? (y/n): ', undefined, cliReadline)) === 'y';
39
+ options.withForwardRef =
40
+ options.withForwardRef ||
41
+ (await askQuestion('Generate component with forwardRef? (y/n): ', undefined, cliReadline)) === 'y';
42
+ cliReadline.close();
43
+
44
+ const libRootPath = `${libPath}/lib`;
45
+ const componentsPath = `${libRootPath}/components`;
46
+ const componentPath = options.subcomponent ? `${libRootPath}/components/${kebabCase(options.name)}` : libRootPath;
47
+ const shouldUpdateSrcIndex = !existsSync(libRootPath);
48
+ const shouldUpdateLibIndex = !existsSync(componentsPath) && options.subcomponent;
49
+
50
+ generateFiles(tree, path.join(__dirname, `files`), componentPath, {
51
+ ...options,
52
+ name: formatName(options.name, true)
53
+ });
54
+
55
+ const updateIndexes = (): void => {
56
+ const componentsIndexFilePath = `${libRootPath}/components/index.ts`;
57
+
58
+ if (shouldUpdateSrcIndex) {
59
+ appendFileContent(`${libPath}/index.ts`, `export * from './lib';\n`, tree);
60
+ }
61
+
62
+ if (shouldUpdateLibIndex) {
63
+ appendFileContent(`${libRootPath}/index.ts`, `export * from './components';\n`, tree);
64
+ }
65
+
66
+ if (!existsSync(componentsIndexFilePath)) {
67
+ tree.write(componentsIndexFilePath, `export * from './${kebabCase(options.name)}';\n`);
68
+ } else {
69
+ appendFileContent(componentsIndexFilePath, `export * from './${kebabCase(options.name)}';\n`, tree);
70
+ }
71
+ };
72
+
73
+ if (options.subcomponent) {
74
+ updateIndexes();
75
+ }
76
+
77
+ await formatFiles(tree);
78
+ }
79
+
80
+ export default reactComponentGenerator;
@@ -0,0 +1,86 @@
1
+ import { execSync } from 'child_process';
2
+ import * as path from 'path';
3
+ import { formatFiles, generateFiles, output, Tree } from '@nx/devkit';
4
+ import { isBoolean } from 'lodash';
5
+ import {
6
+ addNxScopeTag,
7
+ askQuestion,
8
+ constants,
9
+ dynamicImport,
10
+ filterSource,
11
+ formatName,
12
+ LibraryType,
13
+ selectProject,
14
+ validateLibraryType,
15
+ getLibDirectoryName,
16
+ createCliReadline
17
+ } from '../../shared/utils';
18
+ import { ReactLibGeneratorSchema } from './schema';
19
+
20
+ export async function reactLibGenerator(tree: Tree, options: ReactLibGeneratorSchema) {
21
+ const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>(
22
+ 'inquirer-autocomplete-standalone',
23
+ );
24
+
25
+ options.app = options.app || (await selectProject(tree, 'application', 'Select the application: ')).name;
26
+
27
+ const isSharedLib = options.app === constants.sharedValue;
28
+
29
+ options.scope =
30
+ options.scope ||
31
+ (isSharedLib ? '' : await askQuestion(`Enter the scope (e.g: profile) or '${constants.sharedValue}': `));
32
+ options.type = options.type
33
+ ? validateLibraryType(options.type)
34
+ : await autocomplete({
35
+ message: 'Select the library type: ',
36
+ source: (input) => filterSource(input as string, Object.values(LibraryType))
37
+ });
38
+
39
+ const cliReadline = createCliReadline();
40
+ options.name =
41
+ options.name || (await askQuestion('Enter the name of the library (e.g: settings): ', undefined, cliReadline));
42
+
43
+ if (
44
+ [LibraryType.FEATURES, LibraryType.UI].includes(options.type as LibraryType) &&
45
+ !isBoolean(options.withComponent)
46
+ ) {
47
+ options.withComponent =
48
+ (await askQuestion('Generate component inside lib folder? (y/n): ', undefined, cliReadline)) === 'y';
49
+
50
+ if (options.withComponent && !isBoolean(options.withComponentForwardRef)) {
51
+ options.withComponentForwardRef =
52
+ (await askQuestion('Generate component with forwardRef? (y/n): ', undefined, cliReadline)) === 'y';
53
+ }
54
+ }
55
+ cliReadline.close();
56
+
57
+ const scopeTag = options.scope || constants.sharedValue;
58
+ const tags = [`app:${options.app}`, `scope:${scopeTag}`, `type:${options.type}`];
59
+
60
+ const libDirectoryName = getLibDirectoryName(options.name, options.scope);
61
+ const libName = path.normalize(`${options.app}/${options.scope}/${options.type}/${libDirectoryName}`);
62
+ const libPath = `libs/${libName}`;
63
+ const command = `npx nx g @nx/expo:lib --skipPackageJson --unitTestRunner=none --tags="${tags.join(', ')}" --name=${libName} ${libPath} --linter=eslint`;
64
+ const commandWithOptions = options.dryRun ? command + ' --dry-run' : command;
65
+
66
+ execSync(commandWithOptions, { stdio: 'inherit' });
67
+
68
+ if (options.withComponent) {
69
+ const srcPath = `${libPath}/src`;
70
+
71
+ generateFiles(tree, path.join(__dirname, 'files'), srcPath, { ...options, name: formatName(options.name, true) });
72
+ tree.write(`${srcPath}/index.ts`, 'export * from \'./lib\';');
73
+ }
74
+
75
+ addNxScopeTag(tree, scopeTag);
76
+
77
+ await formatFiles(tree);
78
+
79
+ if (libDirectoryName !== options.name) {
80
+ output.warn({
81
+ title: `The library directory was changed to ${output.bold(libDirectoryName)} so that it does not start with the scope name.`
82
+ });
83
+ }
84
+ }
85
+
86
+ export default reactLibGenerator;