tsnite 0.0.8 → 0.0.10

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/README.md CHANGED
@@ -56,23 +56,6 @@ This will execute the specified TypeScript file, allowing you to quickly test an
56
56
  }
57
57
  }
58
58
  ```
59
- - **Debugging with VS Code** when debugging, you may need to configure outFiles in .vscode/launch.json to match the temporary output directory used by tsnite:
60
- Example:
61
- ```json
62
- {
63
- "version": "0.2.0",
64
- "configurations": [
65
- {
66
- //...
67
- "outFiles": [
68
- "/tmp/tsnite/**/*.js",
69
- "C:\Users\<SeuUsuario>\AppData\Local\Temp"
70
- ] // Use one or the other, first for Linux, second for Windows
71
- // ...
72
- }
73
- ]
74
- }
75
- ```
76
59
 
77
60
  ## 📚 More information
78
61
 
package/dist/cli.js CHANGED
@@ -4,8 +4,10 @@ import { join } from 'node:path';
4
4
  import { fork } from 'node:child_process';
5
5
  import { watch } from 'chokidar';
6
6
  import { createRequire } from 'node:module';
7
+ import { gradient } from './gradient.js';
7
8
  const require = createRequire(import.meta.dirname);
8
9
  const { name, description, version } = require(join(import.meta.dirname, '..', 'package.json'));
10
+ const pids = new Set();
9
11
  program
10
12
  .name(name)
11
13
  .description(description)
@@ -19,26 +21,10 @@ program
19
21
  async function handler() {
20
22
  const options = program.opts();
21
23
  const [entry, nodeArgs] = program.processedArgs;
22
- fork(join(process.cwd(), entry), {
23
- stdio: 'inherit',
24
- execArgv: [
25
- '--enable-source-maps',
26
- '--no-experimental-strip-types',
27
- '--import',
28
- join(import.meta.dirname, 'register.js'),
29
- ...nodeArgs
30
- ]
31
- });
32
- if (!options.watch)
33
- return;
34
- const watcher = watch('.', {
35
- atomic: true,
36
- ignoreInitial: true,
37
- ignored: [/.+\.(?:test|spec)\.ts$/i]
38
- });
39
- watcher.on('change', async function () {
24
+ try {
40
25
  process.stdout.write('\x1Bc');
41
- fork(join(process.cwd(), entry), {
26
+ const starts = performance.now();
27
+ const { pid } = fork(join(process.cwd(), entry), {
42
28
  stdio: 'inherit',
43
29
  execArgv: [
44
30
  '--enable-source-maps',
@@ -48,6 +34,49 @@ async function handler() {
48
34
  ...nodeArgs
49
35
  ]
50
36
  });
37
+ pids.add(pid);
38
+ const ends = performance.now();
39
+ process.stdout.write(`\x1b[1m${gradient(['#5e23e6', '#f88bc7'])(`➤ Compiled successfully in ${(ends - starts).toFixed(2)}ms`)}\x1b[0m\n`);
40
+ }
41
+ catch (error) {
42
+ process.stdout.write(`\x1b${gradient(['#cf4444', '#9b1e1e'])(`❌ Failed to compile!\n`)}\x1b[0m\n${error}`);
43
+ }
44
+ if (!options.watch)
45
+ return;
46
+ const watcher = watch('.', {
47
+ atomic: true,
48
+ ignoreInitial: true,
49
+ ignored: [/.+\.(?:test|spec)\.ts$/i]
50
+ });
51
+ watcher.on('change', async function () {
52
+ try {
53
+ process.stdout.write('\x1Bc');
54
+ for (const pid of pids.values()) {
55
+ try {
56
+ process.kill(pid);
57
+ }
58
+ catch {
59
+ //
60
+ }
61
+ }
62
+ const starts = performance.now();
63
+ const { pid } = fork(join(process.cwd(), entry), {
64
+ stdio: 'inherit',
65
+ execArgv: [
66
+ '--enable-source-maps',
67
+ '--no-experimental-strip-types',
68
+ '--import',
69
+ join(import.meta.dirname, 'register.js'),
70
+ ...nodeArgs
71
+ ]
72
+ });
73
+ pids.add(pid);
74
+ const ends = performance.now();
75
+ process.stdout.write(`\x1b[1m${gradient(['#5e23e6', '#f88bc7'])(`➤ Compiled successfully in ${(ends - starts).toFixed(2)}ms`)}\x1b[0m\n`);
76
+ }
77
+ catch (error) {
78
+ process.stdout.write(`\x1b${gradient(['#cf4444', '#9b1e1e'])(`❌ Failed to compile!\n`)}\x1b[0m\n${error}`);
79
+ }
51
80
  });
52
81
  }
53
82
  program.action(handler);
@@ -0,0 +1,36 @@
1
+ function hexToRgb(hex) {
2
+ hex = hex.replace(/^#/, '');
3
+ if (hex.length === 3) {
4
+ hex = hex
5
+ .split('')
6
+ .map((c) => c + c)
7
+ .join('');
8
+ }
9
+ const num = parseInt(hex, 16);
10
+ return [num >> 16, (num >> 8) & 255, num & 255];
11
+ }
12
+ function rgbToAnsi([r, g, b]) {
13
+ return `\x1b[38;2;${r};${g};${b}m`;
14
+ }
15
+ export function gradient(colors) {
16
+ return function (text) {
17
+ if (colors.length < 2) {
18
+ throw new Error('gradient needs at least 2 colors');
19
+ }
20
+ const segments = colors.length - 1;
21
+ const length = text.length;
22
+ let result = '';
23
+ for (let i = 0; i < length; i++) {
24
+ const pos = (i / (length - 1)) * segments;
25
+ const segIndex = Math.min(Math.floor(pos), segments - 1);
26
+ const t = pos - segIndex;
27
+ const start = hexToRgb(colors[segIndex]);
28
+ const end = hexToRgb(colors[segIndex + 1]);
29
+ const r = Math.round(start[0] + (end[0] - start[0]) * t);
30
+ const g = Math.round(start[1] + (end[1] - start[1]) * t);
31
+ const b = Math.round(start[2] + (end[2] - start[2]) * t);
32
+ result += rgbToAnsi([r, g, b]) + text[i];
33
+ }
34
+ return result + '\x1b[0m';
35
+ };
36
+ }
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "nodejs",
9
9
  "typescript"
10
10
  ],
11
- "version": "0.0.8",
11
+ "version": "0.0.10",
12
12
  "type": "module",
13
13
  "bin": {
14
14
  "tsnite": "dist/cli.js"
package/dist/sum.js DELETED
@@ -1,3 +0,0 @@
1
- export function sum(a, b) {
2
- return a + b;
3
- }