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 { dirname } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import js from "@eslint/js";
|
||||
import nxEslintPlugin from "@nx/eslint-plugin";
|
||||
import baseConfig from '../eslint.base.config.mjs';
|
||||
import { FlatCompat } from '@eslint/eslintrc';
|
||||
import { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import js from '@eslint/js';
|
||||
import nxEslintPlugin from '@nx/eslint-plugin';
|
||||
const compat = new FlatCompat({
|
||||
baseDirectory: dirname(fileURLToPath(import.meta.url)),
|
||||
recommendedConfig: js.configs.recommended,
|
||||
baseDirectory: dirname(fileURLToPath(import.meta.url)),
|
||||
recommendedConfig: js.configs.recommended,
|
||||
});
|
||||
|
||||
export default [
|
||||
{ plugins: { "@nx": nxEslintPlugin } },
|
||||
...compat.config({
|
||||
extends: [
|
||||
"plugin:@nx/typescript"
|
||||
]
|
||||
}).map(config => ({
|
||||
...config,
|
||||
files: [
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
"**/*.cts",
|
||||
"**/*.mts"
|
||||
],
|
||||
rules: {
|
||||
...config.rules
|
||||
}
|
||||
})),
|
||||
...compat.config({
|
||||
extends: [
|
||||
"plugin:@nx/javascript"
|
||||
]
|
||||
}).map(config => ({
|
||||
...config,
|
||||
files: [
|
||||
"**/*.js",
|
||||
"**/*.jsx",
|
||||
"**/*.cjs",
|
||||
"**/*.mjs"
|
||||
],
|
||||
rules: {
|
||||
...config.rules
|
||||
}
|
||||
}))
|
||||
...baseConfig,
|
||||
{
|
||||
files: ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts'],
|
||||
rules: {},
|
||||
},
|
||||
{
|
||||
files: ['**/*.js', '**/*.jsx', '**/*.cjs', '**/*.mjs'],
|
||||
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 [
|
||||
...nx.configs["flat/base"],
|
||||
...nx.configs["flat/typescript"],
|
||||
...nx.configs["flat/javascript"],
|
||||
{
|
||||
ignores: [
|
||||
"**/dist"
|
||||
]
|
||||
{
|
||||
files: ['**/*.json'],
|
||||
// Override or add rules here
|
||||
rules: {},
|
||||
languageOptions: {
|
||||
parser: await import('jsonc-eslint-parser'),
|
||||
},
|
||||
{
|
||||
files: [
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
"**/*.js",
|
||||
"**/*.jsx",
|
||||
"**/*.cjs",
|
||||
"**/*.mjs"
|
||||
],
|
||||
// Override or add rules here
|
||||
rules: {}
|
||||
}
|
||||
},
|
||||
...baseConfig,
|
||||
{
|
||||
ignores: ['**/dist'],
|
||||
},
|
||||
{
|
||||
files: [
|
||||
'**/*.ts',
|
||||
'**/*.tsx',
|
||||
'**/*.js',
|
||||
'**/*.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",
|
||||
"namedInputs": {
|
||||
"default": [
|
||||
"{projectRoot}/**/*",
|
||||
"sharedGlobals"
|
||||
],
|
||||
"default": ["{projectRoot}/**/*", "sharedGlobals"],
|
||||
"production": [
|
||||
"default",
|
||||
"!{projectRoot}/.eslintrc.json",
|
||||
@ -39,9 +36,14 @@
|
||||
"options": {
|
||||
"targetName": "test"
|
||||
},
|
||||
"exclude": [
|
||||
"e2e/**/*"
|
||||
]
|
||||
"exclude": ["e2e/**/*"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"targetDefaults": {
|
||||
"@nx/js:tsc": {
|
||||
"cache": true,
|
||||
"dependsOn": ["^build"],
|
||||
"inputs": ["production", "^production"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
"@nestjs/common": "^10.0.2",
|
||||
"@nestjs/core": "^10.0.2",
|
||||
"@nestjs/platform-express": "^10.0.2",
|
||||
"@nx/devkit": "20.4.0",
|
||||
"axios": "^1.6.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rxjs": "^7.8.0"
|
||||
@ -29,10 +30,12 @@
|
||||
"@nx/js": "20.4.0",
|
||||
"@nx/nest": "20.4.0",
|
||||
"@nx/node": "20.4.0",
|
||||
"@nx/plugin": "20.4.0",
|
||||
"@nx/web": "20.4.0",
|
||||
"@nx/webpack": "20.4.0",
|
||||
"@nx/workspace": "20.4.0",
|
||||
"@swc-node/register": "~1.9.1",
|
||||
"@swc/cli": "~0.3.12",
|
||||
"@swc/core": "~1.5.7",
|
||||
"@swc/helpers": "~0.5.11",
|
||||
"@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,
|
||||
"target": "es2015",
|
||||
"module": "esnext",
|
||||
"lib": [
|
||||
"es2020",
|
||||
"dom"
|
||||
],
|
||||
"lib": ["es2020", "dom"],
|
||||
"skipLibCheck": true,
|
||||
"skipDefaultLibCheck": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {},
|
||||
"paths": {
|
||||
"@tools/nest": ["tools/nest/src/index.ts"],
|
||||
},
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"files": [],
|
||||
@ -29,8 +28,5 @@
|
||||
"path": "./tsconfig.spec.json"
|
||||
}
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"tmp"
|
||||
]
|
||||
"exclude": ["node_modules", "tmp"]
|
||||
}
|
||||
|
Reference in New Issue
Block a user