@ronas-it/nx-generators 0.10.3 → 0.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/package.json +1 -1
- package/src/generators/code-checks/files/.eslintrc.json.template +173 -1
- package/src/generators/code-checks/generator.ts +2 -6
- package/src/generators/code-checks/scripts.ts +4 -4
- package/src/generators/entity-api/generator.ts +9 -9
- package/src/generators/expo-app/generator.ts +20 -20
- package/src/generators/expo-app/scripts.ts +1 -1
- package/src/generators/form/generator.ts +17 -9
- package/src/generators/form/utils/add-form-usage.ts +24 -11
- package/src/generators/form/utils/get-form-utils-directory.ts +19 -6
- package/src/generators/form/utils/update-index.ts +2 -1
- package/src/generators/lib-move/generator.ts +5 -5
- package/src/generators/lib-remove/generator.ts +3 -6
- package/src/generators/lib-rename/generator.ts +1 -1
- package/src/generators/lib-tags/generator.ts +8 -10
- package/src/generators/lib-tags/interfaces/verify-tag-config.ts +6 -6
- package/src/generators/lib-tags/utils/check-lib-tags.ts +21 -19
- package/src/generators/next-app/generator.ts +17 -12
- package/src/generators/react-component/generator.ts +4 -4
- package/src/generators/react-lib/generator.ts +6 -6
- package/src/generators/repo-config/generator.ts +2 -2
- package/src/shared/dependencies.ts +20 -20
- package/src/shared/enums/base-generator-type.ts +1 -1
- package/src/shared/generators/api-client/generator.ts +6 -12
- package/src/shared/generators/app-env/generator.ts +7 -9
- package/src/shared/generators/auth/generator.ts +25 -32
- package/src/shared/generators/form-utils/generator.ts +4 -5
- package/src/shared/generators/rn-styles/generator.ts +8 -13
- package/src/shared/generators/storage/generator.ts +6 -11
- package/src/shared/generators/store/generator.ts +6 -12
- package/src/shared/generators/ui-kitten/generator.ts +10 -14
- package/src/shared/templates/config-template.json +2 -12
- package/src/shared/utils/cli-utils.ts +37 -22
- package/src/shared/utils/config-utils.ts +26 -13
- package/src/shared/utils/constants.ts +1 -1
- package/src/shared/utils/dynamic-import.ts +3 -4
- package/src/shared/utils/format-utils.ts +4 -5
- package/src/shared/utils/get-lib-directory-name.ts +1 -0
- package/src/shared/utils/ts-utils.ts +7 -4
- package/tsconfig.spec.json +1 -6
package/README.md
CHANGED
|
@@ -85,7 +85,9 @@ Generates and configures an Expo React Native app.
|
|
|
85
85
|
```sh
|
|
86
86
|
npx nx g expo-app --name=my-app --directory=mobile
|
|
87
87
|
```
|
|
88
|
+
|
|
88
89
|
or
|
|
90
|
+
|
|
89
91
|
```sh
|
|
90
92
|
npx nx g expo-app my-app mobile
|
|
91
93
|
```
|
|
@@ -105,7 +107,9 @@ Generates and configures a Next.js app.
|
|
|
105
107
|
```sh
|
|
106
108
|
npx nx g next-app --name=my-app --directory=web
|
|
107
109
|
```
|
|
110
|
+
|
|
108
111
|
or
|
|
112
|
+
|
|
109
113
|
```sh
|
|
110
114
|
npx nx g next-app my-app web
|
|
111
115
|
```
|
|
@@ -141,7 +145,9 @@ Generates a library according to [NX notation](https://nx.dev/concepts/more-conc
|
|
|
141
145
|
```sh
|
|
142
146
|
npx nx g react-lib --app=mobile --scope=account --type=features --name=profile-settings --withComponent --withComponentForwardRef --dryRun
|
|
143
147
|
```
|
|
148
|
+
|
|
144
149
|
or
|
|
150
|
+
|
|
145
151
|
```sh
|
|
146
152
|
npx nx g react-lib --dryRun
|
|
147
153
|
```
|
|
@@ -235,7 +241,9 @@ Creates a React component in particular library.
|
|
|
235
241
|
```sh
|
|
236
242
|
npx nx g react-component --name=AppButton --subcomponent --withForwardRef
|
|
237
243
|
```
|
|
244
|
+
|
|
238
245
|
or
|
|
246
|
+
|
|
239
247
|
```sh
|
|
240
248
|
npx nx g react-component AppButton --subcomponent --withForwardRef
|
|
241
249
|
```
|
|
@@ -256,7 +264,9 @@ Generates a form schema class and adds its usage to a component or a hook.
|
|
|
256
264
|
```sh
|
|
257
265
|
npx nx g form --name=profile-settings --placeOfUse=ProfileSettings
|
|
258
266
|
```
|
|
267
|
+
|
|
259
268
|
or
|
|
269
|
+
|
|
260
270
|
```sh
|
|
261
271
|
npx nx g form profile-settings ProfileSettings
|
|
262
272
|
```
|
|
@@ -286,4 +296,3 @@ Each generator accepts the `--help` argument to see generator instructions.
|
|
|
286
296
|
```sh
|
|
287
297
|
npx nx g react-lib --help
|
|
288
298
|
```
|
|
289
|
-
|
package/package.json
CHANGED
|
@@ -2,5 +2,177 @@
|
|
|
2
2
|
"root": true,
|
|
3
3
|
"plugins": ["@nx"],
|
|
4
4
|
"extends": ["./.eslint.ronasit.json"],
|
|
5
|
-
"overrides": [
|
|
5
|
+
"overrides": [
|
|
6
|
+
{
|
|
7
|
+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
8
|
+
"rules": {
|
|
9
|
+
"@stylistic/array-bracket-newline": "off",
|
|
10
|
+
"@stylistic/array-bracket-spacing": "off",
|
|
11
|
+
"@stylistic/array-element-newline": "off",
|
|
12
|
+
"@stylistic/arrow-parens": "off",
|
|
13
|
+
"@stylistic/arrow-spacing": "off",
|
|
14
|
+
"@stylistic/block-spacing": "off",
|
|
15
|
+
"@stylistic/brace-style": "off",
|
|
16
|
+
"@stylistic/comma-dangle": "off",
|
|
17
|
+
"@stylistic/comma-spacing": "off",
|
|
18
|
+
"@stylistic/comma-style": "off",
|
|
19
|
+
"@stylistic/computed-property-spacing": "off",
|
|
20
|
+
"@stylistic/dot-location": "off",
|
|
21
|
+
"@stylistic/eol-last": "off",
|
|
22
|
+
"@stylistic/func-call-spacing": "off",
|
|
23
|
+
"@stylistic/function-call-argument-newline": "off",
|
|
24
|
+
"@stylistic/function-call-spacing": "off",
|
|
25
|
+
"@stylistic/function-paren-newline": "off",
|
|
26
|
+
"@stylistic/generator-star-spacing": "off",
|
|
27
|
+
"@stylistic/implicit-arrow-linebreak": "off",
|
|
28
|
+
"@stylistic/indent": "off",
|
|
29
|
+
"@stylistic/jsx-quotes": "off",
|
|
30
|
+
"@stylistic/key-spacing": "off",
|
|
31
|
+
"@stylistic/keyword-spacing": "off",
|
|
32
|
+
"@stylistic/linebreak-style": "off",
|
|
33
|
+
"@stylistic/max-statements-per-line": "off",
|
|
34
|
+
"@stylistic/multiline-ternary": "off",
|
|
35
|
+
"@stylistic/new-parens": "off",
|
|
36
|
+
"@stylistic/newline-per-chained-call": "off",
|
|
37
|
+
"@stylistic/no-extra-parens": "off",
|
|
38
|
+
"@stylistic/no-extra-semi": "off",
|
|
39
|
+
"@stylistic/no-floating-decimal": "off",
|
|
40
|
+
"@stylistic/no-mixed-spaces-and-tabs": "off",
|
|
41
|
+
"@stylistic/no-multi-spaces": "off",
|
|
42
|
+
"@stylistic/no-multiple-empty-lines": "off",
|
|
43
|
+
"@stylistic/no-trailing-spaces": "off",
|
|
44
|
+
"@stylistic/no-whitespace-before-property": "off",
|
|
45
|
+
"@stylistic/nonblock-statement-body-position": "off",
|
|
46
|
+
"@stylistic/object-curly-newline": "off",
|
|
47
|
+
"@stylistic/object-curly-spacing": "off",
|
|
48
|
+
"@stylistic/object-property-newline": "off",
|
|
49
|
+
"@stylistic/one-var-declaration-per-line": "off",
|
|
50
|
+
"@stylistic/operator-linebreak": "off",
|
|
51
|
+
"@stylistic/padded-blocks": "off",
|
|
52
|
+
"@stylistic/quote-props": "off",
|
|
53
|
+
"@stylistic/rest-spread-spacing": "off",
|
|
54
|
+
"@stylistic/semi": "off",
|
|
55
|
+
"@stylistic/semi-spacing": "off",
|
|
56
|
+
"@stylistic/semi-style": "off",
|
|
57
|
+
"@stylistic/space-before-blocks": "off",
|
|
58
|
+
"@stylistic/space-before-function-paren": "off",
|
|
59
|
+
"@stylistic/space-in-parens": "off",
|
|
60
|
+
"@stylistic/space-infix-ops": "off",
|
|
61
|
+
"@stylistic/space-unary-ops": "off",
|
|
62
|
+
"@stylistic/switch-colon-spacing": "off",
|
|
63
|
+
"@stylistic/template-curly-spacing": "off",
|
|
64
|
+
"@stylistic/template-tag-spacing": "off",
|
|
65
|
+
"@stylistic/wrap-iife": "off",
|
|
66
|
+
"@stylistic/wrap-regex": "off",
|
|
67
|
+
"@stylistic/yield-star-spacing": "off",
|
|
68
|
+
"@stylistic/member-delimiter-style": "off",
|
|
69
|
+
"@stylistic/type-annotation-spacing": "off",
|
|
70
|
+
"@stylistic/jsx-child-element-spacing": "off",
|
|
71
|
+
"@stylistic/jsx-closing-bracket-location": "off",
|
|
72
|
+
"@stylistic/jsx-closing-tag-location": "off",
|
|
73
|
+
"@stylistic/jsx-curly-newline": "off",
|
|
74
|
+
"@stylistic/jsx-curly-spacing": "off",
|
|
75
|
+
"@stylistic/jsx-equals-spacing": "off",
|
|
76
|
+
"@stylistic/jsx-first-prop-new-line": "off",
|
|
77
|
+
"@stylistic/jsx-indent": "off",
|
|
78
|
+
"@stylistic/jsx-indent-props": "off",
|
|
79
|
+
"@stylistic/jsx-max-props-per-line": "off",
|
|
80
|
+
"@stylistic/jsx-newline": "off",
|
|
81
|
+
"@stylistic/jsx-one-expression-per-line": "off",
|
|
82
|
+
"@stylistic/jsx-props-no-multi-spaces": "off",
|
|
83
|
+
"@stylistic/jsx-tag-spacing": "off",
|
|
84
|
+
"@stylistic/jsx-wrap-multilines": "off",
|
|
85
|
+
"@stylistic/indent-binary-ops": "off",
|
|
86
|
+
"@stylistic/type-generic-spacing": "off",
|
|
87
|
+
"@stylistic/type-named-tuple-spacing": "off",
|
|
88
|
+
"@stylistic/js/array-bracket-newline": "off",
|
|
89
|
+
"@stylistic/js/array-bracket-spacing": "off",
|
|
90
|
+
"@stylistic/js/array-element-newline": "off",
|
|
91
|
+
"@stylistic/js/arrow-parens": "off",
|
|
92
|
+
"@stylistic/js/arrow-spacing": "off",
|
|
93
|
+
"@stylistic/js/block-spacing": "off",
|
|
94
|
+
"@stylistic/js/brace-style": "off",
|
|
95
|
+
"@stylistic/js/comma-dangle": "off",
|
|
96
|
+
"@stylistic/js/comma-spacing": "off",
|
|
97
|
+
"@stylistic/js/comma-style": "off",
|
|
98
|
+
"@stylistic/js/computed-property-spacing": "off",
|
|
99
|
+
"@stylistic/js/dot-location": "off",
|
|
100
|
+
"@stylistic/js/eol-last": "off",
|
|
101
|
+
"@stylistic/js/func-call-spacing": "off",
|
|
102
|
+
"@stylistic/js/function-call-argument-newline": "off",
|
|
103
|
+
"@stylistic/js/function-call-spacing": "off",
|
|
104
|
+
"@stylistic/js/function-paren-newline": "off",
|
|
105
|
+
"@stylistic/js/generator-star-spacing": "off",
|
|
106
|
+
"@stylistic/js/implicit-arrow-linebreak": "off",
|
|
107
|
+
"@stylistic/js/indent": "off",
|
|
108
|
+
"@stylistic/js/jsx-quotes": "off",
|
|
109
|
+
"@stylistic/js/key-spacing": "off",
|
|
110
|
+
"@stylistic/js/keyword-spacing": "off",
|
|
111
|
+
"@stylistic/js/linebreak-style": "off",
|
|
112
|
+
"@stylistic/js/max-statements-per-line": "off",
|
|
113
|
+
"@stylistic/js/multiline-ternary": "off",
|
|
114
|
+
"@stylistic/js/new-parens": "off",
|
|
115
|
+
"@stylistic/js/newline-per-chained-call": "off",
|
|
116
|
+
"@stylistic/js/no-extra-parens": "off",
|
|
117
|
+
"@stylistic/js/no-extra-semi": "off",
|
|
118
|
+
"@stylistic/js/no-floating-decimal": "off",
|
|
119
|
+
"@stylistic/js/no-mixed-spaces-and-tabs": "off",
|
|
120
|
+
"@stylistic/js/no-multi-spaces": "off",
|
|
121
|
+
"@stylistic/js/no-multiple-empty-lines": "off",
|
|
122
|
+
"@stylistic/js/no-trailing-spaces": "off",
|
|
123
|
+
"@stylistic/js/no-whitespace-before-property": "off",
|
|
124
|
+
"@stylistic/js/nonblock-statement-body-position": "off",
|
|
125
|
+
"@stylistic/js/object-curly-newline": "off",
|
|
126
|
+
"@stylistic/js/object-curly-spacing": "off",
|
|
127
|
+
"@stylistic/js/object-property-newline": "off",
|
|
128
|
+
"@stylistic/js/one-var-declaration-per-line": "off",
|
|
129
|
+
"@stylistic/js/operator-linebreak": "off",
|
|
130
|
+
"@stylistic/js/padded-blocks": "off",
|
|
131
|
+
"@stylistic/js/quote-props": "off",
|
|
132
|
+
"@stylistic/js/rest-spread-spacing": "off",
|
|
133
|
+
"@stylistic/js/semi": "off",
|
|
134
|
+
"@stylistic/js/semi-spacing": "off",
|
|
135
|
+
"@stylistic/js/semi-style": "off",
|
|
136
|
+
"@stylistic/js/space-before-blocks": "off",
|
|
137
|
+
"@stylistic/js/space-before-function-paren": "off",
|
|
138
|
+
"@stylistic/js/space-in-parens": "off",
|
|
139
|
+
"@stylistic/js/space-infix-ops": "off",
|
|
140
|
+
"@stylistic/js/space-unary-ops": "off",
|
|
141
|
+
"@stylistic/js/switch-colon-spacing": "off",
|
|
142
|
+
"@stylistic/js/template-curly-spacing": "off",
|
|
143
|
+
"@stylistic/js/template-tag-spacing": "off",
|
|
144
|
+
"@stylistic/js/wrap-iife": "off",
|
|
145
|
+
"@stylistic/js/wrap-regex": "off",
|
|
146
|
+
"@stylistic/js/yield-star-spacing": "off",
|
|
147
|
+
"@stylistic/ts/block-spacing": "off",
|
|
148
|
+
"@stylistic/ts/brace-style": "off",
|
|
149
|
+
"@stylistic/ts/comma-dangle": "off",
|
|
150
|
+
"@stylistic/ts/comma-spacing": "off",
|
|
151
|
+
"@stylistic/ts/func-call-spacing": "off",
|
|
152
|
+
"@stylistic/ts/function-call-spacing": "off",
|
|
153
|
+
"@stylistic/ts/indent": "off",
|
|
154
|
+
"@stylistic/ts/key-spacing": "off",
|
|
155
|
+
"@stylistic/ts/keyword-spacing": "off",
|
|
156
|
+
"@stylistic/ts/member-delimiter-style": "off",
|
|
157
|
+
"@stylistic/ts/no-extra-parens": "off",
|
|
158
|
+
"@stylistic/ts/no-extra-semi": "off",
|
|
159
|
+
"@stylistic/ts/object-curly-spacing": "off",
|
|
160
|
+
"@stylistic/ts/semi": "off",
|
|
161
|
+
"@stylistic/ts/space-before-blocks": "off",
|
|
162
|
+
"@stylistic/ts/space-before-function-paren": "off",
|
|
163
|
+
"@stylistic/ts/space-infix-ops": "off",
|
|
164
|
+
"@stylistic/ts/type-annotation-spacing": "off",
|
|
165
|
+
"@stylistic/jsx/jsx-child-element-spacing": "off",
|
|
166
|
+
"@stylistic/jsx/jsx-closing-bracket-location": "off",
|
|
167
|
+
"@stylistic/jsx/jsx-closing-tag-location": "off",
|
|
168
|
+
"@stylistic/jsx/jsx-curly-newline": "off",
|
|
169
|
+
"@stylistic/jsx/jsx-curly-spacing": "off",
|
|
170
|
+
"@stylistic/jsx/jsx-equals-spacing": "off",
|
|
171
|
+
"@stylistic/jsx/jsx-first-prop-new-line": "off",
|
|
172
|
+
"@stylistic/jsx/jsx-indent": "off",
|
|
173
|
+
"@stylistic/jsx/jsx-indent-props": "off",
|
|
174
|
+
"@stylistic/jsx/jsx-max-props-per-line": "off"
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
]
|
|
6
178
|
}
|
|
@@ -56,15 +56,11 @@ export async function codeChecksGenerator(tree: Tree, options: CodeChecksGenerat
|
|
|
56
56
|
writeJson(tree, '.eslintrc.json', esLintConfig);
|
|
57
57
|
|
|
58
58
|
// Install necessary dependencies
|
|
59
|
-
addDependenciesToPackageJson(
|
|
60
|
-
tree,
|
|
61
|
-
{},
|
|
62
|
-
devDependencies['code-checks']
|
|
63
|
-
);
|
|
59
|
+
addDependenciesToPackageJson(tree, {}, devDependencies['code-checks']);
|
|
64
60
|
|
|
65
61
|
await formatFiles(tree);
|
|
66
62
|
|
|
67
|
-
return () => {
|
|
63
|
+
return (): void => {
|
|
68
64
|
installPackagesTask(tree);
|
|
69
65
|
};
|
|
70
66
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
2
|
+
lint: 'npx tsc && cross-env ESLINT_USE_FLAT_CONFIG=false npx eslint ./',
|
|
3
|
+
format: 'npx prettier --write . && npm run lint -- --fix',
|
|
4
|
+
prepare: 'husky',
|
|
5
|
+
};
|
|
@@ -12,11 +12,11 @@ import {
|
|
|
12
12
|
getNxLibsPaths,
|
|
13
13
|
LibraryType,
|
|
14
14
|
searchAliasPath,
|
|
15
|
-
searchNxLibsPaths
|
|
15
|
+
searchNxLibsPaths,
|
|
16
16
|
} from '../../shared/utils';
|
|
17
17
|
import { EntityApiGeneratorSchema } from './schema';
|
|
18
18
|
|
|
19
|
-
export async function entityApiGenerator(tree: Tree, options: EntityApiGeneratorSchema) {
|
|
19
|
+
export async function entityApiGenerator(tree: Tree, options: EntityApiGeneratorSchema): Promise<void> {
|
|
20
20
|
const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>(
|
|
21
21
|
'inquirer-autocomplete-standalone',
|
|
22
22
|
);
|
|
@@ -35,14 +35,14 @@ export async function entityApiGenerator(tree: Tree, options: EntityApiGenerator
|
|
|
35
35
|
if (apiClientLibsPaths.length > 1) {
|
|
36
36
|
apiClientLibsPaths[0] = await autocomplete({
|
|
37
37
|
message: 'Select the api client library path:',
|
|
38
|
-
source: (input) => filterSource(input as string, apiClientLibsPaths)
|
|
38
|
+
source: (input) => filterSource(input as string, apiClientLibsPaths),
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
if (apiLibsPaths.length > 1) {
|
|
43
43
|
apiLibsPaths[0] = await autocomplete({
|
|
44
44
|
message: 'Select the api library path:',
|
|
45
|
-
source: (input) => filterSource(input as string, apiLibsPaths)
|
|
45
|
+
source: (input) => filterSource(input as string, apiLibsPaths),
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -71,7 +71,7 @@ export async function entityApiGenerator(tree: Tree, options: EntityApiGenerator
|
|
|
71
71
|
entityName,
|
|
72
72
|
entityFileName: apiName,
|
|
73
73
|
apiClientDirectory,
|
|
74
|
-
baseEndpoint: options.baseEndpoint.startsWith('/') ? options.baseEndpoint : `/${options.baseEndpoint}
|
|
74
|
+
baseEndpoint: options.baseEndpoint.startsWith('/') ? options.baseEndpoint : `/${options.baseEndpoint}`,
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
tree.rename(`${apiPath}/models/entity.ts`, `${apiPath}/models/${apiName}.ts`);
|
|
@@ -89,7 +89,7 @@ export async function entityApiGenerator(tree: Tree, options: EntityApiGenerator
|
|
|
89
89
|
if (storeLibsPaths.length > 1) {
|
|
90
90
|
storeLibsPaths[0] = await autocomplete({
|
|
91
91
|
message: 'Select the store library path:',
|
|
92
|
-
source: (input) => filterSource(input as string, storeLibsPaths)
|
|
92
|
+
source: (input) => filterSource(input as string, storeLibsPaths),
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -98,8 +98,8 @@ export async function entityApiGenerator(tree: Tree, options: EntityApiGenerator
|
|
|
98
98
|
const project = new Project({
|
|
99
99
|
manipulationSettings: {
|
|
100
100
|
indentationText: IndentationText.TwoSpaces,
|
|
101
|
-
quoteKind: QuoteKind.Single
|
|
102
|
-
}
|
|
101
|
+
quoteKind: QuoteKind.Single,
|
|
102
|
+
},
|
|
103
103
|
});
|
|
104
104
|
const store = project.addSourceFileAtPath(`${storeLibsPaths[0]}/store.ts`);
|
|
105
105
|
|
|
@@ -110,7 +110,7 @@ export async function entityApiGenerator(tree: Tree, options: EntityApiGenerator
|
|
|
110
110
|
rootReducer.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression).addProperty({
|
|
111
111
|
name: `[${apiNameDeclaration}.reducerPath]`,
|
|
112
112
|
initializer: `${apiNameDeclaration}.reducer`,
|
|
113
|
-
kind: StructureKind.PropertyAssignment
|
|
113
|
+
kind: StructureKind.PropertyAssignment,
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
const middlewares = store.getVariableDeclarationOrThrow('middlewares');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execSync } from 'child_process';
|
|
2
|
+
import { existsSync, rmSync } from 'fs';
|
|
2
3
|
import * as path from 'path';
|
|
3
4
|
import {
|
|
4
5
|
addDependenciesToPackageJson,
|
|
@@ -9,11 +10,8 @@ import {
|
|
|
9
10
|
readProjectConfiguration,
|
|
10
11
|
Tree,
|
|
11
12
|
updateProjectConfiguration,
|
|
12
|
-
writeJson
|
|
13
|
+
writeJson,
|
|
13
14
|
} from '@nx/devkit';
|
|
14
|
-
import { ExpoAppGeneratorSchema } from './schema';
|
|
15
|
-
import scripts from './scripts';
|
|
16
|
-
import { existsSync, rmSync } from 'fs';
|
|
17
15
|
import { dependencies, devDependencies } from '../../shared/dependencies';
|
|
18
16
|
import { BaseGeneratorType } from '../../shared/enums';
|
|
19
17
|
import {
|
|
@@ -23,19 +21,21 @@ import {
|
|
|
23
21
|
runRNStylesGenerator,
|
|
24
22
|
runFormUtilsGenerator,
|
|
25
23
|
runStoreGenerator,
|
|
26
|
-
runUIKittenGenerator
|
|
24
|
+
runUIKittenGenerator,
|
|
27
25
|
} from '../../shared/generators';
|
|
28
26
|
import { formatName, formatAppIdentifier, addNxAppTag, askQuestion, getImportPathPrefix } from '../../shared/utils';
|
|
27
|
+
import { ExpoAppGeneratorSchema } from './schema';
|
|
28
|
+
import scripts from './scripts';
|
|
29
29
|
|
|
30
|
-
export async function expoAppGenerator(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
)
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const shouldGenerateUIKittenLib = await askQuestion('Do you want to install @ui-kitten? (y/n): ') === 'y';
|
|
30
|
+
export async function expoAppGenerator(tree: Tree, options: ExpoAppGeneratorSchema) {
|
|
31
|
+
const shouldGenerateStoreLib = (await askQuestion('Do you want to create store lib? (y/n): ')) === 'y';
|
|
32
|
+
const shouldGenerateApiClientLib =
|
|
33
|
+
shouldGenerateStoreLib && (await askQuestion('Do you want to create api client lib? (y/n): ')) === 'y';
|
|
34
|
+
const shouldGenerateAuthLibs =
|
|
35
|
+
shouldGenerateApiClientLib && (await askQuestion('Do you want to create auth lib? (y/n): ')) === 'y';
|
|
36
|
+
const shouldGenerateFormUtilsLib =
|
|
37
|
+
(await askQuestion('Do you want to create a lib with the form utils? (y/n): ')) === 'y';
|
|
38
|
+
const shouldGenerateUIKittenLib = (await askQuestion('Do you want to install @ui-kitten? (y/n): ')) === 'y';
|
|
39
39
|
|
|
40
40
|
const appRoot = `apps/${options.directory}`;
|
|
41
41
|
const i18nRoot = `i18n/${options.directory}`;
|
|
@@ -55,7 +55,7 @@ export async function expoAppGenerator(
|
|
|
55
55
|
} else {
|
|
56
56
|
execSync(
|
|
57
57
|
`npx nx g @nx/expo:app ${options.name} --directory=apps/${options.directory} --tags="${tags.join(', ')}" --linter=eslint --unitTestRunner=none --e2eTestRunner=none`,
|
|
58
|
-
{ stdio: 'inherit' }
|
|
58
|
+
{ stdio: 'inherit' },
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -116,7 +116,7 @@ export async function expoAppGenerator(
|
|
|
116
116
|
formatDirectory: () => libPath,
|
|
117
117
|
isUIKittenEnabled: shouldGenerateUIKittenLib,
|
|
118
118
|
isStoreEnabled: shouldGenerateStoreLib,
|
|
119
|
-
appDirectory: options.directory
|
|
119
|
+
appDirectory: options.directory,
|
|
120
120
|
});
|
|
121
121
|
|
|
122
122
|
addNxAppTag(tree, options.directory);
|
|
@@ -127,19 +127,19 @@ export async function expoAppGenerator(
|
|
|
127
127
|
tree,
|
|
128
128
|
{
|
|
129
129
|
...dependencies['expo-app'],
|
|
130
|
-
...dependencies['expo-app-root']
|
|
130
|
+
...dependencies['expo-app-root'],
|
|
131
131
|
},
|
|
132
132
|
{
|
|
133
133
|
...devDependencies['expo-app'],
|
|
134
|
-
...devDependencies['expo-app-root']
|
|
135
|
-
}
|
|
134
|
+
...devDependencies['expo-app-root'],
|
|
135
|
+
},
|
|
136
136
|
);
|
|
137
137
|
|
|
138
138
|
addDependenciesToPackageJson(tree, dependencies['expo-app'], devDependencies['expo-app'], appPackagePath);
|
|
139
139
|
|
|
140
140
|
await formatFiles(tree);
|
|
141
141
|
|
|
142
|
-
return () => {
|
|
142
|
+
return (): void => {
|
|
143
143
|
installPackagesTask(tree);
|
|
144
144
|
execSync('npx expo install --fix', { stdio: 'inherit' });
|
|
145
145
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
|
|
2
|
+
start: 'cross-env EXPO_PUBLIC_APP_ENV=development npx expo start',
|
|
3
3
|
'start:prod': 'cross-env EXPO_PUBLIC_APP_ENV=production npx expo start',
|
|
4
4
|
'build:dev': 'eas build --no-wait -p all --profile=development',
|
|
5
5
|
'build:internal': 'npm run build:dev -- --profile=internal',
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import { addDependenciesToPackageJson, formatFiles, generateFiles, installPackagesTask, Tree } from '@nx/devkit';
|
|
2
1
|
import * as path from 'path';
|
|
3
|
-
import {
|
|
4
|
-
import { dynamicImport, formatName, getNxLibsPaths, LibraryType, searchNxLibsPaths } from '../../shared/utils';
|
|
2
|
+
import { addDependenciesToPackageJson, formatFiles, generateFiles, installPackagesTask, Tree } from '@nx/devkit';
|
|
5
3
|
import { dependencies } from '../../shared/dependencies';
|
|
4
|
+
import { dynamicImport, formatName, getNxLibsPaths, LibraryType, searchNxLibsPaths } from '../../shared/utils';
|
|
5
|
+
import { FormGeneratorSchema } from './schema';
|
|
6
6
|
import { addFormUsage, getAppName, getFormUtilsDirectory, updateIndex } from './utils';
|
|
7
7
|
|
|
8
8
|
export async function formGenerator(tree: Tree, options: FormGeneratorSchema) {
|
|
9
9
|
// Get input data
|
|
10
|
-
const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>(
|
|
10
|
+
const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>(
|
|
11
|
+
'inquirer-autocomplete-standalone',
|
|
12
|
+
);
|
|
11
13
|
const availableLibsPaths = getNxLibsPaths([LibraryType.FEATURES, LibraryType.UI]);
|
|
12
14
|
const libPath = await autocomplete({
|
|
13
15
|
message: 'Enter the library path: ',
|
|
14
16
|
source: async (input) => {
|
|
15
|
-
const filteredNxLibsPaths = searchNxLibsPaths(availableLibsPaths, input as string)
|
|
17
|
+
const filteredNxLibsPaths = searchNxLibsPaths(availableLibsPaths, input as string);
|
|
16
18
|
|
|
17
|
-
return filteredNxLibsPaths.map((path) => ({ value: path }))
|
|
18
|
-
}
|
|
19
|
+
return filteredNxLibsPaths.map((path) => ({ value: path }));
|
|
20
|
+
},
|
|
19
21
|
});
|
|
20
22
|
const fileName = options.name;
|
|
21
23
|
const placeOfUse = options.placeOfUse;
|
|
@@ -27,13 +29,18 @@ export async function formGenerator(tree: Tree, options: FormGeneratorSchema) {
|
|
|
27
29
|
// Generate form class
|
|
28
30
|
const formsPath = `${libPath}/lib/forms`;
|
|
29
31
|
const formFilePath = `${formsPath}/${fileName}.ts`;
|
|
32
|
+
|
|
30
33
|
if (tree.exists(formFilePath)) {
|
|
31
34
|
throw new Error('The form already exists');
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
const formUtilsDirectory = await getFormUtilsDirectory(tree, getAppName(libPath));
|
|
35
38
|
const formClassName = `${formatName(fileName, true)}FormSchema`;
|
|
36
|
-
generateFiles(tree, path.join(__dirname, `files`), formsPath, {
|
|
39
|
+
generateFiles(tree, path.join(__dirname, `files`), formsPath, {
|
|
40
|
+
className: formClassName,
|
|
41
|
+
fileName,
|
|
42
|
+
formUtilsDirectory,
|
|
43
|
+
});
|
|
37
44
|
updateIndex(formsPath, fileName, tree);
|
|
38
45
|
|
|
39
46
|
// Add form usage
|
|
@@ -45,7 +52,8 @@ export async function formGenerator(tree: Tree, options: FormGeneratorSchema) {
|
|
|
45
52
|
|
|
46
53
|
// Install dependencies
|
|
47
54
|
addDependenciesToPackageJson(tree, dependencies.form, {});
|
|
48
|
-
|
|
55
|
+
|
|
56
|
+
return (): void => {
|
|
49
57
|
installPackagesTask(tree);
|
|
50
58
|
};
|
|
51
59
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
QuoteKind,
|
|
8
8
|
SourceFile,
|
|
9
9
|
SyntaxKind,
|
|
10
|
-
VariableDeclaration
|
|
10
|
+
VariableDeclaration,
|
|
11
11
|
} from 'ts-morph';
|
|
12
12
|
import { addNamedImport } from '../../../shared/utils';
|
|
13
13
|
|
|
@@ -16,23 +16,28 @@ function getFormUsageCode(formClassName: string): string {
|
|
|
16
16
|
const form = useForm({
|
|
17
17
|
defaultValues: formSchema.formValues,
|
|
18
18
|
resolver: yupResolver(${formClassName}.validationSchema)
|
|
19
|
-
});\n\n
|
|
19
|
+
});\n\n`;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function getForwardRefFunction(variable: VariableDeclaration): FunctionExpression | ArrowFunction {
|
|
23
23
|
const callExpressionInitializer = variable.getInitializerIfKind(SyntaxKind.CallExpression);
|
|
24
|
-
const hasForwardRef = callExpressionInitializer?.getExpression().getText() === 'forwardRef'
|
|
24
|
+
const hasForwardRef = callExpressionInitializer?.getExpression().getText() === 'forwardRef';
|
|
25
|
+
|
|
25
26
|
if (!hasForwardRef) {
|
|
26
27
|
throw new Error('Could not find forwardRef');
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
const argument = callExpressionInitializer.getArguments()[0];
|
|
30
|
-
const hasComponentFunction =
|
|
31
|
+
const hasComponentFunction =
|
|
32
|
+
argument && [SyntaxKind.FunctionExpression, SyntaxKind.ArrowFunction].includes(argument.getKind());
|
|
33
|
+
|
|
31
34
|
if (!hasComponentFunction) {
|
|
32
35
|
throw new Error('Could not find a component function in forwardRef');
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
const functionExpression = argument.asKind(
|
|
38
|
+
const functionExpression = argument.asKind(
|
|
39
|
+
argument.getKind() === SyntaxKind.FunctionExpression ? SyntaxKind.FunctionExpression : SyntaxKind.ArrowFunction,
|
|
40
|
+
);
|
|
36
41
|
|
|
37
42
|
if (!functionExpression) {
|
|
38
43
|
throw new Error('Could not get a component function in forwardRef');
|
|
@@ -41,31 +46,39 @@ function getForwardRefFunction(variable: VariableDeclaration): FunctionExpressio
|
|
|
41
46
|
return functionExpression;
|
|
42
47
|
}
|
|
43
48
|
|
|
44
|
-
function getPlaceOfUse(
|
|
49
|
+
function getPlaceOfUse(
|
|
50
|
+
file: SourceFile,
|
|
51
|
+
placeOfUseName: string,
|
|
52
|
+
): FunctionExpression | ArrowFunction | FunctionDeclaration {
|
|
45
53
|
const placeOfUseFunction = file.getFunction(placeOfUseName);
|
|
54
|
+
|
|
46
55
|
if (placeOfUseFunction) {
|
|
47
56
|
return placeOfUseFunction;
|
|
48
57
|
}
|
|
49
58
|
|
|
50
59
|
const variable = file.getVariableDeclaration(placeOfUseName);
|
|
60
|
+
|
|
51
61
|
if (!variable) {
|
|
52
62
|
throw new Error(`Could not find the place where the form should be used (${placeOfUseName}).`);
|
|
53
63
|
}
|
|
54
64
|
|
|
55
|
-
return
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
return (
|
|
66
|
+
variable.getInitializerIfKind(SyntaxKind.FunctionExpression) ||
|
|
67
|
+
variable.getInitializerIfKind(SyntaxKind.ArrowFunction) ||
|
|
68
|
+
getForwardRefFunction(variable)
|
|
69
|
+
);
|
|
58
70
|
}
|
|
59
71
|
|
|
60
72
|
export async function addFormUsage(libPath: string, placeOfUseName: string, formClassName: string): Promise<void> {
|
|
61
73
|
const project = new Project({
|
|
62
74
|
manipulationSettings: {
|
|
63
75
|
indentationText: IndentationText.TwoSpaces,
|
|
64
|
-
quoteKind: QuoteKind.Single
|
|
65
|
-
}
|
|
76
|
+
quoteKind: QuoteKind.Single,
|
|
77
|
+
},
|
|
66
78
|
});
|
|
67
79
|
const files = project.addSourceFilesAtPaths([`${libPath}/lib/**/*.tsx`, `${libPath}/lib/**/*.ts`]);
|
|
68
80
|
const file = files.find((file) => file.getFunction(placeOfUseName) || file.getVariableDeclaration(placeOfUseName));
|
|
81
|
+
|
|
69
82
|
if (!file) {
|
|
70
83
|
throw new Error('Could not find the place where the form should be used.');
|
|
71
84
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { runFormUtilsGenerator } from '../../../shared/generators';
|
|
1
3
|
import {
|
|
2
4
|
constants,
|
|
3
5
|
dynamicImport,
|
|
@@ -6,24 +8,31 @@ import {
|
|
|
6
8
|
LibraryType,
|
|
7
9
|
searchAliasPath,
|
|
8
10
|
searchNxLibsPaths,
|
|
9
|
-
selectProject
|
|
11
|
+
selectProject,
|
|
10
12
|
} from '../../../shared/utils';
|
|
11
|
-
import { runFormUtilsGenerator } from '../../../shared/generators';
|
|
12
|
-
import { Tree } from '@nx/devkit';
|
|
13
13
|
import { getAppName } from './get-app-name';
|
|
14
14
|
|
|
15
15
|
function getFormUtilsPaths(): Array<string> {
|
|
16
16
|
const utilsLibsPaths = getNxLibsPaths([LibraryType.UTILS]);
|
|
17
|
+
|
|
17
18
|
return searchNxLibsPaths(utilsLibsPaths, 'utils/form/src', 'endsWith');
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export async function getFormUtilsDirectory(tree: Tree, appName: string): Promise<string> {
|
|
21
|
-
const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>(
|
|
22
|
+
const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>(
|
|
23
|
+
'inquirer-autocomplete-standalone',
|
|
24
|
+
);
|
|
22
25
|
|
|
23
26
|
const formUtilsLibsPaths = getFormUtilsPaths();
|
|
24
27
|
|
|
25
28
|
if (!formUtilsLibsPaths.length) {
|
|
26
|
-
const formUtilsAppDirectory = (
|
|
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;
|
|
27
36
|
await runFormUtilsGenerator(tree, { directory: formUtilsAppDirectory });
|
|
28
37
|
|
|
29
38
|
return searchAliasPath(getFormUtilsPaths()[0]) as string;
|
|
@@ -38,7 +47,11 @@ export async function getFormUtilsDirectory(tree: Tree, appName: string): Promis
|
|
|
38
47
|
|
|
39
48
|
formUtilsLibsPaths[0] = await autocomplete({
|
|
40
49
|
message: 'Select the path of the library with the form utilities: ',
|
|
41
|
-
source: (input) =>
|
|
50
|
+
source: (input) =>
|
|
51
|
+
filterSource(
|
|
52
|
+
input as string,
|
|
53
|
+
formUtilsLibsPaths.filter((path) => [appName, constants.sharedValue].includes(getAppName(path))),
|
|
54
|
+
),
|
|
42
55
|
});
|
|
43
56
|
}
|
|
44
57
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
1
2
|
import { Tree } from '@nx/devkit';
|
|
2
3
|
import { kebabCase } from 'lodash';
|
|
3
|
-
import { existsSync } from 'fs';
|
|
4
4
|
import { appendFileContent } from '../../../shared/utils';
|
|
5
5
|
|
|
6
6
|
export function updateIndex(formsPath: string, fileName: string, tree: Tree): void {
|
|
7
7
|
const formsIndexFilePath = `${formsPath}/index.ts`;
|
|
8
8
|
const newIndexContent = `export * from './${kebabCase(fileName)}';\n`;
|
|
9
|
+
|
|
9
10
|
if (!existsSync(formsIndexFilePath)) {
|
|
10
11
|
tree.write(formsIndexFilePath, newIndexContent);
|
|
11
12
|
} else {
|