@eweap/nx-workspace-tools 0.0.2-2 → 0.0.2-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/dist/executors/internal-deps/internal-deps.d.ts +28 -0
- package/dist/executors/internal-deps/internal-deps.d.ts.map +1 -0
- package/dist/executors/internal-deps/internal-deps.js +221 -0
- package/dist/executors/internal-deps/schema.d.ts +3 -0
- package/dist/executors/internal-deps/schema.json +15 -0
- package/dist/generators/feature-libs/__snapshots__/ui/.storybook/styles.css +4 -0
- package/dist/generators/feature-libs/__snapshots__/ui/tsconfig.storybook.json +25 -0
- package/dist/generators/feature-libs/feature-libs.d.ts +6 -0
- package/dist/generators/feature-libs/feature-libs.d.ts.map +1 -0
- package/dist/generators/feature-libs/feature-libs.js +31 -0
- package/dist/generators/feature-libs/files/data-access/eslint.config.mjs.template +23 -0
- package/dist/generators/feature-libs/files/data-access/src/index.ts.template +1 -0
- package/dist/generators/feature-libs/files/data-access/tsconfig.spec.json.template +7 -0
- package/dist/generators/feature-libs/files/feature/eslint.config.mjs.template +23 -0
- package/dist/generators/feature-libs/files/feature/src/index.ts.template +4 -0
- package/dist/generators/feature-libs/files/feature/test-setup.ts.template +1 -0
- package/dist/generators/feature-libs/files/feature/tsconfig.spec.json.template +7 -0
- package/dist/generators/feature-libs/files/src/index.ts.template +1 -0
- package/dist/generators/feature-libs/files/types/eslint.config.mjs.template +23 -0
- package/dist/generators/feature-libs/files/types/src/__ressourceNameSingular__.ts.template +1 -0
- package/dist/generators/feature-libs/files/types/src/index.ts.template +1 -0
- package/dist/generators/feature-libs/files/ui/.storybook/main.ts.template +26 -0
- package/dist/generators/feature-libs/files/ui/.storybook/preview.ts.template +13 -0
- package/dist/generators/feature-libs/files/ui/.storybook/styles.css.template +4 -0
- package/dist/generators/feature-libs/files/ui/eslint.config.mjs.template +23 -0
- package/dist/generators/feature-libs/files/ui/src/components/index.ts.template +1 -0
- package/dist/generators/feature-libs/files/ui/src/index.ts.template +1 -0
- package/dist/generators/feature-libs/files/ui/tsconfig.spec.json.template +7 -0
- package/dist/generators/feature-libs/files/ui/tsconfig.storybook.json.template +25 -0
- package/dist/generators/feature-libs/files/util/eslint.config.mjs.template +23 -0
- package/dist/generators/feature-libs/files/util/src/index.ts.template +1 -0
- package/dist/generators/feature-libs/files/util/tsconfig.spec.json.template +7 -0
- package/dist/generators/feature-libs/patches/__snapshots__/eslint-config-mjs.patch.spec.ts.snap +27 -0
- package/dist/generators/feature-libs/patches/__snapshots__/package-json.patch.spec.ts.snap +61 -0
- package/dist/generators/feature-libs/patches/__snapshots__/tsconfig-spec-json.patch.spec.ts.snap +39 -0
- package/dist/generators/feature-libs/patches/__snapshots__/vite-config-mts.patch.spec.ts.snap +58 -0
- package/dist/generators/feature-libs/patches/eslint-config-mjs.patch.d.ts +9 -0
- package/dist/generators/feature-libs/patches/eslint-config-mjs.patch.d.ts.map +1 -0
- package/dist/generators/feature-libs/patches/eslint-config-mjs.patch.js +110 -0
- package/dist/generators/feature-libs/patches/generic.d.ts +4 -0
- package/dist/generators/feature-libs/patches/generic.d.ts.map +1 -0
- package/dist/generators/feature-libs/patches/generic.js +9 -0
- package/dist/generators/feature-libs/patches/package-json.patch.d.ts +8 -0
- package/dist/generators/feature-libs/patches/package-json.patch.d.ts.map +1 -0
- package/dist/generators/feature-libs/patches/package-json.patch.js +23 -0
- package/dist/generators/feature-libs/patches/tsconfig-spec-json.patch.d.ts +8 -0
- package/dist/generators/feature-libs/patches/tsconfig-spec-json.patch.d.ts.map +1 -0
- package/dist/generators/feature-libs/patches/tsconfig-spec-json.patch.js +19 -0
- package/dist/generators/feature-libs/patches/vite-config-mts.patch.d.ts +22 -0
- package/dist/generators/feature-libs/patches/vite-config-mts.patch.d.ts.map +1 -0
- package/dist/generators/feature-libs/patches/vite-config-mts.patch.js +47 -0
- package/dist/generators/feature-libs/schema.d.ts +18 -0
- package/dist/generators/feature-libs/schema.json +62 -0
- package/dist/generators/feature-libs/utils/context.d.ts +13 -0
- package/dist/generators/feature-libs/utils/context.d.ts.map +1 -0
- package/dist/generators/feature-libs/utils/context.js +81 -0
- package/dist/generators/feature-libs/utils/file-helpers.d.ts +4 -0
- package/dist/generators/feature-libs/utils/file-helpers.d.ts.map +1 -0
- package/dist/generators/feature-libs/utils/file-helpers.js +49 -0
- package/dist/generators/feature-libs/utils/install-storybook.d.ts +3 -0
- package/dist/generators/feature-libs/utils/install-storybook.d.ts.map +1 -0
- package/dist/generators/feature-libs/utils/install-storybook.js +12 -0
- package/dist/generators/feature-libs/utils/library-generators.d.ts +8 -0
- package/dist/generators/feature-libs/utils/library-generators.d.ts.map +1 -0
- package/dist/generators/feature-libs/utils/library-generators.js +135 -0
- package/dist/generators/feature-libs/utils/patch-file.d.ts +14 -0
- package/dist/generators/feature-libs/utils/patch-file.d.ts.map +1 -0
- package/dist/generators/feature-libs/utils/patch-file.js +28 -0
- package/dist/generators/feature-libs/utils/string-helpers.d.ts +2 -0
- package/dist/generators/feature-libs/utils/string-helpers.d.ts.map +1 -0
- package/dist/generators/feature-libs/utils/string-helpers.js +7 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/package.json +4 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`patchPackageJson > should patch the package json file with inferred task 1`] = `
|
|
4
|
+
"{
|
|
5
|
+
"name": "@test/my-ressources",
|
|
6
|
+
"version": "0.0.1",
|
|
7
|
+
"private": true,
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./src/index.ts",
|
|
15
|
+
"import": "./src/index.ts",
|
|
16
|
+
"default": "./src/index.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"nx": {
|
|
20
|
+
"name": "my-ressources",
|
|
21
|
+
"tags": [
|
|
22
|
+
"type:feature"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"tslib": "^2.3.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {}
|
|
29
|
+
}
|
|
30
|
+
"
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
exports[`patchPackageJson > should patch the package json file without inferred task 1`] = `
|
|
34
|
+
"{
|
|
35
|
+
"name": "@test/my-ressources",
|
|
36
|
+
"version": "0.0.1",
|
|
37
|
+
"private": true,
|
|
38
|
+
"type": "module",
|
|
39
|
+
"main": "./dist/index.js",
|
|
40
|
+
"module": "./dist/index.js",
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"types": "./src/index.ts",
|
|
45
|
+
"import": "./src/index.ts",
|
|
46
|
+
"default": "./src/index.ts"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"nx": {
|
|
50
|
+
"name": "my-ressources",
|
|
51
|
+
"tags": [
|
|
52
|
+
"type:feature"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"tslib": "^2.3.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {}
|
|
59
|
+
}
|
|
60
|
+
"
|
|
61
|
+
`;
|
package/dist/generators/feature-libs/patches/__snapshots__/tsconfig-spec-json.patch.spec.ts.snap
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`patchTsConfigSpec > should patch the tsconfig spec file 1`] = `
|
|
4
|
+
"{
|
|
5
|
+
"extends": "../../tsconfig.base.json",
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"outDir": "./out-tsc/vitest",
|
|
8
|
+
"types": [
|
|
9
|
+
"vitest/globals",
|
|
10
|
+
"vitest/importMeta",
|
|
11
|
+
"vite/client",
|
|
12
|
+
"node",
|
|
13
|
+
"vitest"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"include": [
|
|
17
|
+
"vite.config.ts",
|
|
18
|
+
"vite.config.mts",
|
|
19
|
+
"vitest.config.ts",
|
|
20
|
+
"vitest.config.mts",
|
|
21
|
+
"src/**/*.test.ts",
|
|
22
|
+
"src/**/*.spec.ts",
|
|
23
|
+
"src/**/*.test.tsx",
|
|
24
|
+
"src/**/*.spec.tsx",
|
|
25
|
+
"src/**/*.test.js",
|
|
26
|
+
"src/**/*.spec.js",
|
|
27
|
+
"src/**/*.test.jsx",
|
|
28
|
+
"src/**/*.spec.jsx",
|
|
29
|
+
"src/**/*.d.ts",
|
|
30
|
+
"src/**/*.vue"
|
|
31
|
+
],
|
|
32
|
+
"references": [
|
|
33
|
+
{
|
|
34
|
+
"path": "./tsconfig.lib.json"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
"
|
|
39
|
+
`;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`patchViteConfig > should patch the vite config file for lib with components 1`] = `
|
|
4
|
+
"import vue from '@vitejs/plugin-vue';
|
|
5
|
+
import { defineConfig } from 'vite';
|
|
6
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
7
|
+
export default defineConfig(() => ({
|
|
8
|
+
root: __dirname,
|
|
9
|
+
cacheDir: '../../../node_modules/.vite/libs/my-ressources',
|
|
10
|
+
plugins: [vue(), tailwindcss()],
|
|
11
|
+
// Uncomment this if you are using workers.
|
|
12
|
+
// worker: {
|
|
13
|
+
// plugins: [],
|
|
14
|
+
// },
|
|
15
|
+
test: {
|
|
16
|
+
name: 'my-ressources',
|
|
17
|
+
watch: false,
|
|
18
|
+
globals: true,
|
|
19
|
+
environment: 'jsdom',
|
|
20
|
+
setupFiles: ["test-setup.ts"],
|
|
21
|
+
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
22
|
+
reporters: ['default'],
|
|
23
|
+
coverage: {
|
|
24
|
+
reportsDirectory: './test-output/vitest/coverage',
|
|
25
|
+
provider: 'v8' as const,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
"
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
exports[`patchViteConfig > should patch the vite config file for lib without components 1`] = `
|
|
33
|
+
"import vue from '@vitejs/plugin-vue';
|
|
34
|
+
import { defineConfig } from 'vite';
|
|
35
|
+
export default defineConfig(() => ({
|
|
36
|
+
root: __dirname,
|
|
37
|
+
cacheDir: '../../../node_modules/.vite/libs/my-ressources',
|
|
38
|
+
plugins: [vue()],
|
|
39
|
+
// Uncomment this if you are using workers.
|
|
40
|
+
// worker: {
|
|
41
|
+
// plugins: [],
|
|
42
|
+
// },
|
|
43
|
+
test: {
|
|
44
|
+
name: 'my-ressources',
|
|
45
|
+
watch: false,
|
|
46
|
+
globals: true,
|
|
47
|
+
environment: 'jsdom',
|
|
48
|
+
setupFiles: ["test-setup.ts"],
|
|
49
|
+
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
50
|
+
reporters: ['default'],
|
|
51
|
+
coverage: {
|
|
52
|
+
reportsDirectory: './test-output/vitest/coverage',
|
|
53
|
+
provider: 'v8' as const,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
}));
|
|
57
|
+
"
|
|
58
|
+
`;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { LibraryContext } from '../utils/context';
|
|
3
|
+
export declare function patchCustomRules(input: {
|
|
4
|
+
tree: Tree;
|
|
5
|
+
path: string;
|
|
6
|
+
content: string;
|
|
7
|
+
}): string;
|
|
8
|
+
export declare function patchEslintConfig(tree: Tree, context: LibraryContext): void;
|
|
9
|
+
//# sourceMappingURL=eslint-config-mjs.patch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eslint-config-mjs.patch.d.ts","sourceRoot":"","sources":["../../../../src/generators/feature-libs/patches/eslint-config-mjs.patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIlC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAclD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,UAsBA;AA0ID,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,QAIpE"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.patchCustomRules = patchCustomRules;
|
|
4
|
+
exports.patchEslintConfig = patchEslintConfig;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
7
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
8
|
+
const patch_file_1 = require("../utils/patch-file");
|
|
9
|
+
const CUSTOM_RULES_EXPORT_NAME = 'customRules';
|
|
10
|
+
const ESLINT_CONFIG_FILE_NAME = 'eslint.config.mjs';
|
|
11
|
+
const ESLINT_CONFIG_IMPORT_SELECTOR = `ImportDeclaration:has(StringLiteral[text=/${ESLINT_CONFIG_FILE_NAME.replaceAll('.', '\\.')}$/])`;
|
|
12
|
+
const EXPORT_DEFAULT_ARRAY_SELECTOR = 'ExportAssignment > ArrayLiteralExpression';
|
|
13
|
+
function patchCustomRules(input) {
|
|
14
|
+
const sourceFile = ts.createSourceFile(input.path, input.content, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
15
|
+
const edits = [
|
|
16
|
+
createCustomRulesImportEdit(sourceFile, input.content),
|
|
17
|
+
createCustomRulesSpreadEdit(sourceFile, input.content),
|
|
18
|
+
];
|
|
19
|
+
return edits
|
|
20
|
+
.filter((edit) => Boolean(edit))
|
|
21
|
+
.sort((left, right) => right.position - left.position)
|
|
22
|
+
.reduce((updatedContent, edit) => `${updatedContent.slice(0, edit.position)}${edit.text}${updatedContent.slice(edit.position)}`, input.content);
|
|
23
|
+
}
|
|
24
|
+
function createCustomRulesImportEdit(sourceFile, content) {
|
|
25
|
+
const importDeclaration = (0, tsquery_1.match)(sourceFile, ESLINT_CONFIG_IMPORT_SELECTOR).find(ts.isImportDeclaration);
|
|
26
|
+
const importClause = importDeclaration?.importClause;
|
|
27
|
+
if (!importDeclaration || !importClause) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const namedBindings = importClause.namedBindings;
|
|
31
|
+
if (namedBindings && ts.isNamedImports(namedBindings)) {
|
|
32
|
+
if (namedBindings.elements.some((element) => element.name.text === CUSTOM_RULES_EXPORT_NAME)) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const closingBracePosition = namedBindings.getEnd() - 1;
|
|
36
|
+
const insertionPosition = findLastNonWhitespacePositionBefore(content, closingBracePosition);
|
|
37
|
+
const namedImportsContent = content
|
|
38
|
+
.slice(namedBindings.getStart(sourceFile) + 1, closingBracePosition)
|
|
39
|
+
.trim();
|
|
40
|
+
if (!namedImportsContent) {
|
|
41
|
+
return {
|
|
42
|
+
position: closingBracePosition,
|
|
43
|
+
text: ` ${CUSTOM_RULES_EXPORT_NAME} `,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const separator = namedImportsContent.endsWith(',') ? ' ' : ', ';
|
|
47
|
+
return {
|
|
48
|
+
position: insertionPosition + 1,
|
|
49
|
+
text: `${separator}${CUSTOM_RULES_EXPORT_NAME}`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (!importClause.name) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
position: importClause.name.getEnd(),
|
|
57
|
+
text: `, { ${CUSTOM_RULES_EXPORT_NAME} }`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function createCustomRulesSpreadEdit(sourceFile, content) {
|
|
61
|
+
const exportArray = (0, tsquery_1.match)(sourceFile, EXPORT_DEFAULT_ARRAY_SELECTOR).find((node) => ts.isArrayLiteralExpression(node) &&
|
|
62
|
+
ts.isExportAssignment(node.parent) &&
|
|
63
|
+
!node.parent.isExportEquals);
|
|
64
|
+
if (!exportArray) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
if (exportArray.elements.some((element) => ts.isSpreadElement(element) &&
|
|
68
|
+
ts.isIdentifier(element.expression) &&
|
|
69
|
+
element.expression.text === CUSTOM_RULES_EXPORT_NAME)) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const closingBracketPosition = exportArray.getEnd() - 1;
|
|
73
|
+
const openingBracketPosition = exportArray.getStart(sourceFile);
|
|
74
|
+
const openingLine = sourceFile.getLineAndCharacterOfPosition(openingBracketPosition).line;
|
|
75
|
+
const closingLine = sourceFile.getLineAndCharacterOfPosition(closingBracketPosition).line;
|
|
76
|
+
if (openingLine === closingLine) {
|
|
77
|
+
return {
|
|
78
|
+
position: closingBracketPosition,
|
|
79
|
+
text: exportArray.elements.length
|
|
80
|
+
? `, ...${CUSTOM_RULES_EXPORT_NAME}`
|
|
81
|
+
: `...${CUSTOM_RULES_EXPORT_NAME}`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const firstElement = exportArray.elements.at(0);
|
|
85
|
+
const elementIndent = firstElement
|
|
86
|
+
? getLineIndent(content, firstElement.getStart(sourceFile))
|
|
87
|
+
: `${getLineIndent(content, closingBracketPosition)} `;
|
|
88
|
+
const closingLineStart = content.lastIndexOf('\n', closingBracketPosition - 1) + 1;
|
|
89
|
+
return {
|
|
90
|
+
position: closingLineStart,
|
|
91
|
+
text: `${elementIndent}...${CUSTOM_RULES_EXPORT_NAME},\n`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function getLineIndent(content, position) {
|
|
95
|
+
const lineStart = content.lastIndexOf('\n', position - 1) + 1;
|
|
96
|
+
const indentation = /^\s*/.exec(content.slice(lineStart, position));
|
|
97
|
+
return indentation?.[0] ?? '';
|
|
98
|
+
}
|
|
99
|
+
function findLastNonWhitespacePositionBefore(content, position) {
|
|
100
|
+
for (let index = position - 1; index >= 0; index -= 1) {
|
|
101
|
+
if (!/\s/.test(content[index])) {
|
|
102
|
+
return index;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return position;
|
|
106
|
+
}
|
|
107
|
+
function patchEslintConfig(tree, context) {
|
|
108
|
+
const patches = [(0, patch_file_1.createFilePatch)(patchCustomRules)];
|
|
109
|
+
(0, patch_file_1.patchFile)(tree, `${context.projectRoot}/eslint.config.mjs`, patches);
|
|
110
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../../src/generators/feature-libs/patches/generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIlD,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,QAGlE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runGenericPatch = runGenericPatch;
|
|
4
|
+
const eslint_config_mjs_patch_1 = require("./eslint-config-mjs.patch");
|
|
5
|
+
const package_json_patch_1 = require("./package-json.patch");
|
|
6
|
+
function runGenericPatch(tree, context) {
|
|
7
|
+
(0, eslint_config_mjs_patch_1.patchEslintConfig)(tree, context);
|
|
8
|
+
(0, package_json_patch_1.patchPackageJson)(tree, context);
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { LibraryContext } from '../utils/context';
|
|
3
|
+
export declare function patchAddExports({ tree, path }: {
|
|
4
|
+
tree: Tree;
|
|
5
|
+
path: string;
|
|
6
|
+
}): void;
|
|
7
|
+
export declare function patchPackageJson(tree: Tree, context: LibraryContext): void;
|
|
8
|
+
//# sourceMappingURL=package-json.patch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json.patch.d.ts","sourceRoot":"","sources":["../../../../src/generators/feature-libs/patches/package-json.patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,wBAAgB,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,QAa3E;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,QAInE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.patchAddExports = patchAddExports;
|
|
4
|
+
exports.patchPackageJson = patchPackageJson;
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const patch_file_1 = require("../utils/patch-file");
|
|
7
|
+
function patchAddExports({ tree, path }) {
|
|
8
|
+
(0, devkit_1.updateJson)(tree, path, (pkgJson) => {
|
|
9
|
+
pkgJson.exports = {
|
|
10
|
+
'.': {
|
|
11
|
+
types: './src/index.ts',
|
|
12
|
+
import: './src/index.ts',
|
|
13
|
+
default: './src/index.ts',
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
pkgJson.devDependencies = {};
|
|
17
|
+
return pkgJson;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function patchPackageJson(tree, context) {
|
|
21
|
+
const patches = [(0, patch_file_1.createFilePatch)(patchAddExports)];
|
|
22
|
+
(0, patch_file_1.patchFile)(tree, `${context.projectRoot}/package.json`, patches);
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { LibraryContext } from '../utils/context';
|
|
3
|
+
export declare function patchVueInclude({ tree, path }: {
|
|
4
|
+
tree: Tree;
|
|
5
|
+
path: string;
|
|
6
|
+
}): void;
|
|
7
|
+
export declare function patchTsConfigSpec(tree: Tree, context: LibraryContext): void;
|
|
8
|
+
//# sourceMappingURL=tsconfig-spec-json.patch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsconfig-spec-json.patch.d.ts","sourceRoot":"","sources":["../../../../src/generators/feature-libs/patches/tsconfig-spec-json.patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,wBAAgB,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,QAU3E;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,QAIpE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.patchVueInclude = patchVueInclude;
|
|
4
|
+
exports.patchTsConfigSpec = patchTsConfigSpec;
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const patch_file_1 = require("../utils/patch-file");
|
|
7
|
+
function patchVueInclude({ tree, path }) {
|
|
8
|
+
(0, devkit_1.updateJson)(tree, path, (tsConfig) => {
|
|
9
|
+
const include = Array.isArray(tsConfig.include) ? tsConfig.include : [];
|
|
10
|
+
if (!include.includes('src/**/*.vue')) {
|
|
11
|
+
tsConfig.include = [...include, 'src/**/*.vue'];
|
|
12
|
+
}
|
|
13
|
+
return tsConfig;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function patchTsConfigSpec(tree, context) {
|
|
17
|
+
const patches = [(0, patch_file_1.createFilePatch)(patchVueInclude)];
|
|
18
|
+
(0, patch_file_1.patchFile)(tree, `${context.projectRoot}/tsconfig.spec.json`, patches);
|
|
19
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { LibraryContext } from '../utils/context';
|
|
3
|
+
export declare function patchTestSetupViteConfig(input: {
|
|
4
|
+
content: string;
|
|
5
|
+
}): string;
|
|
6
|
+
export declare function patchCacheDirViteConfig(input: {
|
|
7
|
+
content: string;
|
|
8
|
+
}, context: {
|
|
9
|
+
projectPath: string;
|
|
10
|
+
}): string;
|
|
11
|
+
export declare function patchNameViteConfig(input: {
|
|
12
|
+
content: string;
|
|
13
|
+
}, context: {
|
|
14
|
+
projectName: string;
|
|
15
|
+
}): string;
|
|
16
|
+
export declare function patchTailwindVitePluginViteConfig(input: {
|
|
17
|
+
content: string;
|
|
18
|
+
}): string;
|
|
19
|
+
export declare function patchViteConfig(tree: Tree, context: LibraryContext, options: {
|
|
20
|
+
hasComponents: boolean;
|
|
21
|
+
}): void;
|
|
22
|
+
//# sourceMappingURL=vite-config-mts.patch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-config-mts.patch.d.ts","sourceRoot":"","sources":["../../../../src/generators/feature-libs/patches/vite-config-mts.patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,UAOlE;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,EAC1B,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;CACrB,UAMF;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,EAC1B,OAAO,EAAE;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,UAMjC;AAED,wBAAgB,iCAAiC,CAAC,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,UA6B3E;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE;IAAE,aAAa,EAAE,OAAO,CAAA;CAAE,QAiBpC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.patchTestSetupViteConfig = patchTestSetupViteConfig;
|
|
4
|
+
exports.patchCacheDirViteConfig = patchCacheDirViteConfig;
|
|
5
|
+
exports.patchNameViteConfig = patchNameViteConfig;
|
|
6
|
+
exports.patchTailwindVitePluginViteConfig = patchTailwindVitePluginViteConfig;
|
|
7
|
+
exports.patchViteConfig = patchViteConfig;
|
|
8
|
+
const patch_file_1 = require("../utils/patch-file");
|
|
9
|
+
function patchTestSetupViteConfig(input) {
|
|
10
|
+
const output = input.content.replace(/(\s+environment:\s+["']jsdom["'],\n)/, '$1 setupFiles: ["test-setup.ts"],\n');
|
|
11
|
+
return output;
|
|
12
|
+
}
|
|
13
|
+
function patchCacheDirViteConfig(input, context) {
|
|
14
|
+
return input.content.replace(/^\s*cacheDir:\s*['"][^'"]+['"],$/m, ` cacheDir: '../../../node_modules/.vite/${context.projectPath}',`);
|
|
15
|
+
}
|
|
16
|
+
function patchNameViteConfig(input, context) {
|
|
17
|
+
return input.content.replace(/^\s*name:\s*['"][^'"]+['"],$/m, ` name: '${context.projectName}',`);
|
|
18
|
+
}
|
|
19
|
+
function patchTailwindVitePluginViteConfig(input) {
|
|
20
|
+
let updatedViteConfigContent = input.content;
|
|
21
|
+
if (!updatedViteConfigContent.includes("import tailwindcss from '@tailwindcss/vite';")) {
|
|
22
|
+
updatedViteConfigContent = updatedViteConfigContent.replace(/^(?:import .*\n)+/, (imports) => `${imports}import tailwindcss from '@tailwindcss/vite';\n`);
|
|
23
|
+
}
|
|
24
|
+
updatedViteConfigContent = updatedViteConfigContent.replace(/^\s*plugins:\s*\[(.*)\],$/m, (fullMatch, pluginList) => {
|
|
25
|
+
if (!pluginList.includes('vue()') ||
|
|
26
|
+
pluginList.includes('tailwindcss()')) {
|
|
27
|
+
return fullMatch;
|
|
28
|
+
}
|
|
29
|
+
return fullMatch.replace('vue()', 'vue(), tailwindcss()');
|
|
30
|
+
});
|
|
31
|
+
return updatedViteConfigContent;
|
|
32
|
+
}
|
|
33
|
+
function patchViteConfig(tree, context, options) {
|
|
34
|
+
const patches = [
|
|
35
|
+
(0, patch_file_1.createFilePatch)(patchTestSetupViteConfig),
|
|
36
|
+
(0, patch_file_1.createFilePatch)(patchCacheDirViteConfig, {
|
|
37
|
+
projectPath: context.projectRoot,
|
|
38
|
+
}),
|
|
39
|
+
(0, patch_file_1.createFilePatch)(patchNameViteConfig, {
|
|
40
|
+
projectName: context.projectName,
|
|
41
|
+
}),
|
|
42
|
+
];
|
|
43
|
+
if (options.hasComponents) {
|
|
44
|
+
patches.push((0, patch_file_1.createFilePatch)(patchTailwindVitePluginViteConfig));
|
|
45
|
+
}
|
|
46
|
+
(0, patch_file_1.patchFile)(tree, `${context.projectRoot}/vite.config.mts`, patches);
|
|
47
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface FeatureLibsGeneratorSchema {
|
|
2
|
+
/**
|
|
3
|
+
* Path where the libraries should be created
|
|
4
|
+
*/
|
|
5
|
+
libsPath: string;
|
|
6
|
+
/**
|
|
7
|
+
* Optional workspace prefix. When omitted, the generator will derive it from
|
|
8
|
+
* `package.json` using {@link getWorkspacePrefix}.
|
|
9
|
+
*/
|
|
10
|
+
workspacePrefix?: string;
|
|
11
|
+
ressourceNameSingular: string;
|
|
12
|
+
ressourceNamePlural: string;
|
|
13
|
+
libTypes: ('feature' | 'data-access' | 'ui' | 'types' | 'util')[];
|
|
14
|
+
/**
|
|
15
|
+
* Whether to create a project.json file for the generated library.
|
|
16
|
+
*/
|
|
17
|
+
useProjectJson?: boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "NxWorkspaceToolsFeatureLibsGenerator",
|
|
4
|
+
"title": "Generate feature libraries",
|
|
5
|
+
"description": "Generate a feature libraries scaffold for the workspace.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"libsPath": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The path where the libraries should be created.",
|
|
11
|
+
"$default": {
|
|
12
|
+
"$source": "argv",
|
|
13
|
+
"index": 0
|
|
14
|
+
},
|
|
15
|
+
"x-prompt": "Where should the library be placed (e.g., libs/my-ressources)?"
|
|
16
|
+
},
|
|
17
|
+
"workspacePrefix": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"description": "The workspace prefix used by libraries",
|
|
20
|
+
"$default": {
|
|
21
|
+
"$source": "argv",
|
|
22
|
+
"index": 1
|
|
23
|
+
},
|
|
24
|
+
"x-prompt": "What is the libraries workspace prefix (e.g., @my-org)?"
|
|
25
|
+
},
|
|
26
|
+
"ressourceNameSingular": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "The singular resource name to use in generated files.",
|
|
29
|
+
"$default": {
|
|
30
|
+
"$source": "argv",
|
|
31
|
+
"index": 2
|
|
32
|
+
},
|
|
33
|
+
"x-prompt": "What singular resource name would you like to use?"
|
|
34
|
+
},
|
|
35
|
+
"ressourceNamePlural": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "The plural resource name to use in generated files.",
|
|
38
|
+
"$default": {
|
|
39
|
+
"$source": "argv",
|
|
40
|
+
"index": 3
|
|
41
|
+
},
|
|
42
|
+
"x-prompt": "What plural resource name would you like to use?"
|
|
43
|
+
},
|
|
44
|
+
"libTypes": {
|
|
45
|
+
"type": "array",
|
|
46
|
+
"description": "The lib types to generate.",
|
|
47
|
+
"items": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"enum": ["feature", "data-access", "ui", "types", "util"]
|
|
50
|
+
},
|
|
51
|
+
"default": ["feature", "data-access", "ui", "types", "util"],
|
|
52
|
+
"x-prompt": "Which library types would you like to generate?"
|
|
53
|
+
},
|
|
54
|
+
"useProjectJson": {
|
|
55
|
+
"type": "boolean",
|
|
56
|
+
"description": "Create a project.json file for each generated library.",
|
|
57
|
+
"default": false,
|
|
58
|
+
"x-prompt": "Should a project.json be created?"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"required": ["libsPath", "ressourceNameSingular", "ressourceNamePlural"]
|
|
62
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FeatureLibsGeneratorSchema } from '../schema';
|
|
2
|
+
export type LibraryType = FeatureLibsGeneratorSchema['libTypes'][number];
|
|
3
|
+
export interface LibraryContext {
|
|
4
|
+
workspacePrefix: string;
|
|
5
|
+
libTypes: FeatureLibsGeneratorSchema['libTypes'];
|
|
6
|
+
projectRoot: string;
|
|
7
|
+
projectName: string;
|
|
8
|
+
packageName: string;
|
|
9
|
+
useProjectJson: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function getWorkspacePrefix(): string;
|
|
12
|
+
export declare function createLibraryContext(options: FeatureLibsGeneratorSchema, libraryType: LibraryType): LibraryContext;
|
|
13
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/generators/feature-libs/utils/context.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AAEvD,MAAM,MAAM,WAAW,GAAG,0BAA0B,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzE,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,0BAA0B,CAAC,UAAU,CAAC,CAAC;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;CACzB;AAID,wBAAgB,kBAAkB,IAAI,MAAM,CAiB3C;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,0BAA0B,EACnC,WAAW,EAAE,WAAW,GACvB,cAAc,CAuDhB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWorkspacePrefix = getWorkspacePrefix;
|
|
4
|
+
exports.createLibraryContext = createLibraryContext;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
+
const path = tslib_1.__importStar(require("path"));
|
|
8
|
+
// Detect the prefix from the root package.json. This allows the generator to
|
|
9
|
+
// automatically adapt to different monorepo names without hard‑coding.
|
|
10
|
+
function getWorkspacePrefix() {
|
|
11
|
+
// Resolve the workspace root package.json relative to this file.
|
|
12
|
+
const pkgPath = path.resolve(__dirname, '../../../../../../package.json');
|
|
13
|
+
try {
|
|
14
|
+
const raw = fs.readFileSync(pkgPath, 'utf8');
|
|
15
|
+
const { name } = JSON.parse(raw);
|
|
16
|
+
// The package name is expected to be in the form "@prefix/something".
|
|
17
|
+
if (typeof name === 'string' && name.startsWith('@')) {
|
|
18
|
+
return name.split('/')[0];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
/* fall back */
|
|
23
|
+
}
|
|
24
|
+
// No fallback: if the package.json cannot be read or parsed, let the caller
|
|
25
|
+
// handle the failure. Returning an empty string would silently break the
|
|
26
|
+
// generator.
|
|
27
|
+
throw new Error('Unable to determine workspace prefix');
|
|
28
|
+
}
|
|
29
|
+
function createLibraryContext(options, libraryType) {
|
|
30
|
+
const workspacePrefix = options.workspacePrefix ?? getWorkspacePrefix();
|
|
31
|
+
let context;
|
|
32
|
+
switch (libraryType) {
|
|
33
|
+
case 'feature':
|
|
34
|
+
context = {
|
|
35
|
+
projectRoot: `${options.libsPath}/feature`,
|
|
36
|
+
projectName: options.ressourceNamePlural,
|
|
37
|
+
packageName: `${workspacePrefix}/${options.ressourceNamePlural}`,
|
|
38
|
+
};
|
|
39
|
+
break;
|
|
40
|
+
case 'data-access':
|
|
41
|
+
context = {
|
|
42
|
+
projectRoot: `${options.libsPath}/data-access`,
|
|
43
|
+
projectName: `${options.ressourceNamePlural}-data-access`,
|
|
44
|
+
packageName: `${workspacePrefix}/${options.ressourceNamePlural}-data-access`,
|
|
45
|
+
};
|
|
46
|
+
break;
|
|
47
|
+
case 'ui':
|
|
48
|
+
context = {
|
|
49
|
+
projectRoot: `${options.libsPath}/ui`,
|
|
50
|
+
projectName: `${options.ressourceNamePlural}-ui`,
|
|
51
|
+
packageName: `${workspacePrefix}/${options.ressourceNamePlural}-ui`,
|
|
52
|
+
};
|
|
53
|
+
break;
|
|
54
|
+
case 'types':
|
|
55
|
+
context = {
|
|
56
|
+
projectRoot: `${options.libsPath}/types`,
|
|
57
|
+
projectName: `${options.ressourceNamePlural}-types`,
|
|
58
|
+
packageName: `${workspacePrefix}/${options.ressourceNamePlural}-types`,
|
|
59
|
+
};
|
|
60
|
+
break;
|
|
61
|
+
case 'util':
|
|
62
|
+
context = {
|
|
63
|
+
projectRoot: `${options.libsPath}/util`,
|
|
64
|
+
projectName: `${options.ressourceNamePlural}-util`,
|
|
65
|
+
packageName: `${workspacePrefix}/${options.ressourceNamePlural}-util`,
|
|
66
|
+
};
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
// This should never happen because libraryType is constrained by
|
|
70
|
+
// FeatureLibsGeneratorSchema['libTypes'][number]. Adding a default keeps
|
|
71
|
+
// TypeScript happy and provides a clear error if an unexpected value
|
|
72
|
+
// slips through.
|
|
73
|
+
throw new Error(`Unsupported library type: ${libraryType}`);
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
...context,
|
|
77
|
+
workspacePrefix,
|
|
78
|
+
libTypes: options.libTypes,
|
|
79
|
+
useProjectJson: options.useProjectJson ?? false,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { LibraryContext } from './context';
|
|
3
|
+
export declare function addInternalDepsToPackageJson(tree: Tree, { projectRoot, projectName, packageName, libTypes, workspacePrefix, }: LibraryContext): void;
|
|
4
|
+
//# sourceMappingURL=file-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-helpers.d.ts","sourceRoot":"","sources":["../../../../src/generators/feature-libs/utils/file-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AA0B3C,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,IAAI,EACV,EACE,WAAW,EACX,WAAW,EACX,WAAW,EACX,QAAQ,EACR,eAAe,GAChB,EAAE,cAAc,QAoDlB"}
|