UNPKG

1.98 kBPlain TextView Raw
1#!/usr/bin/env node
2
3var dev = require('..')
4var minimist = require('minimist')
5
6var nodeArgs = []
7
8var devArgs = process.argv.slice(2, 100)
9var unknown = []
10var 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
72var script = opts._[0]
73var scriptArgs = opts._.slice(1)
74
75opts.priorNodeArgs = []
76
77unknown.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
95if (!script) {
96 console.log('Usage: ts-node-dev [options] script [arguments]\n')
97 process.exit(1)
98}
99
100dev(script, scriptArgs, nodeArgs, opts)