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
package/cli/commands/build.js
CHANGED
|
@@ -1,216 +1,254 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* cli/commands/build.js - library build command
|
|
3
|
-
*
|
|
4
|
-
* Concatenates the zQuery source modules into dist/zquery.js and
|
|
5
|
-
* dist/zquery.min.js.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
const path = require('path');
|
|
12
|
-
const zlib = require('zlib');
|
|
13
|
-
const { execSync } = require('child_process');
|
|
14
|
-
const { minify, sizeKB } = require('../utils');
|
|
15
|
-
|
|
16
|
-
function buildLibrary() {
|
|
17
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8'));
|
|
18
|
-
const VERSION = pkg.version;
|
|
19
|
-
|
|
20
|
-
const modules = [
|
|
21
|
-
'src/errors.js',
|
|
22
|
-
'src/reactive.js', 'src/
|
|
23
|
-
'src/
|
|
24
|
-
'src/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
fs.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
fs.writeFileSync(OUT_FILE,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
1
|
+
/**
|
|
2
|
+
* cli/commands/build.js - library build command
|
|
3
|
+
*
|
|
4
|
+
* Concatenates the zQuery source modules into dist/zquery.js and
|
|
5
|
+
* dist/zquery.min.js.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const zlib = require('zlib');
|
|
13
|
+
const { execSync } = require('child_process');
|
|
14
|
+
const { minify, sizeKB } = require('../utils');
|
|
15
|
+
|
|
16
|
+
function buildLibrary() {
|
|
17
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8'));
|
|
18
|
+
const VERSION = pkg.version;
|
|
19
|
+
|
|
20
|
+
const modules = [
|
|
21
|
+
'src/errors.js',
|
|
22
|
+
'src/webrtc/errors.js', 'src/webrtc/sdp.js', 'src/webrtc/ice.js', 'src/webrtc/signaling.js', 'src/webrtc/peer.js', 'src/webrtc/room.js', 'src/webrtc/reactive.js', 'src/webrtc/turn.js', 'src/webrtc/e2ee.js', 'src/webrtc/joinToken.js', 'src/webrtc/observe.js', 'src/webrtc/sfu/mediasoup.js', 'src/webrtc/sfu/livekit.js', 'src/webrtc/sfu/index.js', 'src/webrtc/index.js',
|
|
23
|
+
'src/reactive.js', 'src/diff.js', 'src/core.js', 'src/expression.js',
|
|
24
|
+
'src/component.js', 'src/router.js', 'src/store.js', 'src/http.js',
|
|
25
|
+
'src/utils.js',
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
// Guard: ensure we're inside the zero-query source repo
|
|
29
|
+
const missing = modules.filter(m => !fs.existsSync(path.join(process.cwd(), m)));
|
|
30
|
+
if (missing.length > 0) {
|
|
31
|
+
console.error(` ✗ "zquery build" must be run from the zero-query source repository.`);
|
|
32
|
+
console.error(` Missing source files: ${missing.join(', ')}`);
|
|
33
|
+
console.error(` To bundle your app for production, use "zquery bundle" instead.\n`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const DIST = path.join(process.cwd(), 'dist');
|
|
38
|
+
const OUT_FILE = path.join(DIST, 'zquery.js');
|
|
39
|
+
const MIN_FILE = path.join(DIST, 'zquery.min.js');
|
|
40
|
+
|
|
41
|
+
const start = Date.now();
|
|
42
|
+
if (!fs.existsSync(DIST)) fs.mkdirSync(DIST, { recursive: true });
|
|
43
|
+
|
|
44
|
+
// -----------------------------------------------------------------------
|
|
45
|
+
// Run unit tests and capture results for $.unitTests
|
|
46
|
+
// -----------------------------------------------------------------------
|
|
47
|
+
let testResults = { passed: 0, failed: 0, total: 0, suites: 0, duration: 0, ok: false };
|
|
48
|
+
try {
|
|
49
|
+
const json = execSync('npx vitest run --reporter=json', {
|
|
50
|
+
cwd: process.cwd(),
|
|
51
|
+
encoding: 'utf-8',
|
|
52
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
53
|
+
timeout: 120000,
|
|
54
|
+
});
|
|
55
|
+
// vitest --reporter=json outputs JSON to stdout; may include non-JSON lines
|
|
56
|
+
const jsonStart = json.indexOf('{');
|
|
57
|
+
if (jsonStart !== -1) {
|
|
58
|
+
const parsed = JSON.parse(json.slice(jsonStart));
|
|
59
|
+
const passed = parsed.numPassedTests || 0;
|
|
60
|
+
const failed = parsed.numFailedTests || 0;
|
|
61
|
+
const total = parsed.numTotalTests || 0;
|
|
62
|
+
const suites = parsed.numTotalTestSuites || 0;
|
|
63
|
+
const dur = Math.round((parsed.testResults || []).reduce((s, r) => s + (r.endTime - r.startTime), 0));
|
|
64
|
+
testResults = { passed, failed, total, suites, duration: dur, ok: parsed.success !== false };
|
|
65
|
+
}
|
|
66
|
+
console.log(` ✓ Tests: ${testResults.passed}/${testResults.total} passed (${testResults.suites} suites)\n`);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
// Tests may fail but we still want to capture the numbers
|
|
69
|
+
const out = (err.stdout || '') + (err.stderr || '');
|
|
70
|
+
const jsonStart = out.indexOf('{');
|
|
71
|
+
if (jsonStart !== -1) {
|
|
72
|
+
try {
|
|
73
|
+
const parsed = JSON.parse(out.slice(jsonStart));
|
|
74
|
+
testResults = {
|
|
75
|
+
passed: parsed.numPassedTests || 0,
|
|
76
|
+
failed: parsed.numFailedTests || 0,
|
|
77
|
+
total: parsed.numTotalTests || 0,
|
|
78
|
+
suites: parsed.numTotalTestSuites || 0,
|
|
79
|
+
duration: Math.round((parsed.testResults || []).reduce((s, r) => s + (r.endTime - r.startTime), 0)),
|
|
80
|
+
ok: false,
|
|
81
|
+
};
|
|
82
|
+
} catch (_) { /* keep defaults */ }
|
|
83
|
+
}
|
|
84
|
+
console.log(` ⚠ Tests: ${testResults.passed}/${testResults.total} passed, ${testResults.failed} failed\n`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const parts = modules.map(file => {
|
|
88
|
+
let code = fs.readFileSync(path.join(process.cwd(), file), 'utf-8');
|
|
89
|
+
code = code.replace(/^import\s+[\s\S]*?from\s+['"].*?['"];?\s*$/gm, '');
|
|
90
|
+
code = code.replace(/^export\s+(?:\*|\{[\s\S]*?\})\s+from\s+['"].*?['"];?\s*$/gm, '');
|
|
91
|
+
code = code.replace(/^export\s+(default\s+)?/gm, '');
|
|
92
|
+
code = code.replace(/^export\s*\{[\s\S]*?\};\s*$/gm, '');
|
|
93
|
+
return `// --- ${file} ${'-'.repeat(60 - file.length)}\n${code.trim()}`;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
let indexCode = fs.readFileSync(path.join(process.cwd(), 'index.js'), 'utf-8');
|
|
97
|
+
indexCode = indexCode.replace(/^import\s+[\s\S]*?from\s+['"].*?['"];?\s*$/gm, '');
|
|
98
|
+
indexCode = indexCode.replace(/^export\s+(?:\*|\{[\s\S]*?\})\s+from\s+['"].*?['"];?\s*$/gm, '');
|
|
99
|
+
indexCode = indexCode.replace(/^export\s*\{[\s\S]*?\};\s*$/gm, '');
|
|
100
|
+
indexCode = indexCode.replace(/^export\s+(default\s+)?/gm, '');
|
|
101
|
+
|
|
102
|
+
const banner = `/**\n * zQuery (zeroQuery) v${VERSION}\n * Lightweight Frontend Library\n * https://github.com/tonywied17/zero-query\n * (c) ${new Date().getFullYear()} Anthony Wiedman - MIT License\n */`;
|
|
103
|
+
|
|
104
|
+
const bundle = `${banner}\n(function(global) {\n 'use strict';\n\n${parts.join('\n\n')}\n\n// --- index.js (assembly) ${'-'.repeat(42)}\n${indexCode.trim().replace("'__VERSION__'", `'${VERSION}'`)}\n\n})(typeof window !== 'undefined' ? window : globalThis);\n`;
|
|
105
|
+
|
|
106
|
+
fs.writeFileSync(OUT_FILE, bundle, 'utf-8');
|
|
107
|
+
const minified = minify(bundle, banner);
|
|
108
|
+
fs.writeFileSync(MIN_FILE, minified, 'utf-8');
|
|
109
|
+
|
|
110
|
+
// Inject actual minified library size into both outputs.
|
|
111
|
+
// The unminified bundle keeps single quotes; esbuild rewrites the minified
|
|
112
|
+
// output with double quotes, so we tolerate both.
|
|
113
|
+
const libSizeKB = Math.round(Buffer.from(minified).length / 1024);
|
|
114
|
+
const libSizeStr = `~${libSizeKB} KB`;
|
|
115
|
+
const testObj = JSON.stringify(testResults);
|
|
116
|
+
const libRe = /(['"])__LIB_SIZE__\1/g;
|
|
117
|
+
const testRe = /(['"])__UNIT_TESTS__\1/g;
|
|
118
|
+
let outContent = fs.readFileSync(OUT_FILE, 'utf-8').replace(libRe, `'${libSizeStr}'`);
|
|
119
|
+
let minContent = minified.replace(libRe, JSON.stringify(libSizeStr));
|
|
120
|
+
outContent = outContent.replace(testRe, testObj);
|
|
121
|
+
minContent = minContent.replace(testRe, testObj);
|
|
122
|
+
fs.writeFileSync(OUT_FILE, outContent, 'utf-8');
|
|
123
|
+
fs.writeFileSync(MIN_FILE, minContent, 'utf-8');
|
|
124
|
+
|
|
125
|
+
const elapsed = Date.now() - start;
|
|
126
|
+
console.log(` ✓ dist/zquery.js (${sizeKB(fs.readFileSync(OUT_FILE))} KB)`);
|
|
127
|
+
console.log(` ✓ dist/zquery.min.js (${sizeKB(fs.readFileSync(MIN_FILE))} KB)`);
|
|
128
|
+
console.log(` Done in ${elapsed}ms\n`);
|
|
129
|
+
|
|
130
|
+
// --- Generate API.md before zipping --------------------------------------
|
|
131
|
+
const root = process.cwd();
|
|
132
|
+
try {
|
|
133
|
+
const buildApi = require('./build-api');
|
|
134
|
+
// buildApi() is async (dynamic imports), so we run it synchronously via
|
|
135
|
+
// a child process to keep the build function synchronous.
|
|
136
|
+
execSync('node cli/commands/build-api.js', {
|
|
137
|
+
cwd: root,
|
|
138
|
+
stdio: 'inherit',
|
|
139
|
+
timeout: 60000,
|
|
140
|
+
});
|
|
141
|
+
} catch (err) {
|
|
142
|
+
console.log(' ⚠ API.md generation skipped:', err.message || 'unknown error');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// --- Copy API.md into dist -----------------------------------------------
|
|
146
|
+
const apiSrc = path.join(root, 'API.md');
|
|
147
|
+
const apiDist = path.join(DIST, 'API.md');
|
|
148
|
+
if (fs.existsSync(apiSrc)) {
|
|
149
|
+
fs.copyFileSync(apiSrc, apiDist);
|
|
150
|
+
console.log(` ✓ dist/API.md (${sizeKB(fs.readFileSync(apiDist))} KB)`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// --- Create dist/zquery.dist.zip -----------------------------------------
|
|
154
|
+
const zipFiles = [
|
|
155
|
+
{ src: OUT_FILE, name: 'zquery.js' },
|
|
156
|
+
{ src: MIN_FILE, name: 'zquery.min.js' },
|
|
157
|
+
{ src: path.join(root, 'LICENSE'), name: 'LICENSE' },
|
|
158
|
+
{ src: apiDist, name: 'API.md' },
|
|
159
|
+
{ src: path.join(root, 'README.md'), name: 'README.md' },
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
// Minimal ZIP builder (deflate via zlib, no external deps)
|
|
163
|
+
function buildZip(entries) {
|
|
164
|
+
const localHeaders = [];
|
|
165
|
+
const centralHeaders = [];
|
|
166
|
+
let offset = 0;
|
|
167
|
+
|
|
168
|
+
for (const { name, data } of entries) {
|
|
169
|
+
const nameBytes = Buffer.from(name, 'utf-8');
|
|
170
|
+
const compressed = zlib.deflateRawSync(data, { level: 9 });
|
|
171
|
+
const crc = crc32(data);
|
|
172
|
+
const compLen = compressed.length;
|
|
173
|
+
const uncompLen = data.length;
|
|
174
|
+
|
|
175
|
+
// Local file header
|
|
176
|
+
const local = Buffer.alloc(30 + nameBytes.length);
|
|
177
|
+
local.writeUInt32LE(0x04034b50, 0); // signature
|
|
178
|
+
local.writeUInt16LE(20, 4); // version needed
|
|
179
|
+
local.writeUInt16LE(0, 6); // flags
|
|
180
|
+
local.writeUInt16LE(8, 8); // compression: deflate
|
|
181
|
+
local.writeUInt16LE(0, 10); // mod time
|
|
182
|
+
local.writeUInt16LE(0, 12); // mod date
|
|
183
|
+
local.writeUInt32LE(crc, 14);
|
|
184
|
+
local.writeUInt32LE(compLen, 18);
|
|
185
|
+
local.writeUInt32LE(uncompLen, 22);
|
|
186
|
+
local.writeUInt16LE(nameBytes.length, 26);
|
|
187
|
+
local.writeUInt16LE(0, 28); // extra field length
|
|
188
|
+
nameBytes.copy(local, 30);
|
|
189
|
+
|
|
190
|
+
localHeaders.push(Buffer.concat([local, compressed]));
|
|
191
|
+
|
|
192
|
+
// Central directory header
|
|
193
|
+
const central = Buffer.alloc(46 + nameBytes.length);
|
|
194
|
+
central.writeUInt32LE(0x02014b50, 0);
|
|
195
|
+
central.writeUInt16LE(20, 4); // version made by
|
|
196
|
+
central.writeUInt16LE(20, 6); // version needed
|
|
197
|
+
central.writeUInt16LE(0, 8); // flags
|
|
198
|
+
central.writeUInt16LE(8, 10); // compression: deflate
|
|
199
|
+
central.writeUInt16LE(0, 12); // mod time
|
|
200
|
+
central.writeUInt16LE(0, 14); // mod date
|
|
201
|
+
central.writeUInt32LE(crc, 16);
|
|
202
|
+
central.writeUInt32LE(compLen, 20);
|
|
203
|
+
central.writeUInt32LE(uncompLen, 24);
|
|
204
|
+
central.writeUInt16LE(nameBytes.length, 28);
|
|
205
|
+
central.writeUInt16LE(0, 30); // extra field length
|
|
206
|
+
central.writeUInt16LE(0, 32); // comment length
|
|
207
|
+
central.writeUInt16LE(0, 34); // disk number
|
|
208
|
+
central.writeUInt16LE(0, 36); // internal attrs
|
|
209
|
+
central.writeUInt32LE(0, 38); // external attrs
|
|
210
|
+
central.writeUInt32LE(offset, 42); // local header offset
|
|
211
|
+
nameBytes.copy(central, 46);
|
|
212
|
+
centralHeaders.push(central);
|
|
213
|
+
|
|
214
|
+
offset += local.length + compressed.length;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const centralDir = Buffer.concat(centralHeaders);
|
|
218
|
+
const eocd = Buffer.alloc(22);
|
|
219
|
+
eocd.writeUInt32LE(0x06054b50, 0);
|
|
220
|
+
eocd.writeUInt16LE(0, 4); // disk number
|
|
221
|
+
eocd.writeUInt16LE(0, 6); // central dir disk
|
|
222
|
+
eocd.writeUInt16LE(entries.length, 8); // entries on disk
|
|
223
|
+
eocd.writeUInt16LE(entries.length, 10); // total entries
|
|
224
|
+
eocd.writeUInt32LE(centralDir.length, 12);
|
|
225
|
+
eocd.writeUInt32LE(offset, 16); // central dir offset
|
|
226
|
+
eocd.writeUInt16LE(0, 20); // comment length
|
|
227
|
+
|
|
228
|
+
return Buffer.concat([...localHeaders, centralDir, eocd]);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function crc32(buf) {
|
|
232
|
+
let crc = 0xFFFFFFFF;
|
|
233
|
+
for (let i = 0; i < buf.length; i++) {
|
|
234
|
+
crc ^= buf[i];
|
|
235
|
+
for (let j = 0; j < 8; j++) {
|
|
236
|
+
crc = (crc >>> 1) ^ ((crc & 1) ? 0xEDB88320 : 0);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return (crc ^ 0xFFFFFFFF) >>> 0;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const entries = zipFiles
|
|
243
|
+
.filter(f => fs.existsSync(f.src))
|
|
244
|
+
.map(f => ({ name: f.name, data: fs.readFileSync(f.src) }));
|
|
245
|
+
|
|
246
|
+
const zipBuf = buildZip(entries);
|
|
247
|
+
const zipPath = path.join(DIST, 'zquery.dist.zip');
|
|
248
|
+
fs.writeFileSync(zipPath, zipBuf);
|
|
249
|
+
console.log(` ✓ dist/zquery.dist.zip (${sizeKB(zipBuf)} KB) - ${entries.length} files`);
|
|
250
|
+
|
|
251
|
+
return { DIST, OUT_FILE, MIN_FILE };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
module.exports = buildLibrary;
|