eyeling 1.24.3 → 1.24.5

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.
@@ -1,166 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- // Convert examples/input/*.{ttl,trig} -> examples/*.n3 using n3gen.js
5
- //
6
- // For reproducibility and to avoid mutating tracked files during tests, generated output
7
- // is always written to a temporary file and compared against examples/<name>.n3.
8
-
9
- const fs = require('node:fs');
10
- const os = require('node:os');
11
- const path = require('node:path');
12
- const cp = require('node:child_process');
13
-
14
- const TTY = process.stdout.isTTY;
15
- const C = TTY
16
- ? { g: '\x1b[32m', r: '\x1b[31m', y: '\x1b[33m', dim: '\x1b[2m', n: '\x1b[0m' }
17
- : { g: '', r: '', y: '', dim: '', n: '' };
18
-
19
- function ok(msg) {
20
- console.log(`${C.g}OK ${C.n} ${msg}`);
21
- }
22
- function fail(msg) {
23
- console.error(`${C.r}FAIL${C.n} ${msg}`);
24
- }
25
- function info(msg) {
26
- console.log(`${C.y}==${C.n} ${msg}`);
27
- }
28
-
29
- function run(cmd, args, opts = {}) {
30
- return cp.spawnSync(cmd, args, {
31
- encoding: 'utf8',
32
- maxBuffer: 200 * 1024 * 1024,
33
- ...opts,
34
- });
35
- }
36
-
37
- function mkTmpDir() {
38
- return fs.mkdtempSync(path.join(os.tmpdir(), 'eyeling-n3-'));
39
- }
40
-
41
- function rmrf(p) {
42
- try {
43
- fs.rmSync(p, { recursive: true, force: true });
44
- } catch {}
45
- }
46
-
47
- function showDiff({ examplesDir, expectedPath, generatedPath }) {
48
- const d = run('diff', ['-u', expectedPath, generatedPath], { cwd: examplesDir });
49
- if (d.stdout) process.stdout.write(d.stdout);
50
- if (d.stderr) process.stderr.write(d.stderr);
51
- }
52
-
53
- function main() {
54
- const suiteStart = Date.now();
55
-
56
- // test/n3gen.test.js -> repo root is one level up
57
- const root = path.resolve(__dirname, '..');
58
- const examplesDir = path.join(root, 'examples');
59
- const inputDir = path.join(examplesDir, 'input');
60
- const n3GenJsPath = path.join(root, 'tools/n3gen.js');
61
- const nodePath = process.execPath;
62
-
63
- if (!fs.existsSync(examplesDir)) {
64
- fail(`Cannot find examples directory: ${examplesDir}`);
65
- process.exit(1);
66
- }
67
- if (!fs.existsSync(inputDir)) {
68
- fail(`Cannot find examples/input directory: ${inputDir}`);
69
- process.exit(1);
70
- }
71
- if (!fs.existsSync(n3GenJsPath)) {
72
- fail(`Cannot find n3gen.js: ${n3GenJsPath}`);
73
- process.exit(1);
74
- }
75
-
76
- const inputs = fs
77
- .readdirSync(inputDir)
78
- .filter((f) => /\.(ttl|trig)$/i.test(f))
79
- .sort((a, b) => a.localeCompare(b));
80
-
81
- info(`Running n3 conversions for ${inputs.length} inputs`);
82
- console.log(`${C.dim}node ${process.version}${C.n}`);
83
-
84
- if (inputs.length === 0) {
85
- ok('No .ttl/.trig files found in examples/input/');
86
- process.exit(0);
87
- }
88
-
89
- let passed = 0;
90
- let failed = 0;
91
-
92
- for (let i = 0; i < inputs.length; i++) {
93
- const idx = String(i + 1).padStart(2, '0');
94
- const inFile = inputs[i];
95
- const start = Date.now();
96
-
97
- const inPath = path.join(inputDir, inFile);
98
- const base = inFile.replace(/\.(ttl|trig)$/i, '');
99
- const outFile = `${base}.n3`;
100
-
101
- const expectedPath = path.join(examplesDir, outFile);
102
-
103
- if (!fs.existsSync(expectedPath)) {
104
- const ms = Date.now() - start;
105
- fail(`${idx} ${inFile} -> ${outFile} (${ms} ms)`);
106
- fail(`Missing expected examples/${outFile}`);
107
- failed++;
108
- continue;
109
- }
110
-
111
- const tmpDir = mkTmpDir();
112
- const generatedPath = path.join(tmpDir, outFile);
113
-
114
- // Run converter (stdout -> file; stderr captured)
115
- const outFd = fs.openSync(generatedPath, 'w');
116
- const r = cp.spawnSync(nodePath, [n3GenJsPath, inPath], {
117
- cwd: root,
118
- stdio: ['ignore', outFd, 'pipe'],
119
- encoding: 'utf8',
120
- maxBuffer: 200 * 1024 * 1024,
121
- });
122
- fs.closeSync(outFd);
123
-
124
- const rc = r.status == null ? 1 : r.status;
125
- const ms = Date.now() - start;
126
-
127
- if (rc !== 0) {
128
- fail(`${idx} ${inFile} -> ${outFile} (${ms} ms)`);
129
- fail(`Converter exit code ${rc}`);
130
- if (r.stderr) process.stderr.write(String(r.stderr));
131
- failed++;
132
- rmrf(tmpDir);
133
- continue;
134
- }
135
-
136
- // Compare output (always compare expected vs generated temp file)
137
- const d = run('diff', ['-u', expectedPath, generatedPath], { cwd: examplesDir });
138
- const diffOk = d.status === 0;
139
-
140
- if (diffOk) {
141
- ok(`${idx} ${inFile} -> ${outFile} (${ms} ms)`);
142
- passed++;
143
- } else {
144
- fail(`${idx} ${inFile} -> ${outFile} (${ms} ms)`);
145
- fail('Output differs');
146
- showDiff({ examplesDir, expectedPath, generatedPath });
147
- failed++;
148
- }
149
-
150
- rmrf(tmpDir);
151
- }
152
-
153
- console.log('');
154
- const suiteMs = Date.now() - suiteStart;
155
- info(`Total elapsed: ${suiteMs} ms (${(suiteMs / 1000).toFixed(2)} s)`);
156
-
157
- if (failed === 0) {
158
- ok(`All n3 conversions passed (${passed}/${inputs.length})`);
159
- process.exit(0);
160
- } else {
161
- fail(`Some n3 conversions failed (${passed}/${inputs.length})`);
162
- process.exit(2);
163
- }
164
- }
165
-
166
- main();