Skip to content

Commit 56c9bb1

Browse files
committed
chore: use colorette and close-with-grace
1 parent 86ea25c commit 56c9bb1

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"prepack": "npm run build",
2020
"pack": "oclif manifest && oclif readme",
2121
"postpack": "shx rm -f oclif.manifest.json",
22-
"preunit": "npm run pack",
22+
"preunit": "npm run build",
2323
"unit": "tap \"test/**/*.test.ts\"",
2424
"test": "npm run lint && npm run unit",
2525
"snap": "TAP_SNAPSHOT=1 && npm run unit"
@@ -53,8 +53,9 @@
5353
"@fastify/sensible": "^5.0.0",
5454
"@oclif/core": "^1.8.2",
5555
"@oclif/plugin-help": "^5.1.12",
56-
"ansi-colors": "^4.1.3",
5756
"chokidar": "^3.5.3",
57+
"close-with-grace": "^1.1.0",
58+
"colorette": "^2.0.17",
5859
"ejs": "^3.1.8",
5960
"fastify": "^4.0.0-rc.2",
6061
"fastify-plugin": "^3.0.0",
@@ -82,6 +83,7 @@
8283
"shx": "^0.3.4",
8384
"tap": "^16.2.0",
8485
"ts-node": "^10.7.0",
86+
"tsd": "^0.20.0",
8587
"typescript": "~4.4.0"
8688
},
8789
"oclif": {

src/utils/watch/fastify.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import C from 'ansi-colors'
1+
import { red } from 'colorette'
22
import { FastifyInstance } from 'fastify'
33
import { start, stop } from '../start'
44
import { TIMEOUT } from './constants'
55
import { GRACEFUL_SHUTDOWN, READY } from './events'
66

77
function exit (this: any): void {
8-
if (this as boolean) { console.log(C.red('[fastify-cli] process forced end')) }
8+
if (this as boolean) { console.log(red('[fastify-cli] process forced end')) }
99
process.exit(1)
1010
}
1111

@@ -15,7 +15,7 @@ let fastify: null | FastifyInstance = null
1515
process.on('message', function (event) {
1616
console.log('message', event)
1717
if (event === GRACEFUL_SHUTDOWN) {
18-
const message = C.red('[fastify-cli] process forced end')
18+
const message = red('[fastify-cli] process forced end')
1919
setTimeout(exit.bind({ message }), TIMEOUT).unref()
2020
if (fastify !== null) {
2121
fastify.close(function () {
@@ -28,8 +28,8 @@ process.on('message', function (event) {
2828
})
2929

3030
process.on('uncaughtException', function (err) {
31-
console.log(C.red(err as never as string))
32-
const message = C.red('[fastify-cli] app crashed - waiting for file changes before starting...')
31+
console.log(red(err as never as string))
32+
const message = red('[fastify-cli] app crashed - waiting for file changes before starting...')
3333
exit.bind({ message })()
3434
})
3535

src/utils/watch/watch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import C from 'ansi-colors'
21
import { ChildProcess, fork } from 'child_process'
2+
import { gray, red } from 'colorette'
33
import EventEmitter from 'events'
44
import { join, relative } from 'path'
55
import { normalizeStartOptions, StartOption } from '../start'
@@ -25,7 +25,7 @@ export async function watch (_o?: Partial<StartOption>): Promise<EventEmitter &
2525
childs = []
2626

2727
if (err !== undefined) {
28-
console.log(C.red(err))
28+
console.log(red(err))
2929
}
3030

3131
if (watcher !== undefined) {
@@ -83,15 +83,15 @@ export async function watch (_o?: Partial<StartOption>): Promise<EventEmitter &
8383
watcher.on('all', function (event, path) {
8484
console.log('watcher', event, path)
8585
if (options.watchVerbose) {
86-
console.log(C.gray(`[fastify-cli] watch - '${event}' occurred on '${relative(process.cwd(), path)}'`))
86+
console.log(gray(`[fastify-cli] watch - '${event}' occurred on '${relative(process.cwd(), path)}'`))
8787
}
8888

8989
try {
9090
const child = childs.shift()
9191
child?.send(GRACEFUL_SHUTDOWN)
9292
} catch (err: any) {
9393
if (childs.length !== 0) {
94-
console.log(C.red(err))
94+
console.log(red(err))
9595
stop(watcher, err)
9696
}
9797
childs.push(run('restart'))

0 commit comments

Comments
 (0)