feat(repo): add @tools/nest:lib generator
This commit is contained in:
parent
c6654c9abe
commit
e95117f3a9
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"eslint.validate": ["json"]
|
||||||
|
}
|
@ -1,45 +1,22 @@
|
|||||||
import { FlatCompat } from "@eslint/eslintrc";
|
import baseConfig from '../eslint.base.config.mjs';
|
||||||
import { dirname } from "path";
|
import { FlatCompat } from '@eslint/eslintrc';
|
||||||
import { fileURLToPath } from "url";
|
import { dirname } from 'path';
|
||||||
import js from "@eslint/js";
|
import { fileURLToPath } from 'url';
|
||||||
import nxEslintPlugin from "@nx/eslint-plugin";
|
import js from '@eslint/js';
|
||||||
|
import nxEslintPlugin from '@nx/eslint-plugin';
|
||||||
const compat = new FlatCompat({
|
const compat = new FlatCompat({
|
||||||
baseDirectory: dirname(fileURLToPath(import.meta.url)),
|
baseDirectory: dirname(fileURLToPath(import.meta.url)),
|
||||||
recommendedConfig: js.configs.recommended,
|
recommendedConfig: js.configs.recommended,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{ plugins: { "@nx": nxEslintPlugin } },
|
...baseConfig,
|
||||||
...compat.config({
|
{
|
||||||
extends: [
|
files: ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts'],
|
||||||
"plugin:@nx/typescript"
|
rules: {},
|
||||||
]
|
},
|
||||||
}).map(config => ({
|
{
|
||||||
...config,
|
files: ['**/*.js', '**/*.jsx', '**/*.cjs', '**/*.mjs'],
|
||||||
files: [
|
rules: {},
|
||||||
"**/*.ts",
|
},
|
||||||
"**/*.tsx",
|
|
||||||
"**/*.cts",
|
|
||||||
"**/*.mts"
|
|
||||||
],
|
|
||||||
rules: {
|
|
||||||
...config.rules
|
|
||||||
}
|
|
||||||
})),
|
|
||||||
...compat.config({
|
|
||||||
extends: [
|
|
||||||
"plugin:@nx/javascript"
|
|
||||||
]
|
|
||||||
}).map(config => ({
|
|
||||||
...config,
|
|
||||||
files: [
|
|
||||||
"**/*.js",
|
|
||||||
"**/*.jsx",
|
|
||||||
"**/*.cjs",
|
|
||||||
"**/*.mjs"
|
|
||||||
],
|
|
||||||
rules: {
|
|
||||||
...config.rules
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
];
|
];
|
||||||
|
40
eslint.base.config.mjs
Normal file
40
eslint.base.config.mjs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import nx from '@nx/eslint-plugin';
|
||||||
|
|
||||||
|
export default [
|
||||||
|
...nx.configs['flat/base'],
|
||||||
|
...nx.configs['flat/typescript'],
|
||||||
|
...nx.configs['flat/javascript'],
|
||||||
|
{
|
||||||
|
ignores: ['**/dist'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
|
||||||
|
rules: {
|
||||||
|
'@nx/enforce-module-boundaries': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
enforceBuildableLibDependency: true,
|
||||||
|
allow: ['^.*/eslint(\\.base)?\\.config\\.[cm]?js$'],
|
||||||
|
depConstraints: [
|
||||||
|
{
|
||||||
|
sourceTag: '*',
|
||||||
|
onlyDependOnLibsWithTags: ['*'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: [
|
||||||
|
'**/*.ts',
|
||||||
|
'**/*.tsx',
|
||||||
|
'**/*.js',
|
||||||
|
'**/*.jsx',
|
||||||
|
'**/*.cjs',
|
||||||
|
'**/*.mjs',
|
||||||
|
],
|
||||||
|
// Override or add rules here
|
||||||
|
rules: {},
|
||||||
|
},
|
||||||
|
];
|
@ -1,24 +1,28 @@
|
|||||||
import nx from "@nx/eslint-plugin";
|
import baseConfig from './eslint.base.config.mjs';
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
...nx.configs["flat/base"],
|
{
|
||||||
...nx.configs["flat/typescript"],
|
files: ['**/*.json'],
|
||||||
...nx.configs["flat/javascript"],
|
// Override or add rules here
|
||||||
{
|
rules: {},
|
||||||
ignores: [
|
languageOptions: {
|
||||||
"**/dist"
|
parser: await import('jsonc-eslint-parser'),
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
},
|
||||||
files: [
|
...baseConfig,
|
||||||
"**/*.ts",
|
{
|
||||||
"**/*.tsx",
|
ignores: ['**/dist'],
|
||||||
"**/*.js",
|
},
|
||||||
"**/*.jsx",
|
{
|
||||||
"**/*.cjs",
|
files: [
|
||||||
"**/*.mjs"
|
'**/*.ts',
|
||||||
],
|
'**/*.tsx',
|
||||||
// Override or add rules here
|
'**/*.js',
|
||||||
rules: {}
|
'**/*.jsx',
|
||||||
}
|
'**/*.cjs',
|
||||||
|
'**/*.mjs',
|
||||||
|
],
|
||||||
|
// Override or add rules here
|
||||||
|
rules: {},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
18
nx.json
18
nx.json
@ -1,10 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "./node_modules/nx/schemas/nx-schema.json",
|
"$schema": "./node_modules/nx/schemas/nx-schema.json",
|
||||||
"namedInputs": {
|
"namedInputs": {
|
||||||
"default": [
|
"default": ["{projectRoot}/**/*", "sharedGlobals"],
|
||||||
"{projectRoot}/**/*",
|
|
||||||
"sharedGlobals"
|
|
||||||
],
|
|
||||||
"production": [
|
"production": [
|
||||||
"default",
|
"default",
|
||||||
"!{projectRoot}/.eslintrc.json",
|
"!{projectRoot}/.eslintrc.json",
|
||||||
@ -39,9 +36,14 @@
|
|||||||
"options": {
|
"options": {
|
||||||
"targetName": "test"
|
"targetName": "test"
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": ["e2e/**/*"]
|
||||||
"e2e/**/*"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"targetDefaults": {
|
||||||
|
"@nx/js:tsc": {
|
||||||
|
"cache": true,
|
||||||
|
"dependsOn": ["^build"],
|
||||||
|
"inputs": ["production", "^production"]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
"@nestjs/common": "^10.0.2",
|
"@nestjs/common": "^10.0.2",
|
||||||
"@nestjs/core": "^10.0.2",
|
"@nestjs/core": "^10.0.2",
|
||||||
"@nestjs/platform-express": "^10.0.2",
|
"@nestjs/platform-express": "^10.0.2",
|
||||||
|
"@nx/devkit": "20.4.0",
|
||||||
"axios": "^1.6.0",
|
"axios": "^1.6.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rxjs": "^7.8.0"
|
"rxjs": "^7.8.0"
|
||||||
@ -29,10 +30,12 @@
|
|||||||
"@nx/js": "20.4.0",
|
"@nx/js": "20.4.0",
|
||||||
"@nx/nest": "20.4.0",
|
"@nx/nest": "20.4.0",
|
||||||
"@nx/node": "20.4.0",
|
"@nx/node": "20.4.0",
|
||||||
|
"@nx/plugin": "20.4.0",
|
||||||
"@nx/web": "20.4.0",
|
"@nx/web": "20.4.0",
|
||||||
"@nx/webpack": "20.4.0",
|
"@nx/webpack": "20.4.0",
|
||||||
"@nx/workspace": "20.4.0",
|
"@nx/workspace": "20.4.0",
|
||||||
"@swc-node/register": "~1.9.1",
|
"@swc-node/register": "~1.9.1",
|
||||||
|
"@swc/cli": "~0.3.12",
|
||||||
"@swc/core": "~1.5.7",
|
"@swc/core": "~1.5.7",
|
||||||
"@swc/helpers": "~0.5.11",
|
"@swc/helpers": "~0.5.11",
|
||||||
"@types/jest": "^29.5.12",
|
"@types/jest": "^29.5.12",
|
||||||
|
801
pnpm-lock.yaml
generated
801
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
11
tools/nest/README.md
Normal file
11
tools/nest/README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# nest
|
||||||
|
|
||||||
|
This library was generated with [Nx](https://nx.dev).
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
Run `nx build nest` to build the library.
|
||||||
|
|
||||||
|
## Running unit tests
|
||||||
|
|
||||||
|
Run `nx test nest` to execute the unit tests via [Jest](https://jestjs.io).
|
28
tools/nest/eslint.config.mjs
Normal file
28
tools/nest/eslint.config.mjs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import baseConfig from '../../eslint.base.config.mjs';
|
||||||
|
|
||||||
|
export default [
|
||||||
|
...baseConfig,
|
||||||
|
{
|
||||||
|
files: ['**/*.json'],
|
||||||
|
rules: {
|
||||||
|
'@nx/dependency-checks': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
languageOptions: {
|
||||||
|
parser: await import('jsonc-eslint-parser'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ['**/package.json', '**/package.json', '**/generators.json'],
|
||||||
|
rules: {
|
||||||
|
'@nx/nx-plugin-checks': 'error',
|
||||||
|
},
|
||||||
|
languageOptions: {
|
||||||
|
parser: await import('jsonc-eslint-parser'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
11
tools/nest/generators.json
Normal file
11
tools/nest/generators.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"generators": {
|
||||||
|
"library": {
|
||||||
|
"factory": "./src/generators/library/library",
|
||||||
|
"schema": "./src/generators/library/schema.json",
|
||||||
|
"aliases": ["lib"],
|
||||||
|
"x-type": "library",
|
||||||
|
"description": "Create a NestJS Library for Nx."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
tools/nest/jest.config.ts
Normal file
10
tools/nest/jest.config.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export default {
|
||||||
|
displayName: 'nest',
|
||||||
|
preset: '../../jest.preset.js',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
transform: {
|
||||||
|
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
||||||
|
},
|
||||||
|
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||||
|
coverageDirectory: '../../coverage/tools/nest',
|
||||||
|
};
|
13
tools/nest/package.json
Normal file
13
tools/nest/package.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "@tools/nest",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"type": "commonjs",
|
||||||
|
"main": "./src/index.js",
|
||||||
|
"types": "./src/index.d.ts",
|
||||||
|
"dependencies": {
|
||||||
|
"@nx/devkit": "20.4.0",
|
||||||
|
"tslib": "^2.3.0"
|
||||||
|
},
|
||||||
|
"generators": "./generators.json"
|
||||||
|
}
|
41
tools/nest/project.json
Normal file
41
tools/nest/project.json
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"name": "nest",
|
||||||
|
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||||
|
"sourceRoot": "tools/nest/src",
|
||||||
|
"projectType": "library",
|
||||||
|
"tags": [],
|
||||||
|
"targets": {
|
||||||
|
"build": {
|
||||||
|
"executor": "@nx/js:tsc",
|
||||||
|
"outputs": ["{options.outputPath}"],
|
||||||
|
"options": {
|
||||||
|
"outputPath": "dist/tools/nest",
|
||||||
|
"main": "tools/nest/src/index.ts",
|
||||||
|
"tsConfig": "tools/nest/tsconfig.lib.json",
|
||||||
|
"assets": [
|
||||||
|
"tools/nest/*.md",
|
||||||
|
{
|
||||||
|
"input": "./tools/nest/src",
|
||||||
|
"glob": "**/!(*.ts)",
|
||||||
|
"output": "./src"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"input": "./tools/nest/src",
|
||||||
|
"glob": "**/*.d.ts",
|
||||||
|
"output": "./src"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"input": "./tools/nest",
|
||||||
|
"glob": "generators.json",
|
||||||
|
"output": "."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"input": "./tools/nest",
|
||||||
|
"glob": "executors.json",
|
||||||
|
"output": "."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
tools/nest/src/generators/library/library.ts
Normal file
22
tools/nest/src/generators/library/library.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import {
|
||||||
|
Tree
|
||||||
|
} from '@nx/devkit';
|
||||||
|
import { LibGeneratorSchema } from './schema';
|
||||||
|
|
||||||
|
import { libraryGenerator } from '@nx/nest';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
export async function libGenerator(tree: Tree, options: LibGeneratorSchema) {
|
||||||
|
const opts: Parameters<(typeof libraryGenerator)>[1] = {
|
||||||
|
directory: path.join(options.directory, options.name),
|
||||||
|
name: options.name,
|
||||||
|
buildable: true,
|
||||||
|
linter: "eslint",
|
||||||
|
service: true,
|
||||||
|
strict: true,
|
||||||
|
simpleName: true,
|
||||||
|
};
|
||||||
|
await libraryGenerator(tree, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default libGenerator;
|
4
tools/nest/src/generators/library/schema.d.ts
vendored
Normal file
4
tools/nest/src/generators/library/schema.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface LibGeneratorSchema {
|
||||||
|
name: string;
|
||||||
|
directory: string;
|
||||||
|
}
|
30
tools/nest/src/generators/library/schema.json
Normal file
30
tools/nest/src/generators/library/schema.json
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json-schema.org/schema",
|
||||||
|
"$id": "Library",
|
||||||
|
"title": "Create a NestJS Library for Nx",
|
||||||
|
"description": "Create a NestJS Library for Nx.",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"directory": {
|
||||||
|
"description": "A directory where the library is placed.",
|
||||||
|
"type": "string",
|
||||||
|
"alias": "dir",
|
||||||
|
"$default": {
|
||||||
|
"$source": "argv",
|
||||||
|
"index": 0
|
||||||
|
},
|
||||||
|
"x-prompt": "Which directory do you want to create the library in?"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"description": "Library name.",
|
||||||
|
"pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$",
|
||||||
|
"type": "string",
|
||||||
|
"$default": {
|
||||||
|
"$source": "argv",
|
||||||
|
"index": 1
|
||||||
|
},
|
||||||
|
"x-prompt": "What name would you like to use?"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["directory", "name"]
|
||||||
|
}
|
16
tools/nest/tsconfig.json
Normal file
16
tools/nest/tsconfig.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs"
|
||||||
|
},
|
||||||
|
"files": [],
|
||||||
|
"include": [],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.lib.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.spec.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
10
tools/nest/tsconfig.lib.json
Normal file
10
tools/nest/tsconfig.lib.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "../../dist/out-tsc",
|
||||||
|
"declaration": true,
|
||||||
|
"types": ["node"]
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts"],
|
||||||
|
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
|
||||||
|
}
|
15
tools/nest/tsconfig.spec.json
Normal file
15
tools/nest/tsconfig.spec.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "../../dist/out-tsc",
|
||||||
|
"module": "commonjs",
|
||||||
|
"moduleResolution": "node10",
|
||||||
|
"types": ["jest", "node"]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"jest.config.ts",
|
||||||
|
"src/**/*.test.ts",
|
||||||
|
"src/**/*.spec.ts",
|
||||||
|
"src/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
@ -9,14 +9,13 @@
|
|||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"target": "es2015",
|
"target": "es2015",
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"lib": [
|
"lib": ["es2020", "dom"],
|
||||||
"es2020",
|
|
||||||
"dom"
|
|
||||||
],
|
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"skipDefaultLibCheck": true,
|
"skipDefaultLibCheck": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {},
|
"paths": {
|
||||||
|
"@tools/nest": ["tools/nest/src/index.ts"],
|
||||||
|
},
|
||||||
"esModuleInterop": true
|
"esModuleInterop": true
|
||||||
},
|
},
|
||||||
"files": [],
|
"files": [],
|
||||||
@ -29,8 +28,5 @@
|
|||||||
"path": "./tsconfig.spec.json"
|
"path": "./tsconfig.spec.json"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": ["node_modules", "tmp"]
|
||||||
"node_modules",
|
|
||||||
"tmp"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user