Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Valeriano committed May 29, 2024
0 parents commit 9d4d857
Show file tree
Hide file tree
Showing 26 changed files with 6,939 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
}
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
max_line_length = 100
charset = utf-8
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
20 changes: 20 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: checks

on:
push:
branches:
- main

jobs:
run-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: yarn install
- run: yarn tsc --noEmit
- run: yarn eslint src
- run: yarn prettier src
- run: yarn test
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# output
.next
build
dist
out

# dependencies
node_modules
.pnp
.pnp.js
.yarn/install-state.gz

# tests
.nyc_output
coverage

# environment variables
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# temp directory
.temp
.tmp
temp
tmp

# ides & editors
.idea
.project
.classpath
.c9
*.launch
.settings
*.sublime-workspace

# typescript
*.tsbuildinfo

# vercel
.vercel
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx commitlint --edit $1
3 changes: 3 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npx tsc --noemit
npx lint-staged
npm run test
4 changes: 4 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"*.(ts|tsx)": ["eslint --fix", "prettier --write"],
"*.(json)": ["prettier --write"]
}
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"@mkvlrn/prettier-config"
30 changes: 30 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"module": {
"type": "es6",
"strict": true,
"strictMode": true
},
"jsc": {
"experimental": {
"keepImportAssertions": true
},
"target": "esnext",
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true,
"dynamicImport": true,
"importAssertions": true
},
"minify": {
"compress": false,
"mangle": false
},
"baseUrl": ".",
"paths": {
"#/*": ["./src/*"]
}
},
"isModule": true
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"[javascript][typescript][javascriptreact][typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.rulers": [100],
"editor.wordWrapColumn": 100,
"editor.wordWrap": "wordWrapColumn",
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
"typescript.preferences.importModuleSpecifier": "non-relative",
"typescript.suggest.paths": true,
"typescript.tsdk": "./node_modules/typescript/lib"
}
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@mkvlrn/eslint-config";
12 changes: 12 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"builder": "swc"
},
"generateOptions": {
"spec": false
}
}
56 changes: 56 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "template-nest",
"description": "A template for NestJS projects",
"version": "1.0.0",
"private": true,
"type": "module",
"author": "Mike Valeriano <mkvlrn@gmail.com>",
"repository": {
"type": "git",
"url": "git@github.com:mkvlrn/template-nest"
},
"keywords": [
"nest",
"template"
],
"scripts": {
"test": "vitest --run",
"test:cov": "rm -rf coverage && vitest run --coverage",
"prepare": "husky",
"dev": "node --import @swc-node/register/esm-register --watch src/index.ts",
"build": "rm -rf dist && nest build && find dist -type f -name '*.spec.js' -delete",
"start": "node dist"
},
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@mkvlrn/eslint-config": "^24.5.4",
"@mkvlrn/prettier-config": "^24.5.2",
"@nestjs/cli": "^10.3.2",
"@nestjs/schematics": "^10.1.1",
"@nestjs/testing": "^10.3.8",
"@swc-node/register": "^1.9.1",
"@swc/cli": "^0.3.12",
"@swc/core": "1.5.7",
"@swc/types": "^0.1.7",
"@types/express": "^4.17.21",
"@types/node": "^20.12.12",
"@types/supertest": "^6.0.2",
"@vitest/coverage-v8": "^1.6.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.5",
"supertest": "^7.0.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.11.0",
"unplugin-swc": "^1.4.5",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.6.0"
},
"dependencies": {
"@nestjs/common": "^10.3.8",
"@nestjs/core": "^10.3.8",
"@nestjs/platform-express": "^10.3.8",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1"
}
}
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# template-nest

A sane, opinionated template for nestjs projects.

Uses typescript, eslint, prettier, commitlint, vitest, lint-staged, husky, swc, and more.
29 changes: 29 additions & 0 deletions src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import supertest from 'supertest';
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
import { AppModule } from '#/app.module.js';

describe('AppController', () => {
let app: INestApplication;

beforeEach(async () => {
const module = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = module.createNestApplication();
await app.init();
});

afterEach(async () => {
await app.close();
});

test('GET /', async () => {
const response = await supertest(app.getHttpServer()).get('/');

expect(response.status).toBe(200);
expect(response.text).toBe('Hello World!');
});
});
12 changes: 12 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from '#/app.service.js';

@Controller()
export class AppController {
constructor(private appService: AppService) {}

@Get()
async getHello(): Promise<string> {
return this.appService.getHello();
}
}
11 changes: 11 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { AppController } from '#/app.controller.js';
import { AppService } from '#/app.service.js';

@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
})
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class AppModule {}
21 changes: 21 additions & 0 deletions src/app.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Test } from '@nestjs/testing';
import { beforeEach, describe, expect, test } from 'vitest';
import { AppService } from '#/app.service.js';

describe('AppService', () => {
let appService: AppService;

beforeEach(async () => {
const module = await Test.createTestingModule({
providers: [AppService],
}).compile();

appService = module.get<AppService>(AppService);
});

test('should return "Hello World!"', async () => {
const result = await appService.getHello();

expect(result).toBe('Hello World!');
});
});
8 changes: 8 additions & 0 deletions src/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
async getHello(): Promise<string> {
return 'Hello World!';
}
}
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from '#/app.module.js';

async function bootstrap(): Promise<void> {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
29 changes: 29 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"declaration": false,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"isolatedModules": true,
"lib": ["Dom", "DOM.Iterable", "ESNext", "ESNext.Decorators"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmit": true,
"outDir": "dist",
"paths": { "#/*": ["./src/*"] },
"preserveSymlinks": true,
"removeComments": true,
"resolveJsonModule": true,
"rootDir": ".",
"skipLibCheck": true,
"strict": true,
"target": "esnext"
},

"exclude": ["node_modules"],

"include": ["./src/**/*.*", "*.d.ts", "**/*.d.ts", "*.js", "*.ts"]
}
20 changes: 20 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import swc from 'unplugin-swc';
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vitest/config';

export default defineConfig({
plugins: [swc.vite({ module: { type: 'es6' } }), tsconfigPaths()],
test: {
coverage: {
reportsDirectory: 'coverage',
reporter: ['lcov', 'html', 'text'],
all: true,
include: ['src'],
exclude: ['**/*.{test,spec}.?(c|m)[jt]s?(x)', '**/*.d.ts', 'src/index.ts?(x)'],
},
env: { NODE_ENV: 'test' },
environment: 'node',
passWithNoTests: true,
setupFiles: ['./vitest.setup.ts'],
},
});
1 change: 1 addition & 0 deletions vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
Loading

0 comments on commit 9d4d857

Please sign in to comment.