tsnite 0.0.8 → 0.0.9

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,6 +4,7 @@ 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'));
9
10
  program
@@ -19,25 +20,9 @@ program
19
20
  async function handler() {
20
21
  const options = program.opts();
21
22
  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 () {
23
+ try {
40
24
  process.stdout.write('\x1Bc');
25
+ const starts = performance.now();
41
26
  fork(join(process.cwd(), entry), {
42
27
  stdio: 'inherit',
43
28
  execArgv: [
@@ -48,6 +33,39 @@ async function handler() {
48
33
  ...nodeArgs
49
34
  ]
50
35
  });
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
+ }
51
69
  });
52
70
  }
53
71
  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.9",
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
- }