zero-query 1.0.9 → 1.2.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.
- package/LICENSE +21 -21
- package/README.md +2 -0
- package/cli/args.js +33 -33
- package/cli/commands/build-api.js +443 -0
- package/cli/commands/build.js +254 -216
- package/cli/commands/bundle.js +1228 -1183
- package/cli/commands/create.js +137 -121
- package/cli/commands/dev/devtools/index.js +56 -56
- package/cli/commands/dev/devtools/js/components.js +49 -49
- package/cli/commands/dev/devtools/js/core.js +423 -423
- package/cli/commands/dev/devtools/js/elements.js +421 -421
- package/cli/commands/dev/devtools/js/network.js +166 -166
- package/cli/commands/dev/devtools/js/performance.js +73 -73
- package/cli/commands/dev/devtools/js/router.js +105 -105
- package/cli/commands/dev/devtools/js/source.js +132 -132
- package/cli/commands/dev/devtools/js/stats.js +35 -35
- package/cli/commands/dev/devtools/js/tabs.js +79 -79
- package/cli/commands/dev/devtools/panel.html +95 -95
- package/cli/commands/dev/devtools/styles.css +244 -244
- package/cli/commands/dev/index.js +107 -107
- package/cli/commands/dev/logger.js +75 -75
- package/cli/commands/dev/overlay.js +858 -858
- package/cli/commands/dev/server.js +220 -167
- package/cli/commands/dev/validator.js +94 -94
- package/cli/commands/dev/watcher.js +172 -172
- package/cli/help.js +114 -112
- package/cli/index.js +52 -52
- package/cli/scaffold/default/LICENSE +21 -21
- package/cli/scaffold/default/app/app.js +207 -207
- package/cli/scaffold/default/app/components/about.js +201 -201
- package/cli/scaffold/default/app/components/api-demo.js +143 -143
- package/cli/scaffold/default/app/components/contact-card.js +231 -231
- package/cli/scaffold/default/app/components/contacts/contacts.css +706 -706
- package/cli/scaffold/default/app/components/contacts/contacts.html +200 -200
- package/cli/scaffold/default/app/components/contacts/contacts.js +196 -196
- package/cli/scaffold/default/app/components/counter.js +127 -127
- package/cli/scaffold/default/app/components/home.js +249 -249
- package/cli/scaffold/default/app/components/not-found.js +16 -16
- package/cli/scaffold/default/app/components/playground/playground.css +115 -115
- package/cli/scaffold/default/app/components/playground/playground.html +161 -161
- package/cli/scaffold/default/app/components/playground/playground.js +116 -116
- package/cli/scaffold/default/app/components/todos.js +225 -225
- package/cli/scaffold/default/app/components/toolkit/toolkit.css +97 -97
- package/cli/scaffold/default/app/components/toolkit/toolkit.html +146 -146
- package/cli/scaffold/default/app/components/toolkit/toolkit.js +280 -280
- package/cli/scaffold/default/app/routes.js +15 -15
- package/cli/scaffold/default/app/store.js +101 -101
- package/cli/scaffold/default/global.css +552 -552
- package/cli/scaffold/default/index.html +99 -99
- package/cli/scaffold/minimal/app/app.js +85 -85
- package/cli/scaffold/minimal/app/components/about.js +68 -68
- package/cli/scaffold/minimal/app/components/counter.js +122 -122
- package/cli/scaffold/minimal/app/components/home.js +68 -68
- package/cli/scaffold/minimal/app/components/not-found.js +16 -16
- package/cli/scaffold/minimal/app/routes.js +9 -9
- package/cli/scaffold/minimal/app/store.js +36 -36
- package/cli/scaffold/minimal/global.css +300 -300
- package/cli/scaffold/minimal/index.html +44 -44
- package/cli/scaffold/ssr/app/app.js +41 -41
- package/cli/scaffold/ssr/app/components/about.js +55 -55
- package/cli/scaffold/ssr/app/components/blog/index.js +65 -65
- package/cli/scaffold/ssr/app/components/blog/post.js +86 -86
- package/cli/scaffold/ssr/app/components/home.js +37 -37
- package/cli/scaffold/ssr/app/components/not-found.js +15 -15
- package/cli/scaffold/ssr/app/routes.js +8 -8
- package/cli/scaffold/ssr/global.css +228 -228
- package/cli/scaffold/ssr/index.html +37 -37
- package/cli/scaffold/ssr/package.json +8 -8
- package/cli/scaffold/ssr/server/data/posts.js +144 -144
- package/cli/scaffold/ssr/server/index.js +213 -213
- package/cli/scaffold/webrtc/app/app.js +11 -0
- package/cli/scaffold/webrtc/app/components/video-room.js +295 -0
- package/cli/scaffold/webrtc/app/lib/room.js +252 -0
- package/cli/scaffold/webrtc/assets/.gitkeep +0 -0
- package/cli/scaffold/webrtc/global.css +250 -0
- package/cli/scaffold/webrtc/index.html +21 -0
- package/cli/utils.js +305 -287
- package/dist/API.md +7264 -0
- package/dist/zquery.dist.zip +0 -0
- package/dist/zquery.js +10313 -6252
- package/dist/zquery.min.js +8 -601
- package/index.d.ts +570 -365
- package/index.js +311 -232
- package/package.json +76 -69
- package/src/component.js +1709 -1454
- package/src/core.js +921 -921
- package/src/diff.js +497 -497
- package/src/errors.js +209 -209
- package/src/expression.js +922 -922
- package/src/http.js +242 -242
- package/src/package.json +1 -1
- package/src/reactive.js +255 -254
- package/src/router.js +843 -773
- package/src/ssr.js +418 -418
- package/src/store.js +318 -272
- package/src/utils.js +515 -515
- package/src/webrtc/e2ee.js +351 -0
- package/src/webrtc/errors.js +116 -0
- package/src/webrtc/ice.js +301 -0
- package/src/webrtc/index.js +131 -0
- package/src/webrtc/joinToken.js +119 -0
- package/src/webrtc/observe.js +172 -0
- package/src/webrtc/peer.js +351 -0
- package/src/webrtc/reactive.js +268 -0
- package/src/webrtc/room.js +625 -0
- package/src/webrtc/sdp.js +302 -0
- package/src/webrtc/sfu/index.js +43 -0
- package/src/webrtc/sfu/livekit.js +131 -0
- package/src/webrtc/sfu/mediasoup.js +150 -0
- package/src/webrtc/signaling.js +373 -0
- package/src/webrtc/turn.js +237 -0
- package/tests/_helpers/webrtcFakes.js +289 -0
- package/tests/audit.test.js +4158 -4158
- package/tests/cli.test.js +1136 -1023
- package/tests/compare.test.js +497 -0
- package/tests/component.test.js +3969 -3938
- package/tests/core.test.js +1910 -1910
- package/tests/dev-server.test.js +489 -0
- package/tests/diff.test.js +1416 -1416
- package/tests/docs.test.js +1664 -0
- package/tests/electron-features.test.js +864 -0
- package/tests/errors.test.js +619 -619
- package/tests/expression.test.js +1056 -1056
- package/tests/http.test.js +648 -648
- package/tests/reactive.test.js +819 -819
- package/tests/router.test.js +2327 -2327
- package/tests/ssr.test.js +870 -870
- package/tests/store.test.js +830 -830
- package/tests/test-minifier.js +153 -153
- package/tests/test-ssr.js +27 -27
- package/tests/utils.test.js +1377 -1377
- package/tests/webrtc/e2ee.test.js +283 -0
- package/tests/webrtc/ice.test.js +202 -0
- package/tests/webrtc/joinToken.test.js +89 -0
- package/tests/webrtc/observe.test.js +111 -0
- package/tests/webrtc/peer.test.js +373 -0
- package/tests/webrtc/reactive.test.js +235 -0
- package/tests/webrtc/room.test.js +406 -0
- package/tests/webrtc/sdp.test.js +151 -0
- package/tests/webrtc/sfu-livekit.test.js +119 -0
- package/tests/webrtc/sfu.test.js +160 -0
- package/tests/webrtc/signaling.test.js +251 -0
- package/tests/webrtc/turn.test.js +256 -0
- package/types/collection.d.ts +383 -383
- package/types/component.d.ts +186 -186
- package/types/errors.d.ts +135 -135
- package/types/http.d.ts +92 -92
- package/types/misc.d.ts +201 -201
- package/types/reactive.d.ts +98 -98
- package/types/router.d.ts +190 -190
- package/types/ssr.d.ts +102 -102
- package/types/store.d.ts +146 -145
- package/types/utils.d.ts +245 -245
- package/types/webrtc.d.ts +653 -0
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* cli/commands/dev/index.js - Dev server orchestrator
|
|
3
|
-
*
|
|
4
|
-
* Ties together the HTTP server, file watcher, logger, and overlay
|
|
5
|
-
* to provide a complete development environment with live-reload,
|
|
6
|
-
* syntax validation, and a full-screen error overlay that surfaces
|
|
7
|
-
* both build-time and runtime ZQueryErrors.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
const fs = require('fs');
|
|
13
|
-
const path = require('path');
|
|
14
|
-
|
|
15
|
-
const { args, flag, option } = require('../../args');
|
|
16
|
-
const { createServer } = require('./server');
|
|
17
|
-
const { startWatcher } = require('./watcher');
|
|
18
|
-
const { printBanner } = require('./logger');
|
|
19
|
-
const bundleApp = require('../bundle');
|
|
20
|
-
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
// Resolve project root
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
|
|
25
|
-
function resolveRoot(htmlEntry) {
|
|
26
|
-
// Explicit positional argument → zquery dev <dir>
|
|
27
|
-
for (let i = 1; i < args.length; i++) {
|
|
28
|
-
const prev = args[i - 1];
|
|
29
|
-
if (!args[i].startsWith('-') && prev !== '-p' && prev !== '--port' && prev !== '--index' && prev !== '-i') {
|
|
30
|
-
return path.resolve(process.cwd(), args[i]);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Auto-detect: first candidate that contains the HTML entry file
|
|
35
|
-
const candidates = [
|
|
36
|
-
process.cwd(),
|
|
37
|
-
path.join(process.cwd(), 'public'),
|
|
38
|
-
path.join(process.cwd(), 'src'),
|
|
39
|
-
];
|
|
40
|
-
for (const c of candidates) {
|
|
41
|
-
if (fs.existsSync(path.join(c, htmlEntry))) return c;
|
|
42
|
-
}
|
|
43
|
-
return process.cwd();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// ---------------------------------------------------------------------------
|
|
47
|
-
// devServer - main entry point (called from cli/index.js)
|
|
48
|
-
// ---------------------------------------------------------------------------
|
|
49
|
-
|
|
50
|
-
async function devServer() {
|
|
51
|
-
const htmlEntry = option('index', 'i', 'index.html');
|
|
52
|
-
const port = parseInt(option('port', 'p', '3100'), 10);
|
|
53
|
-
const noIntercept = flag('no-intercept');
|
|
54
|
-
const bundleMode = flag('bundle', 'b');
|
|
55
|
-
const root = resolveRoot(htmlEntry);
|
|
56
|
-
|
|
57
|
-
// In bundle mode, build the app first then serve from dist/server/
|
|
58
|
-
let serveRoot = root;
|
|
59
|
-
if (bundleMode) {
|
|
60
|
-
console.log('\n Building bundled app...\n');
|
|
61
|
-
// Clear the shared args array so the bundler auto-detects entry from cwd
|
|
62
|
-
// instead of re-parsing the dev command's positional args
|
|
63
|
-
const { args: cliArgs } = require('../../args');
|
|
64
|
-
const savedArgs = cliArgs.slice();
|
|
65
|
-
cliArgs.length = 0;
|
|
66
|
-
cliArgs.push('bundle');
|
|
67
|
-
const prevCwd = process.cwd();
|
|
68
|
-
try {
|
|
69
|
-
process.chdir(root);
|
|
70
|
-
bundleApp();
|
|
71
|
-
} finally {
|
|
72
|
-
process.chdir(prevCwd);
|
|
73
|
-
cliArgs.length = 0;
|
|
74
|
-
savedArgs.forEach(a => cliArgs.push(a));
|
|
75
|
-
}
|
|
76
|
-
serveRoot = path.join(root, 'dist', 'server');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Start HTTP server + SSE pool
|
|
80
|
-
const { app, pool, listen } = await createServer({ root: serveRoot, htmlEntry, port, noIntercept });
|
|
81
|
-
|
|
82
|
-
// Start file watcher (watches source root, rebuilds in bundle mode)
|
|
83
|
-
const watcher = startWatcher({ root, pool, bundleMode, serveRoot });
|
|
84
|
-
|
|
85
|
-
// Boot
|
|
86
|
-
listen(() => {
|
|
87
|
-
printBanner({
|
|
88
|
-
port,
|
|
89
|
-
root: path.relative(process.cwd(), root) || '.',
|
|
90
|
-
htmlEntry,
|
|
91
|
-
noIntercept,
|
|
92
|
-
bundleMode,
|
|
93
|
-
watchDirCount: watcher.dirs.length,
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Graceful shutdown
|
|
98
|
-
process.on('SIGINT', () => {
|
|
99
|
-
console.log('\n Shutting down...');
|
|
100
|
-
watcher.destroy();
|
|
101
|
-
pool.closeAll();
|
|
102
|
-
app.close(() => process.exit(0));
|
|
103
|
-
setTimeout(() => process.exit(0), 1000);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
module.exports = devServer;
|
|
1
|
+
/**
|
|
2
|
+
* cli/commands/dev/index.js - Dev server orchestrator
|
|
3
|
+
*
|
|
4
|
+
* Ties together the HTTP server, file watcher, logger, and overlay
|
|
5
|
+
* to provide a complete development environment with live-reload,
|
|
6
|
+
* syntax validation, and a full-screen error overlay that surfaces
|
|
7
|
+
* both build-time and runtime ZQueryErrors.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
15
|
+
const { args, flag, option } = require('../../args');
|
|
16
|
+
const { createServer } = require('./server');
|
|
17
|
+
const { startWatcher } = require('./watcher');
|
|
18
|
+
const { printBanner } = require('./logger');
|
|
19
|
+
const bundleApp = require('../bundle');
|
|
20
|
+
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Resolve project root
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
function resolveRoot(htmlEntry) {
|
|
26
|
+
// Explicit positional argument → zquery dev <dir>
|
|
27
|
+
for (let i = 1; i < args.length; i++) {
|
|
28
|
+
const prev = args[i - 1];
|
|
29
|
+
if (!args[i].startsWith('-') && prev !== '-p' && prev !== '--port' && prev !== '--index' && prev !== '-i') {
|
|
30
|
+
return path.resolve(process.cwd(), args[i]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Auto-detect: first candidate that contains the HTML entry file
|
|
35
|
+
const candidates = [
|
|
36
|
+
process.cwd(),
|
|
37
|
+
path.join(process.cwd(), 'public'),
|
|
38
|
+
path.join(process.cwd(), 'src'),
|
|
39
|
+
];
|
|
40
|
+
for (const c of candidates) {
|
|
41
|
+
if (fs.existsSync(path.join(c, htmlEntry))) return c;
|
|
42
|
+
}
|
|
43
|
+
return process.cwd();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// devServer - main entry point (called from cli/index.js)
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
async function devServer() {
|
|
51
|
+
const htmlEntry = option('index', 'i', 'index.html');
|
|
52
|
+
const port = parseInt(option('port', 'p', '3100'), 10);
|
|
53
|
+
const noIntercept = flag('no-intercept');
|
|
54
|
+
const bundleMode = flag('bundle', 'b');
|
|
55
|
+
const root = resolveRoot(htmlEntry);
|
|
56
|
+
|
|
57
|
+
// In bundle mode, build the app first then serve from dist/server/
|
|
58
|
+
let serveRoot = root;
|
|
59
|
+
if (bundleMode) {
|
|
60
|
+
console.log('\n Building bundled app...\n');
|
|
61
|
+
// Clear the shared args array so the bundler auto-detects entry from cwd
|
|
62
|
+
// instead of re-parsing the dev command's positional args
|
|
63
|
+
const { args: cliArgs } = require('../../args');
|
|
64
|
+
const savedArgs = cliArgs.slice();
|
|
65
|
+
cliArgs.length = 0;
|
|
66
|
+
cliArgs.push('bundle');
|
|
67
|
+
const prevCwd = process.cwd();
|
|
68
|
+
try {
|
|
69
|
+
process.chdir(root);
|
|
70
|
+
bundleApp();
|
|
71
|
+
} finally {
|
|
72
|
+
process.chdir(prevCwd);
|
|
73
|
+
cliArgs.length = 0;
|
|
74
|
+
savedArgs.forEach(a => cliArgs.push(a));
|
|
75
|
+
}
|
|
76
|
+
serveRoot = path.join(root, 'dist', 'server');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Start HTTP server + SSE pool
|
|
80
|
+
const { app, pool, listen } = await createServer({ root: serveRoot, htmlEntry, port, noIntercept });
|
|
81
|
+
|
|
82
|
+
// Start file watcher (watches source root, rebuilds in bundle mode)
|
|
83
|
+
const watcher = startWatcher({ root, pool, bundleMode, serveRoot });
|
|
84
|
+
|
|
85
|
+
// Boot
|
|
86
|
+
listen(() => {
|
|
87
|
+
printBanner({
|
|
88
|
+
port,
|
|
89
|
+
root: path.relative(process.cwd(), root) || '.',
|
|
90
|
+
htmlEntry,
|
|
91
|
+
noIntercept,
|
|
92
|
+
bundleMode,
|
|
93
|
+
watchDirCount: watcher.dirs.length,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Graceful shutdown
|
|
98
|
+
process.on('SIGINT', () => {
|
|
99
|
+
console.log('\n Shutting down...');
|
|
100
|
+
watcher.destroy();
|
|
101
|
+
pool.closeAll();
|
|
102
|
+
app.close(() => process.exit(0));
|
|
103
|
+
setTimeout(() => process.exit(0), 1000);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
module.exports = devServer;
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* cli/commands/dev/logger.js - Terminal output helpers
|
|
3
|
-
*
|
|
4
|
-
* Provides styled console output for the dev server: startup banner,
|
|
5
|
-
* timestamped file-change messages, and error formatting.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
// ANSI colour helpers (works on all modern terminals)
|
|
11
|
-
const c = {
|
|
12
|
-
reset: '\x1b[0m',
|
|
13
|
-
bold: '\x1b[1m',
|
|
14
|
-
dim: '\x1b[2m',
|
|
15
|
-
red: '\x1b[31m',
|
|
16
|
-
green: '\x1b[32m',
|
|
17
|
-
yellow: '\x1b[33m',
|
|
18
|
-
cyan: '\x1b[36m',
|
|
19
|
-
magenta: '\x1b[35m',
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
function timestamp() {
|
|
23
|
-
return new Date().toLocaleTimeString();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
// Event-level log helpers
|
|
28
|
-
// ---------------------------------------------------------------------------
|
|
29
|
-
|
|
30
|
-
function logCSS(relPath) {
|
|
31
|
-
console.log(` ${timestamp()} ${c.magenta} css ${c.reset} ${relPath}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function logReload(relPath) {
|
|
35
|
-
console.log(` ${timestamp()} ${c.cyan} reload ${c.reset} ${relPath}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function logError(descriptor) {
|
|
39
|
-
const t = timestamp();
|
|
40
|
-
console.log(` ${t} ${c.red} error ${c.reset} ${descriptor.file}`);
|
|
41
|
-
console.log(` ${c.red}${descriptor.type}: ${descriptor.message}${c.reset}`);
|
|
42
|
-
if (descriptor.line) {
|
|
43
|
-
console.log(` ${c.dim}at line ${descriptor.line}${descriptor.column ? ':' + descriptor.column : ''}${c.reset}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ---------------------------------------------------------------------------
|
|
48
|
-
// Startup banner
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
|
|
51
|
-
function printBanner({ port, root, htmlEntry, noIntercept, bundleMode, watchDirCount }) {
|
|
52
|
-
const rule = c.dim + '-'.repeat(40) + c.reset;
|
|
53
|
-
console.log(`\n ${c.bold}zQuery Dev Server${c.reset}`);
|
|
54
|
-
console.log(` ${rule}`);
|
|
55
|
-
console.log(` Local: ${c.cyan}http://localhost:${port}/${c.reset}`);
|
|
56
|
-
console.log(` DevTools: ${c.cyan}http://localhost:${port}/_devtools${c.reset}`);
|
|
57
|
-
console.log(` Root: ${root}`);
|
|
58
|
-
if (bundleMode) {
|
|
59
|
-
console.log(` Mode: ${c.yellow}bundled${c.reset} (serving from dist/server/)`);
|
|
60
|
-
}
|
|
61
|
-
if (htmlEntry !== 'index.html') {
|
|
62
|
-
console.log(` HTML: ${c.cyan}${htmlEntry}${c.reset}`);
|
|
63
|
-
}
|
|
64
|
-
console.log(` Live Reload: ${c.green}enabled${c.reset} (SSE)`);
|
|
65
|
-
console.log(` Overlay: ${c.green}enabled${c.reset} (syntax + runtime + ZQueryError)`);
|
|
66
|
-
console.log(` Fetch Log: ${c.green}enabled${c.reset} (auto-intercept all fetch/$.http)`);
|
|
67
|
-
if (noIntercept) {
|
|
68
|
-
console.log(` Intercept: ${c.yellow}disabled${c.reset} (--no-intercept)`);
|
|
69
|
-
}
|
|
70
|
-
console.log(` Watching: all files in ${watchDirCount} director${watchDirCount === 1 ? 'y' : 'ies'}`);
|
|
71
|
-
console.log(` ${rule}`);
|
|
72
|
-
console.log(` Press Ctrl+C to stop\n`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
module.exports = { logCSS, logReload, logError, printBanner };
|
|
1
|
+
/**
|
|
2
|
+
* cli/commands/dev/logger.js - Terminal output helpers
|
|
3
|
+
*
|
|
4
|
+
* Provides styled console output for the dev server: startup banner,
|
|
5
|
+
* timestamped file-change messages, and error formatting.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
// ANSI colour helpers (works on all modern terminals)
|
|
11
|
+
const c = {
|
|
12
|
+
reset: '\x1b[0m',
|
|
13
|
+
bold: '\x1b[1m',
|
|
14
|
+
dim: '\x1b[2m',
|
|
15
|
+
red: '\x1b[31m',
|
|
16
|
+
green: '\x1b[32m',
|
|
17
|
+
yellow: '\x1b[33m',
|
|
18
|
+
cyan: '\x1b[36m',
|
|
19
|
+
magenta: '\x1b[35m',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function timestamp() {
|
|
23
|
+
return new Date().toLocaleTimeString();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// Event-level log helpers
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
function logCSS(relPath) {
|
|
31
|
+
console.log(` ${timestamp()} ${c.magenta} css ${c.reset} ${relPath}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function logReload(relPath) {
|
|
35
|
+
console.log(` ${timestamp()} ${c.cyan} reload ${c.reset} ${relPath}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function logError(descriptor) {
|
|
39
|
+
const t = timestamp();
|
|
40
|
+
console.log(` ${t} ${c.red} error ${c.reset} ${descriptor.file}`);
|
|
41
|
+
console.log(` ${c.red}${descriptor.type}: ${descriptor.message}${c.reset}`);
|
|
42
|
+
if (descriptor.line) {
|
|
43
|
+
console.log(` ${c.dim}at line ${descriptor.line}${descriptor.column ? ':' + descriptor.column : ''}${c.reset}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Startup banner
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
function printBanner({ port, root, htmlEntry, noIntercept, bundleMode, watchDirCount }) {
|
|
52
|
+
const rule = c.dim + '-'.repeat(40) + c.reset;
|
|
53
|
+
console.log(`\n ${c.bold}zQuery Dev Server${c.reset}`);
|
|
54
|
+
console.log(` ${rule}`);
|
|
55
|
+
console.log(` Local: ${c.cyan}http://localhost:${port}/${c.reset}`);
|
|
56
|
+
console.log(` DevTools: ${c.cyan}http://localhost:${port}/_devtools${c.reset}`);
|
|
57
|
+
console.log(` Root: ${root}`);
|
|
58
|
+
if (bundleMode) {
|
|
59
|
+
console.log(` Mode: ${c.yellow}bundled${c.reset} (serving from dist/server/)`);
|
|
60
|
+
}
|
|
61
|
+
if (htmlEntry !== 'index.html') {
|
|
62
|
+
console.log(` HTML: ${c.cyan}${htmlEntry}${c.reset}`);
|
|
63
|
+
}
|
|
64
|
+
console.log(` Live Reload: ${c.green}enabled${c.reset} (SSE)`);
|
|
65
|
+
console.log(` Overlay: ${c.green}enabled${c.reset} (syntax + runtime + ZQueryError)`);
|
|
66
|
+
console.log(` Fetch Log: ${c.green}enabled${c.reset} (auto-intercept all fetch/$.http)`);
|
|
67
|
+
if (noIntercept) {
|
|
68
|
+
console.log(` Intercept: ${c.yellow}disabled${c.reset} (--no-intercept)`);
|
|
69
|
+
}
|
|
70
|
+
console.log(` Watching: all files in ${watchDirCount} director${watchDirCount === 1 ? 'y' : 'ies'}`);
|
|
71
|
+
console.log(` ${rule}`);
|
|
72
|
+
console.log(` Press Ctrl+C to stop\n`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = { logCSS, logReload, logError, printBanner };
|