Skip to content

Commit

Permalink
feat(tsx): replace nodemon with tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
wd-David committed Jun 27, 2022
1 parent 5b83675 commit 3ed6bb1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
41 changes: 41 additions & 0 deletions dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import path from 'node:path'
import { readdirSync, statSync } from 'node:fs'
import { build } from 'esbuild'
import nodemon from 'nodemon'

const getFilesRecursively = (dir: string) => {
const fileArray = []
const files = readdirSync(dir)
files.forEach((file) => {
const filePath = path.join(dir, file)
if (statSync(filePath).isDirectory()) {
getFilesRecursively(filePath)
} else {
fileArray.push(filePath)
}
})
return fileArray.filter((file) => file.endsWith('.ts'))
}

;(async () => {
const builder = await build({
entryPoints: getFilesRecursively('src'),
logLevel: 'info',
outdir: 'dist',
platform: 'node',
format: 'cjs',
incremental: true
})
nodemon('-w src -x "dist"')
.on('start', function () {
console.log('App has started')
builder.rebuild()
})
.on('quit', function () {
console.log('App has quit')
process.exit()
})
.on('restart', function (files) {
console.log('App restarted due to: ', files)
})
})()
2 changes: 2 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ build({
logLevel: 'info',
outdir: env === 'dev' ? 'dist' : 'build',
bundle: env === 'dev' ? false : true,
minify: env === 'dev' ? false : true,
platform: 'node',
format: 'cjs',
sourcemap: true,
plugins:
env === 'dev' ? [] : [esbuildPluginPino({ transports: ['pino-pretty'] })]
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.1",
"scripts": {
"prepare": "husky install",
"dev": "nodemon",
"dev": "tsx watch src",
"build": "rm -rf build && node esbuild.js",
"format": "prettier --write 'src/**/*.{js,ts,json,md}'",
"lint": "prettier --check 'src/**/*.{js,ts,json,md}' && eslint --ignore-path .gitignore .",
Expand Down
34 changes: 34 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const fastify = Fastify({
}
}
})

fastify.register(autoLoad, {
dir: join(__dirname, 'plugins')
})
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"esModuleInterop": true,
"outDir": "./dist"
}
}

0 comments on commit 3ed6bb1

Please sign in to comment.