初始化NestAPI模板

This commit is contained in:
3R-喜东东 2023-11-18 00:18:24 +08:00
commit d00d3ab968
15 changed files with 7088 additions and 0 deletions

26
.eslintignore Normal file
View File

@ -0,0 +1,26 @@
dist
back
node_modules
pnpm-lock.yaml
docker
Dockerfile*
LICENSE
yarn-error.log
.history
.vscode
.docusaurus
.dockerignore
.DS_Store
.eslintignore
.editorconfig
.gitignore
.prettierignore
.eslintcache
*.lock
**/*.svg
**/*.md
**/*.svg
**/*.ejs
**/*.html
**/*.png
**/*.toml

136
.eslintrc.js Normal file
View File

@ -0,0 +1,136 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
ecmaVersion: 'latest',
sourceType: 'module',
},
root: true,
env: {
node: true,
jest: true,
},
plugins: ['@typescript-eslint', 'jest', 'prettier', 'import', 'unused-imports'],
extends: [
// airbnb规范
// https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb
'airbnb-base',
// 兼容typescript的airbnb规范
// https://github.com/iamturns/eslint-config-airbnb-typescript
'airbnb-typescript/base',
// typescript的eslint插件
// https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/README.md
// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
// 支持jest
'plugin:jest/recommended',
// 使用prettier格式化代码
// https://github.com/prettier/eslint-config-prettier#readme
'prettier',
// 整合typescript-eslint与prettier
// https://github.com/prettier/eslint-plugin-prettier
'plugin:prettier/recommended',
],
rules: {
/* ********************************** ES6+ ********************************** */
'no-console': 0,
'no-var-requires': 0,
'no-restricted-syntax': 0,
'no-continue': 0,
'no-await-in-loop': 0,
'no-return-await': 0,
'no-unused-vars': 0,
'no-multi-assign': 0,
'no-param-reassign': [2, { props: false }],
'import/prefer-default-export': 0,
'import/no-cycle': 0,
'import/no-dynamic-require': 0,
'max-classes-per-file': 0,
'class-methods-use-this': 0,
'guard-for-in': 0,
'no-underscore-dangle': 0,
'no-plusplus': 0,
'no-lonely-if': 0,
'no-bitwise': ['error', { allow: ['~'] }],
/* ********************************** Module Import ********************************** */
'import/no-absolute-path': 0,
'import/extensions': 0,
'import/no-named-default': 0,
'no-restricted-exports': 0,
// 一部分文件在导入devDependencies的依赖时不报错
'import/no-extraneous-dependencies': [
1,
{
devDependencies: [
'**/*.test.{ts,js}',
'**/*.spec.{ts,js}',
'./test/**.{ts,js}',
'./scripts/**/*.{ts,js}',
],
},
],
// 模块导入顺序规则
'import/order': [
1,
{
pathGroups: [
{
pattern: '@/**',
group: 'external',
position: 'after',
},
],
alphabetize: { order: 'asc', caseInsensitive: false },
'newlines-between': 'always-and-inside-groups',
warnOnUnassignedImports: true,
},
],
// 自动删除未使用的导入
// https://github.com/sweepline/eslint-plugin-unused-imports
'unused-imports/no-unused-imports': 1,
'unused-imports/no-unused-vars': [
'error',
{
vars: 'all',
args: 'none',
ignoreRestSiblings: true,
},
],
/* ********************************** Typescript ********************************** */
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/no-empty-interface': 0,
'@typescript-eslint/no-this-alias': 0,
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/no-use-before-define': 0,
'@typescript-eslint/explicit-member-accessibility': 0,
'@typescript-eslint/no-non-null-assertion': 0,
'@typescript-eslint/no-unnecessary-type-assertion': 0,
'@typescript-eslint/require-await': 0,
'@typescript-eslint/no-for-in-array': 0,
'@typescript-eslint/interface-name-prefix': 0,
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/no-floating-promises': 0,
'@typescript-eslint/restrict-template-expressions': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
'@typescript-eslint/no-unsafe-return': 0,
'@typescript-eslint/no-unused-expressions': 0,
'@typescript-eslint/no-misused-promises': 0,
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/no-unsafe-call': 0,
'@typescript-eslint/no-unsafe-argument': 0,
'@typescript-eslint/ban-ts-comment': 0,
},
settings: {
extensions: ['.ts', '.d.ts', '.cts', '.mts', '.js', '.cjs', 'mjs', '.json'],
},
};

35
.gitignore vendored Normal file
View File

@ -0,0 +1,35 @@
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

26
.prettierignore Normal file
View File

@ -0,0 +1,26 @@
dist
back
node_modules
pnpm-lock.yaml
docker
Dockerfile*
LICENSE
yarn-error.log
.history
.vscode
.docusaurus
.dockerignore
.DS_Store
.eslintignore
.editorconfig
.gitignore
.prettierignore
.eslintcache
*.lock
**/*.svg
**/*.md
**/*.svg
**/*.ejs
**/*.html
**/*.png
**/*.toml

18
.prettierrc.js Normal file
View File

@ -0,0 +1,18 @@
module.exports = {
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"proseWrap": "never",
"endOfLine": "auto",
"semi": true,
"tabWidth": 4,
"overrides": [
{
"files": ".prettierrc",
"options": {
"parser": "json"
}
}
]
}

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}

56
README.md Normal file
View File

@ -0,0 +1,56 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest
<p align="center">NestJS 基础配置模板</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
## NestJS描述
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
## 安装依赖
```bash
$ pnpm install
```
## 运行 Ink NestJS API 应用
```bash
# 开发环境
$ pnpm run start
# watch mode
$ pnpm run start:dev
# production mode
$ pnpm run start:prod
```
## 适配器
http适配器使用了`fastify`
## 文档支持
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

10
nest-cli.json Normal file
View File

@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"builder": "swc",
"typeCheck": true
}
}

81
package.json Normal file
View File

@ -0,0 +1,81 @@
{
"name": "ink-nestjs-api",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^10.2.9",
"@nestjs/core": "^10.2.9",
"@nestjs/platform-fastify": "^10.2.9",
"@nestjs/swagger": "^7.1.16",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"fastify": "^4.24.3",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@nestjs/cli": "^10.2.1",
"@nestjs/schematics": "^10.0.3",
"@nestjs/testing": "^10.2.9",
"@swc/cli": "^0.1.63",
"@swc/core": "^1.3.96",
"@types/jest": "^29.5.8",
"@types/lodash": "^4.14.201",
"@types/node": "^20.9.1",
"@types/supertest": "^2.0.16",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"eslint": "^8.53.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-unused-imports": "^3.0.0",
"jest": "^29.7.0",
"prettier": "^3.1.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.2.2"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}

6614
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load Diff

10
src/app.module.ts Normal file
View File

@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { WelcomeController } from '@/modules/welcome/welcome.controller';
@Module({
imports: [],
controllers: [WelcomeController],
providers: [],
})
export class AppModule {}

17
src/main.ts Normal file
View File

@ -0,0 +1,17 @@
import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import { AppModule } from '@/app.module';
const bootstrap = async () => {
const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter(), {
cors: true,
logger: ['error', 'warn'],
});
await app.listen(2333, () => {
console.log('api: http://localhost:2333');
});
};
bootstrap();

View File

@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
/**
* 访 Ink NestJS API
*/
@Controller()
export class WelcomeController {
@Get()
getMessage(): string {
return '访问 ink nestjs api, 了解更多 请联系邮箱 youzegehq@gmail.com';
}
}

4
tsconfig.build.json Normal file
View File

@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts", "**.js"]
}

40
tsconfig.json Normal file
View File

@ -0,0 +1,40 @@
{
"compilerOptions": {
"strict": true,
"alwaysStrict": true,
"target": "esnext",
"module": "CommonJS",
"moduleResolution": "Node",
"declaration": true,
"declarationMap": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": true,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": false,
"isolatedModules": true,
"esModuleInterop": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"pretty": true,
"resolveJsonModule": true,
"allowJs": true,
"importsNotUsedAsValues": "remove",
"noEmit": false,
"lib": ["esnext", "DOM", "ScriptHost", "WebWorker"],
"baseUrl": ".",
"outDir": "./dist",
"paths": {
"@/*": ["./src/*"]
},
"types": ["@types/jest"]
},
"include": ["src", "test", "typings/**/*.d.ts", "**.js"]
}