forked from wclr/ts-node-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfg.ts
More file actions
70 lines (63 loc) · 1.98 KB
/
Copy pathcfg.ts
File metadata and controls
70 lines (63 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import fs from 'fs'
import path from 'path'
import { Options } from './bin'
import { type } from 'os'
function read(dir: string) {
const f = path.resolve(dir, '.node-dev.json')
return fs.existsSync(f) ? JSON.parse(fs.readFileSync(f, 'utf-8')) : null
}
function resolvePath(unresolvedPath: string) {
return path.resolve(process.cwd(), unresolvedPath)
}
export type Config = {
vm: boolean
fork: boolean
notify: boolean
deps: number
timestamp: number
clear: boolean
dedupe: boolean
ignore: string[]
respawn: boolean
debug: boolean
quiet: boolean
extensions: Record<string, string>
}
export const makeCfg = (main: string, opts: Partial<Options>): Config => {
const dir = main ? path.dirname(main) : '.'
const userDir = process.env.HOME || process.env.USERPROFILE
const c = read(dir) || read(process.cwd()) || (userDir && read(userDir)) || {}
c.deps = parseInt(opts['deps-level'] || '') || 0
if (typeof c.depsLevel === 'number') c.deps = c.depsLevel
if (opts) {
// Overwrite with CLI opts ...
if (opts['deps'] || opts['all-deps']) c.deps = -1
if (opts.dedupe) c.dedupe = true
if (opts.respawn) c.respawn = true
if (opts.notify === false) c.notify = false
if (opts.clear || opts.cls) c.clear = true
c.fork = opts.fork
}
const ignoreWatchItems: string[] = opts['ignore-watch']
? ([] as string[])
.concat(opts['ignore-watch'] as string)
.map((_) => _.trim())
: []
const ignoreWatch: string[] = ignoreWatchItems.concat(c.ignore || [])
opts.debug && console.log('Ignore watch:', ignoreWatch)
const ignore = ignoreWatch.concat(ignoreWatch.map(resolvePath))
return {
vm: c.vm !== false,
fork: c.fork !== false,
notify: c.notify !== false,
deps: c.deps,
timestamp: c.timestamp || (c.timestamp !== false && 'HH:MM:ss'),
clear: !!c.clear,
dedupe: !!c.dedupe,
ignore: ignore,
respawn: c.respawn || false,
debug: !!opts.debug,
quiet: !!opts.quiet,
extensions: c.extensions,
}
}