@ressjs/cli 0.6.0-experimental.0

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.
Files changed (46) hide show
  1. package/bin/ress.js +2 -0
  2. package/dist/api/app.d.ts +4 -0
  3. package/dist/api/app.js +189 -0
  4. package/dist/api/build.d.ts +8 -0
  5. package/dist/api/build.js +113 -0
  6. package/dist/api/dev.d.ts +3 -0
  7. package/dist/api/dev.js +6 -0
  8. package/dist/api/errors.d.ts +37 -0
  9. package/dist/api/errors.js +119 -0
  10. package/dist/api/extend.d.ts +29 -0
  11. package/dist/api/extend.js +117 -0
  12. package/dist/api/index.d.ts +22 -0
  13. package/dist/api/index.js +16 -0
  14. package/dist/api/inspect.d.ts +75 -0
  15. package/dist/api/inspect.js +170 -0
  16. package/dist/api/options.d.ts +29 -0
  17. package/dist/api/options.js +152 -0
  18. package/dist/api/reporter.d.ts +74 -0
  19. package/dist/api/reporter.js +12 -0
  20. package/dist/api/start.d.ts +3 -0
  21. package/dist/api/start.js +6 -0
  22. package/dist/api/types.d.ts +82 -0
  23. package/dist/api/types.js +1 -0
  24. package/dist/cli/argv.d.ts +63 -0
  25. package/dist/cli/argv.js +148 -0
  26. package/dist/cli/commands/build.d.ts +2 -0
  27. package/dist/cli/commands/build.js +7 -0
  28. package/dist/cli/commands/dev.d.ts +2 -0
  29. package/dist/cli/commands/dev.js +10 -0
  30. package/dist/cli/commands/info.d.ts +2 -0
  31. package/dist/cli/commands/info.js +17 -0
  32. package/dist/cli/commands/start.d.ts +2 -0
  33. package/dist/cli/commands/start.js +10 -0
  34. package/dist/cli/main.d.ts +2 -0
  35. package/dist/cli/main.js +62 -0
  36. package/dist/cli/reporters/format.d.ts +24 -0
  37. package/dist/cli/reporters/format.js +50 -0
  38. package/dist/cli/reporters/info-format.d.ts +15 -0
  39. package/dist/cli/reporters/info-format.js +49 -0
  40. package/dist/cli/reporters/json.d.ts +12 -0
  41. package/dist/cli/reporters/json.js +13 -0
  42. package/dist/cli/reporters/terminal.d.ts +35 -0
  43. package/dist/cli/reporters/terminal.js +118 -0
  44. package/dist/cli/shutdown.d.ts +2 -0
  45. package/dist/cli/shutdown.js +17 -0
  46. package/package.json +59 -0
@@ -0,0 +1,118 @@
1
+ import { bold, cyan, detectFormatEnv, dim, formatBytes, formatDuration, green, red, yellow } from './format.js';
2
+ const LEVEL_RANK = { silent: 0, error: 1, warn: 2, info: 3, debug: 4 };
3
+ export function createTerminalReporter(opts = {}) {
4
+ const logLevel = opts.logLevel ?? 'info';
5
+ const stdout = opts.stdout ?? process.stdout;
6
+ const stderr = opts.stderr ?? process.stderr;
7
+ const env = detectFormatEnv(Boolean(stdout.isTTY), opts.env ?? process.env);
8
+ const rank = LEVEL_RANK[logLevel];
9
+ const out = (line) => {
10
+ if (rank < LEVEL_RANK.info)
11
+ return;
12
+ stdout.write(line + '\n');
13
+ };
14
+ const debugOut = (line) => {
15
+ if (rank < LEVEL_RANK.debug)
16
+ return;
17
+ stdout.write(line + '\n');
18
+ };
19
+ const warnOut = (line) => {
20
+ if (rank < LEVEL_RANK.warn)
21
+ return;
22
+ stderr.write(line + '\n');
23
+ };
24
+ // Un error no se apaga con `--log-level silent`: la regla es "nada en
25
+ // stdout", no "nada en absoluto". `silent` es para scripts que sólo miran
26
+ // el código de salida, y ese código lo produce este mismo error.
27
+ const errOut = (line) => {
28
+ stderr.write(line + '\n');
29
+ };
30
+ return {
31
+ event(e) {
32
+ formatEvent(e, env, { out, debugOut, warnOut, errOut });
33
+ },
34
+ };
35
+ }
36
+ /**
37
+ * Un caso por variante de `RessEvent`, a propósito: es lo que el test de
38
+ * reporter recorre para comprobar que ninguna se quedó sin formato.
39
+ */
40
+ export function formatEvent(e, env, sinks) {
41
+ switch (e.type) {
42
+ case 'config:loaded':
43
+ sinks.debugOut(dim(env, ` config ${e.file ?? '(sin archivo)'} ${formatDuration(e.durationMs)}`));
44
+ return;
45
+ case 'routes:scanned': {
46
+ sinks.out('');
47
+ sinks.out(bold(env, ` Rutas (${e.entries.length})`));
48
+ for (const entry of e.entries) {
49
+ sinks.out(` ${entry.pattern.padEnd(24)} ${dim(env, entry.sourceFile)}`);
50
+ }
51
+ return;
52
+ }
53
+ case 'routes:conflict':
54
+ sinks.warnOut(yellow(env, ` ⚠ conflicto de ruta ${e.pattern}: ${e.files.join(', ')}`));
55
+ return;
56
+ case 'routes:changed':
57
+ for (const file of e.added)
58
+ sinks.out(` ${timestamp()} ruta agregada ${file}`);
59
+ for (const file of e.removed)
60
+ sinks.out(` ${timestamp()} ruta eliminada ${file}`);
61
+ return;
62
+ case 'catalog:built':
63
+ sinks.out(` Variantes (${e.variants.length}) ${e.variants.join(' · ') || '(ninguna)'}`);
64
+ return;
65
+ case 'server:listening':
66
+ sinks.out('');
67
+ sinks.out(` ${bold(env, cyan(env, 'ress.js'))} modo: ${e.mode}`);
68
+ sinks.out('');
69
+ sinks.out(` ${green(env, '➜')} Local: ${e.url}`);
70
+ sinks.out('');
71
+ return;
72
+ case 'server:extended':
73
+ sinks.debugOut(dim(env, ` extensión (${e.hook}) ${e.file}`));
74
+ return;
75
+ case 'build:start':
76
+ sinks.out(` ${dim(env, '·')} construyendo ${e.target}…`);
77
+ return;
78
+ case 'build:done':
79
+ sinks.out(` ${green(env, '✓')} ${e.target.padEnd(8)} ${formatBytes(e.bytes).padStart(8)} ${formatDuration(e.durationMs)}`);
80
+ return;
81
+ case 'build:artifact':
82
+ sinks.debugOut(dim(env, ` ${e.file}`));
83
+ return;
84
+ case 'config:reload':
85
+ sinks.out(` ${timestamp()} config recargado: ${e.keys.join(', ')}`);
86
+ if (e.requiresRestart.length) {
87
+ sinks.warnOut(yellow(env, ` ${e.requiresRestart.join(', ')} requiere reinicio`));
88
+ }
89
+ return;
90
+ case 'warn':
91
+ sinks.warnOut(yellow(env, ` ⚠ ${e.message}${e.file ? ` (${e.file})` : ''}`));
92
+ return;
93
+ case 'error':
94
+ sinks.errOut(formatError(e.error, env));
95
+ return;
96
+ }
97
+ }
98
+ export function formatError(error, env) {
99
+ const lines = ['', ` ${red(env, '✖')} ${bold(env, error.title)}`, ''];
100
+ if (error.files?.length) {
101
+ for (const file of error.files)
102
+ lines.push(` ${file}`);
103
+ lines.push('');
104
+ }
105
+ if (error.reason) {
106
+ lines.push(` ${error.reason}`);
107
+ lines.push('');
108
+ }
109
+ if (error.action) {
110
+ lines.push(` ${error.action}`);
111
+ lines.push('');
112
+ }
113
+ lines.push(dim(env, ` ress.js · código ${error.code}`));
114
+ return lines.join('\n');
115
+ }
116
+ function timestamp() {
117
+ return new Date().toTimeString().slice(0, 8);
118
+ }
@@ -0,0 +1,2 @@
1
+ /** Cierre ordenado ante SIGINT/SIGTERM. Código de salida 130, siempre. */
2
+ export declare function registerShutdown(close: () => Promise<void>): void;
@@ -0,0 +1,17 @@
1
+ /** Cierre ordenado ante SIGINT/SIGTERM. Código de salida 130, siempre. */
2
+ export function registerShutdown(close) {
3
+ let closing = false;
4
+ const handler = async () => {
5
+ if (closing)
6
+ return;
7
+ closing = true;
8
+ try {
9
+ await close();
10
+ }
11
+ finally {
12
+ process.exit(130);
13
+ }
14
+ };
15
+ process.once('SIGINT', handler);
16
+ process.once('SIGTERM', handler);
17
+ }
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@ressjs/cli",
3
+ "version": "0.6.0-experimental.0",
4
+ "description": "La CLI de ress.js: dev, build, start e info sobre la misma construcción de la aplicación que expone como API.",
5
+ "type": "module",
6
+ "bin": {
7
+ "ress": "./bin/ress.js"
8
+ },
9
+ "types": "dist/api/index.d.ts",
10
+ "main": "dist/api/index.js",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/api/index.d.ts",
14
+ "require": "./dist/api/index.js",
15
+ "import": "./dist/api/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "bin"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "scripts": {
26
+ "build": "tsc",
27
+ "dev": "tsc --watch",
28
+ "clean": "rm -rf dist",
29
+ "test": "vitest run",
30
+ "test:watch": "vitest",
31
+ "prepublishOnly": "npm run build"
32
+ },
33
+ "keywords": [
34
+ "ressjs",
35
+ "cli",
36
+ "ssr",
37
+ "vite"
38
+ ],
39
+ "author": "ress.js team",
40
+ "license": "MIT",
41
+ "dependencies": {
42
+ "@ressjs/vite-router": "0.6.0-experimental.0",
43
+ "@vitejs/plugin-react": "^6.1.0",
44
+ "commander": "^12.1.0",
45
+ "express": "^5.1.0"
46
+ },
47
+ "devDependencies": {
48
+ "@types/express": "^5.0.3",
49
+ "@types/node": "^22.17.2",
50
+ "typescript": "~5.9.0",
51
+ "vitest": "^3.2.4"
52
+ },
53
+ "peerDependencies": {
54
+ "vite": "^8.0.0"
55
+ },
56
+ "engines": {
57
+ "node": ">=20.19.0"
58
+ }
59
+ }