tsnite 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +20 -37
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { program } from 'commander';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
4
5
|
import { fork } from 'node:child_process';
|
|
5
6
|
import { watch } from 'chokidar';
|
|
6
7
|
import { createRequire } from 'node:module';
|
|
7
|
-
import { gradient } from './gradient.js';
|
|
8
8
|
const require = createRequire(import.meta.dirname);
|
|
9
9
|
const { name, description, version } = require(join(import.meta.dirname, '..', 'package.json'));
|
|
10
10
|
program
|
|
@@ -20,52 +20,35 @@ program
|
|
|
20
20
|
async function handler() {
|
|
21
21
|
const options = program.opts();
|
|
22
22
|
const [entry, nodeArgs] = program.processedArgs;
|
|
23
|
-
|
|
23
|
+
fork(join(process.cwd(), entry), {
|
|
24
|
+
stdio: 'inherit',
|
|
25
|
+
execArgv: [
|
|
26
|
+
'--enable-source-maps',
|
|
27
|
+
'--no-experimental-strip-types',
|
|
28
|
+
'--import',
|
|
29
|
+
pathToFileURL(join(import.meta.dirname, 'register.js')).href,
|
|
30
|
+
...nodeArgs
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
if (!options.watch)
|
|
34
|
+
return;
|
|
35
|
+
const watcher = watch('.', {
|
|
36
|
+
atomic: true,
|
|
37
|
+
ignoreInitial: true,
|
|
38
|
+
ignored: [/.+\.(?:test|spec)\.ts$/i]
|
|
39
|
+
});
|
|
40
|
+
watcher.on('change', async function () {
|
|
24
41
|
process.stdout.write('\x1Bc');
|
|
25
|
-
const starts = performance.now();
|
|
26
42
|
fork(join(process.cwd(), entry), {
|
|
27
43
|
stdio: 'inherit',
|
|
28
44
|
execArgv: [
|
|
29
45
|
'--enable-source-maps',
|
|
30
46
|
'--no-experimental-strip-types',
|
|
31
47
|
'--import',
|
|
32
|
-
join(import.meta.dirname, 'register.js'),
|
|
48
|
+
pathToFileURL(join(import.meta.dirname, 'register.js')).href,
|
|
33
49
|
...nodeArgs
|
|
34
50
|
]
|
|
35
51
|
});
|
|
36
|
-
const ends = performance.now();
|
|
37
|
-
process.stdout.write(`\x1b[1m${gradient(['#5e23e6', '#f88bc7'])(`➤ Compiled successfully in ${(ends - starts).toFixed(2)}ms`)}\x1b[0m\n`);
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
process.stdout.write(`\x1b${gradient(['#cf4444', '#9b1e1e'])(`❌ Failed to compile!\n`)}\x1b[0m\n${error}`);
|
|
41
|
-
}
|
|
42
|
-
if (!options.watch)
|
|
43
|
-
return;
|
|
44
|
-
const watcher = watch('.', {
|
|
45
|
-
atomic: true,
|
|
46
|
-
ignoreInitial: true,
|
|
47
|
-
ignored: [/.+\.(?:test|spec)\.ts$/i]
|
|
48
|
-
});
|
|
49
|
-
watcher.on('change', async function () {
|
|
50
|
-
try {
|
|
51
|
-
process.stdout.write('\x1Bc');
|
|
52
|
-
const starts = performance.now();
|
|
53
|
-
fork(join(process.cwd(), entry), {
|
|
54
|
-
stdio: 'inherit',
|
|
55
|
-
execArgv: [
|
|
56
|
-
'--enable-source-maps',
|
|
57
|
-
'--no-experimental-strip-types',
|
|
58
|
-
'--import',
|
|
59
|
-
join(import.meta.dirname, 'register.js'),
|
|
60
|
-
...nodeArgs
|
|
61
|
-
]
|
|
62
|
-
});
|
|
63
|
-
const ends = performance.now();
|
|
64
|
-
process.stdout.write(`\x1b[1m${gradient(['#5e23e6', '#f88bc7'])(`➤ Compiled successfully in ${(ends - starts).toFixed(2)}ms`)}\x1b[0m\n`);
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
process.stdout.write(`\x1b${gradient(['#cf4444', '#9b1e1e'])(`❌ Failed to compile!\n`)}\x1b[0m\n${error}`);
|
|
68
|
-
}
|
|
69
52
|
});
|
|
70
53
|
}
|
|
71
54
|
program.action(handler);
|