@ronas-it/nx-generators 0.10.4 → 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/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/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/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 -68
- 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 -61
- package/src/generators/form/utils/add-form-usage.ts +0 -99
- package/src/generators/form/utils/get-app-name.ts +0 -3
- package/src/generators/form/utils/get-form-utils-directory.ts +0 -59
- package/src/generators/form/utils/update-index.ts +0 -15
- package/src/generators/lib-move/generator.ts +0 -57
- package/src/generators/lib-remove/generator.ts +0 -22
- package/src/generators/lib-rename/generator.ts +0 -25
- package/src/generators/lib-tags/generator.ts +0 -66
- package/src/generators/lib-tags/interfaces/context.ts +0 -9
- package/src/generators/lib-tags/utils/check-lib-tags.ts +0 -145
- package/src/generators/next-app/generator.ts +0 -104
- 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 -43
- package/src/shared/generators/app-env/generator.ts +0 -35
- package/src/shared/generators/auth/generator.ts +0 -100
- package/src/shared/generators/form-utils/generator.ts +0 -22
- package/src/shared/generators/rn-styles/generator.ts +0 -44
- package/src/shared/generators/storage/generator.ts +0 -29
- package/src/shared/generators/store/generator.ts +0 -42
- package/src/shared/generators/ui-kitten/generator.ts +0 -51
- package/src/shared/utils/cli-utils.ts +0 -164
- package/src/shared/utils/config-utils.ts +0 -159
- package/src/shared/utils/constants.ts +0 -3
- package/src/shared/utils/dynamic-import.ts +0 -3
- package/src/shared/utils/format-utils.ts +0 -15
- package/src/shared/utils/get-lib-directory-name.ts +0 -13
- package/src/shared/utils/ts-utils.ts +0 -20
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -9
- /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,164 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as readline from 'readline';
|
|
3
|
-
import { getProjects, ProjectType, Tree } from '@nx/devkit';
|
|
4
|
-
import { constants } from './constants';
|
|
5
|
-
import { dynamicImport } from './dynamic-import';
|
|
6
|
-
|
|
7
|
-
export const createCliReadline = (): readline.Interface =>
|
|
8
|
-
readline.createInterface({
|
|
9
|
-
input: process.stdin,
|
|
10
|
-
output: process.stdout,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export const askQuestion = (
|
|
14
|
-
question: string,
|
|
15
|
-
defaultAnswer?: string,
|
|
16
|
-
cliReadline?: readline.Interface,
|
|
17
|
-
): Promise<string> => {
|
|
18
|
-
const rl = cliReadline || createCliReadline();
|
|
19
|
-
|
|
20
|
-
if (defaultAnswer) {
|
|
21
|
-
rl.write(defaultAnswer);
|
|
22
|
-
// Move cursor to end of the line
|
|
23
|
-
setTimeout(() => rl.write(null, { ctrl: true, name: 'e' }));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return new Promise((resolve) =>
|
|
27
|
-
rl.question(question, (answer) => {
|
|
28
|
-
if (!cliReadline) {
|
|
29
|
-
rl.close();
|
|
30
|
-
}
|
|
31
|
-
resolve(answer);
|
|
32
|
-
}),
|
|
33
|
-
);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export enum LibraryType {
|
|
37
|
-
UI = 'ui',
|
|
38
|
-
DATA_ACCESS = 'data-access',
|
|
39
|
-
FEATURES = 'features',
|
|
40
|
-
UTILS = 'utils',
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const parseLibsPaths = (): Record<string, Array<string>> => {
|
|
44
|
-
let tsconfig;
|
|
45
|
-
|
|
46
|
-
if (fs.existsSync('tsconfig.base.json')) {
|
|
47
|
-
tsconfig = JSON.parse(fs.readFileSync('tsconfig.base.json', 'utf8'));
|
|
48
|
-
} else {
|
|
49
|
-
tsconfig = JSON.parse(fs.readFileSync('tsconfig.json', 'utf8'));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return tsconfig.compilerOptions.paths;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const validateLibraryType = (type: string): string => {
|
|
56
|
-
const allLibraryTypes = Object.values(LibraryType);
|
|
57
|
-
|
|
58
|
-
if (!allLibraryTypes.includes(type as LibraryType)) {
|
|
59
|
-
throw new Error(`Invalid library type: ${type}.\nAvailable types: ${allLibraryTypes.join(', ')}`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return type;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const getNxLibsPaths = (types: Array<LibraryType>): Array<string> => {
|
|
66
|
-
const libs = parseLibsPaths();
|
|
67
|
-
|
|
68
|
-
return Object.values(libs)
|
|
69
|
-
.map((value) => value[0].replace('/index.ts', ''))
|
|
70
|
-
.filter((value) => types.some((type) => value.includes(type)));
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export const searchNxLibsPaths = (
|
|
74
|
-
paths: Array<string>,
|
|
75
|
-
input: string,
|
|
76
|
-
method: 'includes' | 'startsWith' | 'endsWith' = 'includes',
|
|
77
|
-
): Array<string> => {
|
|
78
|
-
return paths.filter((path) => path[method](input));
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export const searchAliasPath = (input: string): string | undefined => {
|
|
82
|
-
const libs = parseLibsPaths();
|
|
83
|
-
const path = Object.keys(libs).find((key) => libs[key][0].includes(input));
|
|
84
|
-
|
|
85
|
-
return path;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const filterSource = async (input: string, source: Array<string>): Promise<Array<{ value: string }>> => {
|
|
89
|
-
const filteredData = input
|
|
90
|
-
? source.filter((pathname) => pathname.toLowerCase().includes(input.toLowerCase()))
|
|
91
|
-
: source;
|
|
92
|
-
|
|
93
|
-
return filteredData.map((path) => ({ value: path }));
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export const appendFileContent = (path: string, endContent: string, tree: Tree): void => {
|
|
97
|
-
const content = tree.read(path, 'utf-8');
|
|
98
|
-
const contentUpdate = (content || '') + endContent;
|
|
99
|
-
|
|
100
|
-
tree.write(path, contentUpdate);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export const getProjectsDetails = (tree: Tree, projectType: ProjectType): Array<{ name: string; path: string }> =>
|
|
104
|
-
Array.from(getProjects(tree))
|
|
105
|
-
.filter(([_, project]) => project.projectType === projectType)
|
|
106
|
-
.map(([name, project]) => ({ name, path: project.root }));
|
|
107
|
-
|
|
108
|
-
export const selectProject = async (
|
|
109
|
-
tree: Tree,
|
|
110
|
-
projectType: ProjectType,
|
|
111
|
-
message: string,
|
|
112
|
-
): Promise<{ name: string; path: string }> => {
|
|
113
|
-
const { default: autocomplete } = await dynamicImport<typeof import('inquirer-autocomplete-standalone')>(
|
|
114
|
-
'inquirer-autocomplete-standalone',
|
|
115
|
-
);
|
|
116
|
-
const projects = getProjectsDetails(tree, projectType);
|
|
117
|
-
|
|
118
|
-
if (!projects.length) {
|
|
119
|
-
throw new Error(`No projects of type ${projectType} found.`);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return autocomplete({
|
|
123
|
-
message,
|
|
124
|
-
source: async (input) => {
|
|
125
|
-
const entries = [...projects, { name: constants.sharedValue, path: constants.sharedValue }].map((project) => ({
|
|
126
|
-
name: `${project.name} (${project.path})`,
|
|
127
|
-
value: { ...project, name: projectType === 'application' ? project.path.replace('apps/', '') : project.name },
|
|
128
|
-
}));
|
|
129
|
-
|
|
130
|
-
if (!input) {
|
|
131
|
-
return entries;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return entries.filter((entry) => entry.name.toLowerCase().includes(input.toLowerCase()));
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export const getLibraryDetailsByName = async (
|
|
140
|
-
tree: Tree,
|
|
141
|
-
libraryName?: string,
|
|
142
|
-
): Promise<{ name: string; path: string }> => {
|
|
143
|
-
let selectedLibraryName: string;
|
|
144
|
-
let selectedLibraryPath: string;
|
|
145
|
-
|
|
146
|
-
if (libraryName) {
|
|
147
|
-
selectedLibraryName = libraryName;
|
|
148
|
-
|
|
149
|
-
const library = getProjectsDetails(tree, 'library').find((library) => library.name === selectedLibraryName);
|
|
150
|
-
|
|
151
|
-
if (!library) {
|
|
152
|
-
throw new Error(`Library ${selectedLibraryName} not found`);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
selectedLibraryPath = library.path;
|
|
156
|
-
} else {
|
|
157
|
-
const selectedLibrary = await selectProject(tree, 'library', 'Select the library to move: ');
|
|
158
|
-
|
|
159
|
-
selectedLibraryName = selectedLibrary.name;
|
|
160
|
-
selectedLibraryPath = selectedLibrary.path;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return { name: selectedLibraryName, path: selectedLibraryPath };
|
|
164
|
-
};
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { Tree, output, readJson, writeJson } from '@nx/devkit';
|
|
2
|
-
import { isEmpty } from 'lodash';
|
|
3
|
-
|
|
4
|
-
const defaultEsLintConfigPath = '.eslintrc.json';
|
|
5
|
-
|
|
6
|
-
export interface Constraint {
|
|
7
|
-
sourceTag: string;
|
|
8
|
-
onlyDependOnLibsWithTags: Array<string>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const getNxRulesEntry = (config: Record<string, any>): { files: Array<string>; rules: Record<string, any> } =>
|
|
12
|
-
config.overrides?.find((entry: { rules: { [x: string]: any } }) => !!entry.rules['@nx/enforce-module-boundaries']);
|
|
13
|
-
|
|
14
|
-
export const getNxRulesEntryOrThrowError = (
|
|
15
|
-
config: Record<string, any>,
|
|
16
|
-
): { files: Array<string>; rules: Record<string, any> } => {
|
|
17
|
-
if (!config) {
|
|
18
|
-
throw new Error('ESLint config not found');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const entryWithRules = getNxRulesEntry(config);
|
|
22
|
-
|
|
23
|
-
if (!entryWithRules) {
|
|
24
|
-
throw new Error(`ESLint: can't find '@nx/enforce-module-boundaries' rule`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return entryWithRules;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const getNxRulesStatus = (config: Record<string, any>): string => {
|
|
31
|
-
return getNxRulesEntryOrThrowError(config).rules['@nx/enforce-module-boundaries'][0];
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const getNxRules = (config: Record<string, any>): Array<Constraint> => {
|
|
35
|
-
return getNxRulesEntryOrThrowError(config).rules['@nx/enforce-module-boundaries'][1].depConstraints;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const readESLintConfig = (tree: Tree): { config: Record<string, any>; path: string } => {
|
|
39
|
-
let path = defaultEsLintConfigPath;
|
|
40
|
-
|
|
41
|
-
const checkConfigExists = (path: string): void => {
|
|
42
|
-
if (!tree.exists(path)) {
|
|
43
|
-
throw new Error(`ESLint config not found: ${path}`);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
checkConfigExists(path);
|
|
48
|
-
|
|
49
|
-
let config = readJson(tree, path);
|
|
50
|
-
|
|
51
|
-
if (getNxRulesEntry(config)) {
|
|
52
|
-
return { config, path };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (config.extends?.length) {
|
|
56
|
-
path = config.extends[0];
|
|
57
|
-
|
|
58
|
-
checkConfigExists(path);
|
|
59
|
-
|
|
60
|
-
config = readJson(tree, config.extends[0]);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return { config, path };
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const getNpmScope = (tree: Tree): string | undefined => {
|
|
67
|
-
const { name } = tree.exists('package.json') ? readJson<{ name?: string }>(tree, 'package.json') : { name: null };
|
|
68
|
-
|
|
69
|
-
return name?.startsWith('@') ? name.split('/')[0].substring(1) : undefined;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export const addNxAppTag = (tree: Tree, appDirectory: string): void => {
|
|
73
|
-
const { config, path } = readESLintConfig(tree);
|
|
74
|
-
const constraints = getNxRules(config);
|
|
75
|
-
const doesTagExist = !!constraints.find((constraint) => constraint.sourceTag === `app:${appDirectory}`);
|
|
76
|
-
|
|
77
|
-
if (doesTagExist) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
constraints.push({
|
|
82
|
-
sourceTag: `app:${appDirectory}`,
|
|
83
|
-
onlyDependOnLibsWithTags: [`app:${appDirectory}`, 'app:shared'],
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
writeJson(tree, path, config);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export const addNxScopeTag = (tree: Tree, scope: string): void => {
|
|
90
|
-
const { config, path } = readESLintConfig(tree);
|
|
91
|
-
const constraints = getNxRules(config);
|
|
92
|
-
const doesTagExist = !!constraints.find((constraint) => constraint.sourceTag === `scope:${scope}`);
|
|
93
|
-
|
|
94
|
-
if (doesTagExist) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
constraints.push({ sourceTag: `scope:${scope}`, onlyDependOnLibsWithTags: [`scope:${scope}`, 'scope:shared'] });
|
|
99
|
-
|
|
100
|
-
writeJson(tree, path, config);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export const getImportPathPrefix = (tree: Tree): string => {
|
|
104
|
-
const npmScope = getNpmScope(tree);
|
|
105
|
-
|
|
106
|
-
return npmScope ? `${npmScope === '@' ? '' : '@'}${npmScope}` : '';
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export const verifyEsLintConfig = (tree: Tree): Record<string, any> => {
|
|
110
|
-
const { config, path } = readESLintConfig(tree);
|
|
111
|
-
const importantTags = [
|
|
112
|
-
'app:shared',
|
|
113
|
-
'scope:shared',
|
|
114
|
-
'type:app',
|
|
115
|
-
'type:data-access',
|
|
116
|
-
'type:features',
|
|
117
|
-
'type:ui',
|
|
118
|
-
'type:utils',
|
|
119
|
-
];
|
|
120
|
-
|
|
121
|
-
if (!config || isEmpty(config)) {
|
|
122
|
-
throw new Error(`Failed to load ESLint config: ${path}`);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
try {
|
|
126
|
-
const rulesEntry = getNxRulesEntryOrThrowError(config).rules['@nx/enforce-module-boundaries'];
|
|
127
|
-
const tags = rulesEntry[1].depConstraints.map((rule: Constraint) => rule.sourceTag);
|
|
128
|
-
const areRulesDisabled = rulesEntry[1].depConstraints.find(
|
|
129
|
-
(rule: Constraint) => rule.sourceTag === '*' && rule.onlyDependOnLibsWithTags.includes('*'),
|
|
130
|
-
);
|
|
131
|
-
const areRulesBroken = !importantTags.every((tag) => tags.includes(tag));
|
|
132
|
-
|
|
133
|
-
if (rulesEntry[0] !== 'error') {
|
|
134
|
-
rulesEntry[0] = 'error';
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (areRulesDisabled || areRulesBroken) {
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
139
|
-
const esLintConfigTemplate = require('../templates/config-template.json');
|
|
140
|
-
const templateRules = esLintConfigTemplate.rules['@nx/enforce-module-boundaries'];
|
|
141
|
-
|
|
142
|
-
rulesEntry[0] = templateRules[0];
|
|
143
|
-
rulesEntry[1] = templateRules[1];
|
|
144
|
-
|
|
145
|
-
writeJson(tree, path, config);
|
|
146
|
-
}
|
|
147
|
-
// TODO: use custom errors
|
|
148
|
-
} catch {
|
|
149
|
-
output.warn({ title: output.bold('ESLint config has no @nx/enforce-module-boundaries rule. Updating rules...') });
|
|
150
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
151
|
-
const esLintConfigRulesTemplate = require('../templates/config-template.json');
|
|
152
|
-
|
|
153
|
-
config.overrides.push(esLintConfigRulesTemplate);
|
|
154
|
-
|
|
155
|
-
writeJson(tree, path, config);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return config;
|
|
159
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const formatName = (value: string, withoutSpaces = false): string =>
|
|
2
|
-
value
|
|
3
|
-
.split('-')
|
|
4
|
-
.map((word) => `${word.charAt(0).toUpperCase()}${word.substring(1)}`)
|
|
5
|
-
.join(withoutSpaces ? '' : ' ');
|
|
6
|
-
|
|
7
|
-
export const formatAppIdentifier = (value: string): string => value.toLowerCase().replace(/-/g, '.');
|
|
8
|
-
|
|
9
|
-
export const getProjectName = (str: string): string => {
|
|
10
|
-
const parts = str.split('@');
|
|
11
|
-
|
|
12
|
-
return parts.length > 1 ? parts[1].split('/')[0] : parts[0];
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const getLibName = (path: string): string | undefined => path.split('/').pop();
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function getLibDirectoryName(libName: string, scopeName: string): string {
|
|
2
|
-
const libWords = libName.split('-');
|
|
3
|
-
const scopeWords = scopeName.split('-');
|
|
4
|
-
let newLibWords = libWords;
|
|
5
|
-
|
|
6
|
-
const startsWithScopeWords = scopeWords.every((word, index) => libWords[index] === word);
|
|
7
|
-
|
|
8
|
-
if (startsWithScopeWords && libWords.length > scopeWords.length) {
|
|
9
|
-
newLibWords = libWords.slice(scopeWords.length);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return newLibWords.join('-');
|
|
13
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { SourceFile } from 'ts-morph';
|
|
2
|
-
|
|
3
|
-
export const addNamedImport = (namedImport: string, moduleSpecifier: string, file: SourceFile): void => {
|
|
4
|
-
const importDeclaration = file.getImportDeclaration(moduleSpecifier);
|
|
5
|
-
|
|
6
|
-
if (importDeclaration) {
|
|
7
|
-
const hasNamedImport = importDeclaration
|
|
8
|
-
.getNamedImports()
|
|
9
|
-
.find((declaration) => declaration.getName() === namedImport);
|
|
10
|
-
|
|
11
|
-
if (!hasNamedImport) {
|
|
12
|
-
importDeclaration.addNamedImport(namedImport);
|
|
13
|
-
}
|
|
14
|
-
} else {
|
|
15
|
-
file.addImportDeclaration({
|
|
16
|
-
namedImports: [namedImport],
|
|
17
|
-
moduleSpecifier,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
};
|
package/tsconfig.json
DELETED
package/tsconfig.lib.json
DELETED
package/tsconfig.spec.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|