@ronas-it/nx-generators 0.10.3 → 0.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/package.json +4 -3
- package/src/generators/code-checks/config.d.ts +18 -0
- package/src/generators/code-checks/config.js +20 -0
- package/src/generators/code-checks/config.js.map +1 -0
- package/src/generators/code-checks/files/.eslintrc.json.template +173 -1
- package/src/generators/code-checks/generator.d.ts +4 -0
- package/src/generators/code-checks/generator.js +53 -0
- package/src/generators/code-checks/generator.js.map +1 -0
- package/src/generators/code-checks/scripts.d.ts +6 -0
- package/src/generators/code-checks/scripts.js +8 -0
- package/src/generators/code-checks/scripts.js.map +1 -0
- package/src/generators/entity-api/generator.d.ts +4 -0
- package/src/generators/entity-api/generator.js +87 -0
- package/src/generators/entity-api/generator.js.map +1 -0
- package/src/generators/expo-app/generator.d.ts +4 -0
- package/src/generators/expo-app/generator.js +93 -0
- package/src/generators/expo-app/generator.js.map +1 -0
- package/src/generators/expo-app/scripts.d.ts +13 -0
- package/src/generators/expo-app/scripts.js +15 -0
- package/src/generators/expo-app/scripts.js.map +1 -0
- package/src/generators/form/generator.d.ts +4 -0
- package/src/generators/form/generator.js +55 -0
- package/src/generators/form/generator.js.map +1 -0
- package/src/generators/form/utils/add-form-usage.d.ts +1 -0
- package/src/generators/form/utils/add-form-usage.js +71 -0
- package/src/generators/form/utils/add-form-usage.js.map +1 -0
- package/src/generators/form/utils/get-app-name.d.ts +1 -0
- package/src/generators/form/utils/get-app-name.js +8 -0
- package/src/generators/form/utils/get-app-name.js.map +1 -0
- package/src/generators/form/utils/get-form-utils-directory.d.ts +2 -0
- package/src/generators/form/utils/get-form-utils-directory.js +35 -0
- package/src/generators/form/utils/get-form-utils-directory.js.map +1 -0
- package/src/generators/form/utils/index.js +8 -0
- package/src/generators/form/utils/index.js.map +1 -0
- package/src/generators/form/utils/update-index.d.ts +2 -0
- package/src/generators/form/utils/update-index.js +18 -0
- package/src/generators/form/utils/update-index.js.map +1 -0
- package/src/generators/lib-move/generator.d.ts +4 -0
- package/src/generators/lib-move/generator.js +37 -0
- package/src/generators/lib-move/generator.js.map +1 -0
- package/src/generators/lib-remove/generator.d.ts +4 -0
- package/src/generators/lib-remove/generator.js +22 -0
- package/src/generators/lib-remove/generator.js.map +1 -0
- package/src/generators/lib-rename/generator.d.ts +4 -0
- package/src/generators/lib-rename/generator.js +22 -0
- package/src/generators/lib-rename/generator.js.map +1 -0
- package/src/generators/lib-tags/generator.d.ts +4 -0
- package/src/generators/lib-tags/generator.js +56 -0
- package/src/generators/lib-tags/generator.js.map +1 -0
- package/src/generators/lib-tags/interfaces/context.d.ts +8 -0
- package/src/generators/lib-tags/interfaces/context.js +3 -0
- package/src/generators/lib-tags/interfaces/context.js.map +1 -0
- package/src/generators/lib-tags/interfaces/index.js +6 -0
- package/src/generators/lib-tags/interfaces/index.js.map +1 -0
- package/src/generators/lib-tags/interfaces/{verify-tag-config.ts → verify-tag-config.d.ts} +6 -7
- package/src/generators/lib-tags/interfaces/verify-tag-config.js +3 -0
- package/src/generators/lib-tags/interfaces/verify-tag-config.js.map +1 -0
- package/src/generators/lib-tags/types/index.js +5 -0
- package/src/generators/lib-tags/types/index.js.map +1 -0
- package/src/generators/lib-tags/types/tag.js +3 -0
- package/src/generators/lib-tags/types/tag.js.map +1 -0
- package/src/generators/lib-tags/utils/check-lib-tags.d.ts +4 -0
- package/src/generators/lib-tags/utils/check-lib-tags.js +113 -0
- package/src/generators/lib-tags/utils/check-lib-tags.js.map +1 -0
- package/src/generators/lib-tags/utils/index.js +5 -0
- package/src/generators/lib-tags/utils/index.js.map +1 -0
- package/src/generators/next-app/generator.d.ts +4 -0
- package/src/generators/next-app/generator.js +71 -0
- package/src/generators/next-app/generator.js.map +1 -0
- package/src/generators/react-component/generator.d.ts +4 -0
- package/src/generators/react-component/generator.js +60 -0
- package/src/generators/react-component/generator.js.map +1 -0
- package/src/generators/react-lib/generator.d.ts +4 -0
- package/src/generators/react-lib/generator.js +61 -0
- package/src/generators/react-lib/generator.js.map +1 -0
- package/src/generators/repo-config/generator.d.ts +3 -0
- package/src/generators/repo-config/generator.js +36 -0
- package/src/generators/repo-config/generator.js.map +1 -0
- package/src/generators/repo-config/scripts.d.ts +4 -0
- package/src/generators/repo-config/scripts.js +6 -0
- package/src/generators/repo-config/scripts.js.map +1 -0
- package/src/index.js +2 -0
- package/src/index.js.map +1 -0
- package/src/shared/dependencies.d.ts +73 -0
- package/src/shared/dependencies.js +79 -0
- package/src/shared/dependencies.js.map +1 -0
- package/src/shared/enums/base-generator-type.d.ts +4 -0
- package/src/shared/enums/base-generator-type.js +9 -0
- package/src/shared/enums/base-generator-type.js.map +1 -0
- package/src/shared/enums/index.js +5 -0
- package/src/shared/enums/index.js.map +1 -0
- package/src/shared/generators/api-client/generator.d.ts +6 -0
- package/src/shared/generators/api-client/generator.js +37 -0
- package/src/shared/generators/api-client/generator.js.map +1 -0
- package/src/shared/generators/api-client/index.js +5 -0
- package/src/shared/generators/api-client/index.js.map +1 -0
- package/src/shared/generators/app-env/generator.d.ts +8 -0
- package/src/shared/generators/app-env/generator.js +28 -0
- package/src/shared/generators/app-env/generator.js.map +1 -0
- package/src/shared/generators/app-env/index.js +5 -0
- package/src/shared/generators/app-env/index.js.map +1 -0
- package/src/shared/generators/auth/generator.d.ts +4 -0
- package/src/shared/generators/auth/generator.js +82 -0
- package/src/shared/generators/auth/generator.js.map +1 -0
- package/src/shared/generators/auth/index.js +5 -0
- package/src/shared/generators/auth/index.js.map +1 -0
- package/src/shared/generators/form-utils/generator.d.ts +5 -0
- package/src/shared/generators/form-utils/generator.js +24 -0
- package/src/shared/generators/form-utils/generator.js.map +1 -0
- package/src/shared/generators/form-utils/index.js +5 -0
- package/src/shared/generators/form-utils/index.js.map +1 -0
- package/src/shared/generators/index.js +12 -0
- package/src/shared/generators/index.js.map +1 -0
- package/src/shared/generators/rn-styles/generator.d.ts +6 -0
- package/src/shared/generators/rn-styles/generator.js +36 -0
- package/src/shared/generators/rn-styles/generator.js.map +1 -0
- package/src/shared/generators/rn-styles/index.js +5 -0
- package/src/shared/generators/rn-styles/index.js.map +1 -0
- package/src/shared/generators/storage/generator.d.ts +6 -0
- package/src/shared/generators/storage/generator.js +27 -0
- package/src/shared/generators/storage/generator.js.map +1 -0
- package/src/shared/generators/storage/index.js +5 -0
- package/src/shared/generators/storage/index.js.map +1 -0
- package/src/shared/generators/store/generator.d.ts +4 -0
- package/src/shared/generators/store/generator.js +36 -0
- package/src/shared/generators/store/generator.js.map +1 -0
- package/src/shared/generators/store/index.js +5 -0
- package/src/shared/generators/store/index.js.map +1 -0
- package/src/shared/generators/ui-kitten/generator.d.ts +6 -0
- package/src/shared/generators/ui-kitten/generator.js +40 -0
- package/src/shared/generators/ui-kitten/generator.js.map +1 -0
- package/src/shared/generators/ui-kitten/index.js +5 -0
- package/src/shared/generators/ui-kitten/index.js.map +1 -0
- package/src/shared/templates/config-template.json +2 -12
- package/src/shared/utils/cli-utils.d.ts +31 -0
- package/src/shared/utils/cli-utils.js +129 -0
- package/src/shared/utils/cli-utils.js.map +1 -0
- package/src/shared/utils/config-utils.d.ts +19 -0
- package/src/shared/utils/config-utils.js +124 -0
- package/src/shared/utils/config-utils.js.map +1 -0
- package/src/shared/utils/constants.d.ts +3 -0
- package/src/shared/utils/constants.js +7 -0
- package/src/shared/utils/constants.js.map +1 -0
- package/src/shared/utils/dynamic-import.d.ts +1 -0
- package/src/shared/utils/dynamic-import.js +5 -0
- package/src/shared/utils/dynamic-import.js.map +1 -0
- package/src/shared/utils/format-utils.d.ts +4 -0
- package/src/shared/utils/format-utils.js +18 -0
- package/src/shared/utils/format-utils.js.map +1 -0
- package/src/shared/utils/get-lib-directory-name.d.ts +1 -0
- package/src/shared/utils/get-lib-directory-name.js +15 -0
- package/src/shared/utils/get-lib-directory-name.js.map +1 -0
- package/src/shared/utils/index.js +11 -0
- package/src/shared/utils/index.js.map +1 -0
- package/src/shared/utils/ts-utils.d.ts +2 -0
- package/src/shared/utils/ts-utils.js +22 -0
- package/src/shared/utils/ts-utils.js.map +1 -0
- package/.eslintrc.json +0 -37
- package/jest.config.ts +0 -10
- package/project.json +0 -61
- package/src/generators/code-checks/config.ts +0 -17
- package/src/generators/code-checks/generator.ts +0 -72
- package/src/generators/code-checks/scripts.ts +0 -5
- package/src/generators/entity-api/generator.ts +0 -127
- package/src/generators/expo-app/generator.ts +0 -152
- package/src/generators/expo-app/scripts.ts +0 -12
- package/src/generators/form/generator.ts +0 -53
- package/src/generators/form/utils/add-form-usage.ts +0 -86
- package/src/generators/form/utils/get-app-name.ts +0 -3
- package/src/generators/form/utils/get-form-utils-directory.ts +0 -46
- package/src/generators/form/utils/update-index.ts +0 -14
- package/src/generators/lib-move/generator.ts +0 -57
- package/src/generators/lib-remove/generator.ts +0 -25
- package/src/generators/lib-rename/generator.ts +0 -25
- package/src/generators/lib-tags/generator.ts +0 -68
- package/src/generators/lib-tags/interfaces/context.ts +0 -9
- package/src/generators/lib-tags/utils/check-lib-tags.ts +0 -143
- package/src/generators/next-app/generator.ts +0 -99
- package/src/generators/react-component/generator.ts +0 -80
- package/src/generators/react-lib/generator.ts +0 -86
- package/src/generators/repo-config/generator.ts +0 -44
- package/src/generators/repo-config/scripts.ts +0 -3
- package/src/shared/dependencies.ts +0 -76
- package/src/shared/enums/base-generator-type.ts +0 -4
- package/src/shared/generators/api-client/generator.ts +0 -49
- package/src/shared/generators/app-env/generator.ts +0 -37
- package/src/shared/generators/auth/generator.ts +0 -107
- package/src/shared/generators/form-utils/generator.ts +0 -23
- package/src/shared/generators/rn-styles/generator.ts +0 -49
- package/src/shared/generators/storage/generator.ts +0 -34
- package/src/shared/generators/store/generator.ts +0 -48
- package/src/shared/generators/ui-kitten/generator.ts +0 -55
- package/src/shared/utils/cli-utils.ts +0 -149
- package/src/shared/utils/config-utils.ts +0 -146
- package/src/shared/utils/constants.ts +0 -3
- package/src/shared/utils/dynamic-import.ts +0 -4
- package/src/shared/utils/format-utils.ts +0 -16
- package/src/shared/utils/get-lib-directory-name.ts +0 -12
- package/src/shared/utils/ts-utils.ts +0 -17
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -14
- /package/src/generators/form/utils/{index.ts → index.d.ts} +0 -0
- /package/src/generators/lib-tags/interfaces/{index.ts → index.d.ts} +0 -0
- /package/src/generators/lib-tags/types/{index.ts → index.d.ts} +0 -0
- /package/src/generators/lib-tags/types/{tag.ts → tag.d.ts} +0 -0
- /package/src/generators/lib-tags/utils/{index.ts → index.d.ts} +0 -0
- /package/src/{index.ts → index.d.ts} +0 -0
- /package/src/shared/enums/{index.ts → index.d.ts} +0 -0
- /package/src/shared/generators/api-client/{index.ts → index.d.ts} +0 -0
- /package/src/shared/generators/app-env/{index.ts → index.d.ts} +0 -0
- /package/src/shared/generators/auth/{index.ts → index.d.ts} +0 -0
- /package/src/shared/generators/form-utils/{index.ts → index.d.ts} +0 -0
- /package/src/shared/generators/{index.ts → index.d.ts} +0 -0
- /package/src/shared/generators/rn-styles/{index.ts → index.d.ts} +0 -0
- /package/src/shared/generators/storage/{index.ts → index.d.ts} +0 -0
- /package/src/shared/generators/store/{index.ts → index.d.ts} +0 -0
- /package/src/shared/generators/ui-kitten/{index.ts → index.d.ts} +0 -0
- /package/src/shared/utils/{index.ts → index.d.ts} +0 -0
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import { formatFiles, generateFiles, Tree } from '@nx/devkit';
|
|
3
|
-
import { camelCase, kebabCase, startCase } from 'lodash';
|
|
4
|
-
import { IndentationText, Project, QuoteKind, StructureKind, SyntaxKind } from 'ts-morph';
|
|
5
|
-
import {
|
|
6
|
-
addNamedImport,
|
|
7
|
-
appendFileContent,
|
|
8
|
-
askQuestion,
|
|
9
|
-
createCliReadline,
|
|
10
|
-
dynamicImport,
|
|
11
|
-
filterSource,
|
|
12
|
-
getNxLibsPaths,
|
|
13
|
-
LibraryType,
|
|
14
|
-
searchAliasPath,
|
|
15
|
-
searchNxLibsPaths
|
|
16
|
-
} from '../../shared/utils';
|
|
17
|
-
import { EntityApiGeneratorSchema } from './schema';
|
|
18
|
-
|
|
19
|
-
export async function entityApiGenerator(tree: Tree, options: EntityApiGeneratorSchema) {
|
|
20
|
-
const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>(
|
|
21
|
-
'inquirer-autocomplete-standalone',
|
|
22
|
-
);
|
|
23
|
-
const nxLibsPaths = getNxLibsPaths([LibraryType.DATA_ACCESS]);
|
|
24
|
-
const apiLibsPaths = searchNxLibsPaths(nxLibsPaths, 'data-access/api/src', 'endsWith');
|
|
25
|
-
const apiClientLibsPaths = searchNxLibsPaths(nxLibsPaths, 'data-access/api-client/src', 'endsWith');
|
|
26
|
-
|
|
27
|
-
if (!apiClientLibsPaths.length) {
|
|
28
|
-
throw new Error('Could not find API Client path.');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!apiLibsPaths.length) {
|
|
32
|
-
throw new Error('Could not find API path.');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (apiClientLibsPaths.length > 1) {
|
|
36
|
-
apiClientLibsPaths[0] = await autocomplete({
|
|
37
|
-
message: 'Select the api client library path:',
|
|
38
|
-
source: (input) => filterSource(input as string, apiClientLibsPaths)
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (apiLibsPaths.length > 1) {
|
|
43
|
-
apiLibsPaths[0] = await autocomplete({
|
|
44
|
-
message: 'Select the api library path:',
|
|
45
|
-
source: (input) => filterSource(input as string, apiLibsPaths)
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const apiDirectory = searchAliasPath(apiLibsPaths[0]) as string;
|
|
50
|
-
const apiClientDirectory = searchAliasPath(apiClientLibsPaths[0]);
|
|
51
|
-
|
|
52
|
-
const libPath = apiLibsPaths[0];
|
|
53
|
-
const libRootPath = `${libPath}/lib`;
|
|
54
|
-
|
|
55
|
-
const cliReadline = createCliReadline();
|
|
56
|
-
options.name =
|
|
57
|
-
options.name || (await askQuestion('Enter the name of the entity (e.g: User): ', undefined, cliReadline));
|
|
58
|
-
|
|
59
|
-
const apiName = kebabCase(options.name);
|
|
60
|
-
|
|
61
|
-
options.baseEndpoint =
|
|
62
|
-
options.baseEndpoint || (await askQuestion('Enter the base endpoint (e.g: /users): ', `/${apiName}`, cliReadline));
|
|
63
|
-
cliReadline.close();
|
|
64
|
-
|
|
65
|
-
const apiPath = `${libRootPath}/${apiName}`;
|
|
66
|
-
const entityName = startCase(camelCase(apiName)).replace(/\s+/g, '');
|
|
67
|
-
|
|
68
|
-
generateFiles(tree, path.join(__dirname, `files`), apiPath, {
|
|
69
|
-
...options,
|
|
70
|
-
apiName: camelCase(options.name),
|
|
71
|
-
entityName,
|
|
72
|
-
entityFileName: apiName,
|
|
73
|
-
apiClientDirectory,
|
|
74
|
-
baseEndpoint: options.baseEndpoint.startsWith('/') ? options.baseEndpoint : `/${options.baseEndpoint}`
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
tree.rename(`${apiPath}/models/entity.ts`, `${apiPath}/models/${apiName}.ts`);
|
|
78
|
-
|
|
79
|
-
appendFileContent(`${libRootPath}/index.ts`, `export * from './${apiName}';\n`, tree);
|
|
80
|
-
|
|
81
|
-
const storeLibsPaths = searchNxLibsPaths(nxLibsPaths, 'data-access/store/src', 'endsWith');
|
|
82
|
-
|
|
83
|
-
if (!storeLibsPaths.length) {
|
|
84
|
-
await formatFiles(tree);
|
|
85
|
-
|
|
86
|
-
throw new Error('Could not find redux store path.');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (storeLibsPaths.length > 1) {
|
|
90
|
-
storeLibsPaths[0] = await autocomplete({
|
|
91
|
-
message: 'Select the store library path:',
|
|
92
|
-
source: (input) => filterSource(input as string, storeLibsPaths)
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Update redux store
|
|
97
|
-
const apiNameDeclaration = camelCase(options.name + 'Api');
|
|
98
|
-
const project = new Project({
|
|
99
|
-
manipulationSettings: {
|
|
100
|
-
indentationText: IndentationText.TwoSpaces,
|
|
101
|
-
quoteKind: QuoteKind.Single
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
const store = project.addSourceFileAtPath(`${storeLibsPaths[0]}/store.ts`);
|
|
105
|
-
|
|
106
|
-
addNamedImport(apiNameDeclaration, apiDirectory, store);
|
|
107
|
-
|
|
108
|
-
const rootReducer = store.getVariableDeclarationOrThrow('rootReducer');
|
|
109
|
-
|
|
110
|
-
rootReducer.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression).addProperty({
|
|
111
|
-
name: `[${apiNameDeclaration}.reducerPath]`,
|
|
112
|
-
initializer: `${apiNameDeclaration}.reducer`,
|
|
113
|
-
kind: StructureKind.PropertyAssignment
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const middlewares = store.getVariableDeclarationOrThrow('middlewares');
|
|
117
|
-
|
|
118
|
-
middlewares
|
|
119
|
-
.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression)
|
|
120
|
-
.addElement(`${apiNameDeclaration}.middleware`);
|
|
121
|
-
|
|
122
|
-
project.saveSync();
|
|
123
|
-
|
|
124
|
-
await formatFiles(tree);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export default entityApiGenerator;
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import {
|
|
4
|
-
addDependenciesToPackageJson,
|
|
5
|
-
formatFiles,
|
|
6
|
-
generateFiles,
|
|
7
|
-
installPackagesTask,
|
|
8
|
-
readJson,
|
|
9
|
-
readProjectConfiguration,
|
|
10
|
-
Tree,
|
|
11
|
-
updateProjectConfiguration,
|
|
12
|
-
writeJson
|
|
13
|
-
} from '@nx/devkit';
|
|
14
|
-
import { ExpoAppGeneratorSchema } from './schema';
|
|
15
|
-
import scripts from './scripts';
|
|
16
|
-
import { existsSync, rmSync } from 'fs';
|
|
17
|
-
import { dependencies, devDependencies } from '../../shared/dependencies';
|
|
18
|
-
import { BaseGeneratorType } from '../../shared/enums';
|
|
19
|
-
import {
|
|
20
|
-
runAppEnvGenerator,
|
|
21
|
-
runApiClientGenerator,
|
|
22
|
-
runStorageGenerator,
|
|
23
|
-
runRNStylesGenerator,
|
|
24
|
-
runFormUtilsGenerator,
|
|
25
|
-
runStoreGenerator,
|
|
26
|
-
runUIKittenGenerator
|
|
27
|
-
} from '../../shared/generators';
|
|
28
|
-
import { formatName, formatAppIdentifier, addNxAppTag, askQuestion, getImportPathPrefix } from '../../shared/utils';
|
|
29
|
-
|
|
30
|
-
export async function expoAppGenerator(
|
|
31
|
-
tree: Tree,
|
|
32
|
-
options: ExpoAppGeneratorSchema
|
|
33
|
-
) {
|
|
34
|
-
const shouldGenerateStoreLib = await askQuestion('Do you want to create store lib? (y/n): ') === 'y';
|
|
35
|
-
const shouldGenerateApiClientLib = shouldGenerateStoreLib && await askQuestion('Do you want to create api client lib? (y/n): ') === 'y';
|
|
36
|
-
const shouldGenerateAuthLibs = shouldGenerateApiClientLib && await askQuestion('Do you want to create auth lib? (y/n): ') === 'y';
|
|
37
|
-
const shouldGenerateFormUtilsLib = 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
|
-
|
|
40
|
-
const appRoot = `apps/${options.directory}`;
|
|
41
|
-
const i18nRoot = `i18n/${options.directory}`;
|
|
42
|
-
const appTestFolder = `apps/${options.directory}-e2e`;
|
|
43
|
-
const libPath = `${getImportPathPrefix(tree)}/${options.directory}`;
|
|
44
|
-
const tags = [`app:${options.directory}`, 'type:app'];
|
|
45
|
-
|
|
46
|
-
// Install @nx/expo plugin
|
|
47
|
-
execSync('npx nx add @nx/expo', { stdio: 'inherit' });
|
|
48
|
-
|
|
49
|
-
if (existsSync(appRoot)) {
|
|
50
|
-
const project = readProjectConfiguration(tree, options.directory);
|
|
51
|
-
|
|
52
|
-
project.tags = [`app:${options.directory}`, 'type:app'];
|
|
53
|
-
|
|
54
|
-
updateProjectConfiguration(tree, project.name as string, project);
|
|
55
|
-
} else {
|
|
56
|
-
execSync(
|
|
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' }
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Generate shared libs
|
|
63
|
-
await runAppEnvGenerator(tree, { ...options, baseGeneratorType: BaseGeneratorType.EXPO_APP });
|
|
64
|
-
await runStorageGenerator(tree, options);
|
|
65
|
-
await runRNStylesGenerator(tree, options);
|
|
66
|
-
|
|
67
|
-
if (shouldGenerateStoreLib) {
|
|
68
|
-
await runStoreGenerator(tree, { ...options, baseGeneratorType: BaseGeneratorType.EXPO_APP });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (shouldGenerateApiClientLib) {
|
|
72
|
-
await runApiClientGenerator(tree, options);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (shouldGenerateFormUtilsLib) {
|
|
76
|
-
await runFormUtilsGenerator(tree, options);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (shouldGenerateUIKittenLib) {
|
|
80
|
-
await runUIKittenGenerator(tree, options);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Workaround: Even with the '--e2eTestRunner=none' parameter, the test folder is created. We delete it manually.
|
|
84
|
-
if (existsSync(appTestFolder)) {
|
|
85
|
-
rmSync(appTestFolder, { recursive: true, force: true });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const appPackagePath = `${appRoot}/package.json`;
|
|
89
|
-
|
|
90
|
-
// Remove unnecessary files and files that will be replaced
|
|
91
|
-
tree.delete(`${appRoot}/src`);
|
|
92
|
-
tree.delete(`${appRoot}/index.js`);
|
|
93
|
-
tree.delete(`${appRoot}/webpack.config.js`);
|
|
94
|
-
tree.delete(`${appRoot}/.eslintrc.json`);
|
|
95
|
-
tree.delete(`${appRoot}/eslint.config.cjs`);
|
|
96
|
-
tree.delete(`${appRoot}/app.json`);
|
|
97
|
-
tree.delete(`${appRoot}/eas.json`);
|
|
98
|
-
tree.delete(`${appRoot}/metro.config.js`);
|
|
99
|
-
tree.delete(`${appRoot}/jest.config.ts`);
|
|
100
|
-
tree.delete(`${appRoot}/tsconfig.app.json`);
|
|
101
|
-
|
|
102
|
-
// Update app package.json
|
|
103
|
-
const appPackageJson = readJson(tree, appPackagePath);
|
|
104
|
-
appPackageJson.main = 'expo-router/entry';
|
|
105
|
-
appPackageJson.scripts = {
|
|
106
|
-
...scripts,
|
|
107
|
-
...appPackageJson.scripts,
|
|
108
|
-
};
|
|
109
|
-
writeJson(tree, appPackagePath, appPackageJson);
|
|
110
|
-
|
|
111
|
-
// Add app files
|
|
112
|
-
generateFiles(tree, path.join(__dirname, 'app-files'), appRoot, {
|
|
113
|
-
...options,
|
|
114
|
-
formatName,
|
|
115
|
-
formatAppIdentifier,
|
|
116
|
-
formatDirectory: () => libPath,
|
|
117
|
-
isUIKittenEnabled: shouldGenerateUIKittenLib,
|
|
118
|
-
isStoreEnabled: shouldGenerateStoreLib,
|
|
119
|
-
appDirectory: options.directory
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
addNxAppTag(tree, options.directory);
|
|
123
|
-
generateFiles(tree, path.join(__dirname, 'i18n'), i18nRoot, {});
|
|
124
|
-
|
|
125
|
-
// Add dependencies
|
|
126
|
-
addDependenciesToPackageJson(
|
|
127
|
-
tree,
|
|
128
|
-
{
|
|
129
|
-
...dependencies['expo-app'],
|
|
130
|
-
...dependencies['expo-app-root']
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
...devDependencies['expo-app'],
|
|
134
|
-
...devDependencies['expo-app-root']
|
|
135
|
-
}
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
addDependenciesToPackageJson(tree, dependencies['expo-app'], devDependencies['expo-app'], appPackagePath);
|
|
139
|
-
|
|
140
|
-
await formatFiles(tree);
|
|
141
|
-
|
|
142
|
-
return () => {
|
|
143
|
-
installPackagesTask(tree);
|
|
144
|
-
execSync('npx expo install --fix', { stdio: 'inherit' });
|
|
145
|
-
|
|
146
|
-
if (shouldGenerateAuthLibs) {
|
|
147
|
-
execSync(`npx nx g auth ${options.name} ${options.directory}`, { stdio: 'inherit' });
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export default expoAppGenerator;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
'start': 'cross-env EXPO_PUBLIC_APP_ENV=development npx expo start',
|
|
3
|
-
'start:prod': 'cross-env EXPO_PUBLIC_APP_ENV=production npx expo start',
|
|
4
|
-
'build:dev': 'eas build --no-wait -p all --profile=development',
|
|
5
|
-
'build:internal': 'npm run build:dev -- --profile=internal',
|
|
6
|
-
'build:debug': 'npm run build:dev -- --profile=debug',
|
|
7
|
-
'build:prod': 'npm run build:dev -- --profile=production',
|
|
8
|
-
'update:dev': 'cross-env EXPO_PUBLIC_APP_ENV=development eas update --branch development',
|
|
9
|
-
'update:prod': 'cross-env EXPO_PUBLIC_APP_ENV=production eas update --branch production',
|
|
10
|
-
'submit:dev': 'cross-env EXPO_PUBLIC_APP_ENV=development eas submit --no-wait --profile=development',
|
|
11
|
-
'submit:prod': 'cross-env EXPO_PUBLIC_APP_ENV=production eas submit --no-wait --profile=production',
|
|
12
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { addDependenciesToPackageJson, formatFiles, generateFiles, installPackagesTask, Tree } from '@nx/devkit';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import { FormGeneratorSchema } from './schema';
|
|
4
|
-
import { dynamicImport, formatName, getNxLibsPaths, LibraryType, searchNxLibsPaths } from '../../shared/utils';
|
|
5
|
-
import { dependencies } from '../../shared/dependencies';
|
|
6
|
-
import { addFormUsage, getAppName, getFormUtilsDirectory, updateIndex } from './utils';
|
|
7
|
-
|
|
8
|
-
export async function formGenerator(tree: Tree, options: FormGeneratorSchema) {
|
|
9
|
-
// Get input data
|
|
10
|
-
const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>('inquirer-autocomplete-standalone');
|
|
11
|
-
const availableLibsPaths = getNxLibsPaths([LibraryType.FEATURES, LibraryType.UI]);
|
|
12
|
-
const libPath = await autocomplete({
|
|
13
|
-
message: 'Enter the library path: ',
|
|
14
|
-
source: async (input) => {
|
|
15
|
-
const filteredNxLibsPaths = searchNxLibsPaths(availableLibsPaths, input as string)
|
|
16
|
-
|
|
17
|
-
return filteredNxLibsPaths.map((path) => ({ value: path }))
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
const fileName = options.name;
|
|
21
|
-
const placeOfUse = options.placeOfUse;
|
|
22
|
-
|
|
23
|
-
if (!fileName) {
|
|
24
|
-
throw new Error('Form name is required');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Generate form class
|
|
28
|
-
const formsPath = `${libPath}/lib/forms`;
|
|
29
|
-
const formFilePath = `${formsPath}/${fileName}.ts`;
|
|
30
|
-
if (tree.exists(formFilePath)) {
|
|
31
|
-
throw new Error('The form already exists');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const formUtilsDirectory = await getFormUtilsDirectory(tree, getAppName(libPath));
|
|
35
|
-
const formClassName = `${formatName(fileName, true)}FormSchema`;
|
|
36
|
-
generateFiles(tree, path.join(__dirname, `files`), formsPath, { className: formClassName, fileName, formUtilsDirectory });
|
|
37
|
-
updateIndex(formsPath, fileName, tree);
|
|
38
|
-
|
|
39
|
-
// Add form usage
|
|
40
|
-
if (placeOfUse) {
|
|
41
|
-
await addFormUsage(libPath, placeOfUse, formClassName);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
await formatFiles(tree);
|
|
45
|
-
|
|
46
|
-
// Install dependencies
|
|
47
|
-
addDependenciesToPackageJson(tree, dependencies.form, {});
|
|
48
|
-
return () => {
|
|
49
|
-
installPackagesTask(tree);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export default formGenerator;
|
|
@@ -1,86 +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
|
-
if (!hasForwardRef) {
|
|
26
|
-
throw new Error('Could not find forwardRef');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const argument = callExpressionInitializer.getArguments()[0];
|
|
30
|
-
const hasComponentFunction = argument && [SyntaxKind.FunctionExpression, SyntaxKind.ArrowFunction].includes(argument.getKind())
|
|
31
|
-
if (!hasComponentFunction) {
|
|
32
|
-
throw new Error('Could not find a component function in forwardRef');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const functionExpression = argument.asKind(argument.getKind() === SyntaxKind.FunctionExpression ? SyntaxKind.FunctionExpression : SyntaxKind.ArrowFunction);
|
|
36
|
-
|
|
37
|
-
if (!functionExpression) {
|
|
38
|
-
throw new Error('Could not get a component function in forwardRef');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return functionExpression;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function getPlaceOfUse(file: SourceFile, placeOfUseName: string): FunctionExpression | ArrowFunction | FunctionDeclaration {
|
|
45
|
-
const placeOfUseFunction = file.getFunction(placeOfUseName);
|
|
46
|
-
if (placeOfUseFunction) {
|
|
47
|
-
return placeOfUseFunction;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const variable = file.getVariableDeclaration(placeOfUseName);
|
|
51
|
-
if (!variable) {
|
|
52
|
-
throw new Error(`Could not find the place where the form should be used (${placeOfUseName}).`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return variable.getInitializerIfKind(SyntaxKind.FunctionExpression)
|
|
56
|
-
|| variable.getInitializerIfKind(SyntaxKind.ArrowFunction)
|
|
57
|
-
|| getForwardRefFunction(variable);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export async function addFormUsage(libPath: string, placeOfUseName: string, formClassName: string): Promise<void> {
|
|
61
|
-
const project = new Project({
|
|
62
|
-
manipulationSettings: {
|
|
63
|
-
indentationText: IndentationText.TwoSpaces,
|
|
64
|
-
quoteKind: QuoteKind.Single
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
const files = project.addSourceFilesAtPaths([`${libPath}/lib/**/*.tsx`, `${libPath}/lib/**/*.ts`]);
|
|
68
|
-
const file = files.find((file) => file.getFunction(placeOfUseName) || file.getVariableDeclaration(placeOfUseName));
|
|
69
|
-
if (!file) {
|
|
70
|
-
throw new Error('Could not find the place where the form should be used.');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const pathToForm = file.getFilePath().includes('components')
|
|
74
|
-
? '../../forms'
|
|
75
|
-
: file.getFilePath().includes('hooks')
|
|
76
|
-
? '../forms'
|
|
77
|
-
: './forms';
|
|
78
|
-
addNamedImport(formClassName, pathToForm, file);
|
|
79
|
-
addNamedImport('useForm', 'react-hook-form', file);
|
|
80
|
-
addNamedImport('yupResolver', '@hookform/resolvers/yup', file);
|
|
81
|
-
|
|
82
|
-
const placeOfUse = getPlaceOfUse(file, placeOfUseName);
|
|
83
|
-
placeOfUse.setBodyText(`${getFormUsageCode(formClassName)}${placeOfUse.getBodyText()}`);
|
|
84
|
-
|
|
85
|
-
project.saveSync();
|
|
86
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -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 () => {
|
|
53
|
-
execSync('npx nx g lib-tags --skipRepoCheck', { stdio: 'inherit' });
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export default libMoveGenerator;
|
|
@@ -1,25 +0,0 @@
|
|
|
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;
|
|
@@ -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) {
|
|
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,68 +0,0 @@
|
|
|
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;
|