1 | #!/usr/bin/env node
|
2 |
|
3 | var dev = require('..')
|
4 | var minimist = require('minimist')
|
5 |
|
6 | var nodeArgs = []
|
7 |
|
8 | var devArgs = process.argv.slice(2, 100)
|
9 | var unknown = []
|
10 | var opts = minimist(devArgs, {
|
11 | stopEarly: true,
|
12 | boolean: [
|
13 | 'all-deps',
|
14 | 'deps',
|
15 | 'dedupe',
|
16 | 'poll',
|
17 | 'respawn',
|
18 | 'notify',
|
19 | 'tree-kill',
|
20 | 'clear',
|
21 | 'cls',
|
22 | 'exit-child',
|
23 | 'error-recompile',
|
24 | // ts-node
|
25 | 'scope',
|
26 | 'emit',
|
27 | 'files',
|
28 | 'pretty',
|
29 | 'transpile-only',
|
30 | 'prefer-ts-exts',
|
31 | 'prefer-ts',
|
32 | 'exec-check',
|
33 | 'debug',
|
34 | 'log-error',
|
35 | 'skip-project',
|
36 | 'skip-ignore',
|
37 | 'compiler-host',
|
38 | 'script-mode',
|
39 | 'rs'
|
40 | ],
|
41 | string: [
|
42 | 'dir',
|
43 | 'compile-timeout',
|
44 | 'ignore-watch',
|
45 | 'interval',
|
46 | 'debounce',
|
47 | 'watch',
|
48 | // ts-node
|
49 | 'compiler',
|
50 | 'project',
|
51 | 'ignore',
|
52 | 'ignore-diagnostics',
|
53 | 'compiler-options',
|
54 | ],
|
55 | alias: {
|
56 | 'transpile-only': 'T',
|
57 | 'compiler-host': 'H',
|
58 | ignore: 'I',
|
59 | 'ignore-diagnostics': 'D',
|
60 | 'compiler-options': 'O',
|
61 | compiler: 'C',
|
62 | project: 'P',
|
63 | 'script-mode': 's'
|
64 | },
|
65 | default: { deps: false, notify: true, rs: false, 'type-check': true },
|
66 | unknown: function (arg) {
|
67 | unknown.push(arg)
|
68 | return true
|
69 | },
|
70 | })
|
71 |
|
72 | var script = opts._[0]
|
73 | var scriptArgs = opts._.slice(1)
|
74 |
|
75 | opts.priorNodeArgs = []
|
76 |
|
77 | unknown.forEach(function (arg) {
|
78 | if (arg === script || nodeArgs.indexOf(arg) >= 0) return
|
79 |
|
80 | var argName = arg.replace(/^-+/, '')
|
81 | var argOpts = opts[argName]
|
82 | var argValues = Array.isArray(argOpts) ? argOpts : [argOpts]
|
83 | argValues.forEach(function (argValue) {
|
84 | if ((arg === '-r' || arg === '--require') && argValue === 'esm') {
|
85 | opts.priorNodeArgs.push(arg, argValue)
|
86 | return false
|
87 | }
|
88 | nodeArgs.push(arg)
|
89 | if (typeof argValue === 'string') {
|
90 | nodeArgs.push(argValue)
|
91 | }
|
92 | })
|
93 | })
|
94 |
|
95 | if (!script) {
|
96 | console.log('Usage: ts-node-dev [options] script [arguments]\n')
|
97 | process.exit(1)
|
98 | }
|
99 |
|
100 | dev(script, scriptArgs, nodeArgs, opts)
|