@xn-intenton-z2a/agentic-lib 7.2.10 → 7.2.11
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/bin/agentic-lib.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (C) 2025-2026 Polycode Limited
|
|
4
|
+
// scripts/build-web.cjs
|
|
5
|
+
// Usage: node .github/agentic-lib/scripts/build-web.cjs
|
|
6
|
+
//
|
|
7
|
+
// Builds the docs/ directory for web serving:
|
|
8
|
+
// 1. Creates docs/ and copies src/web/* into it
|
|
9
|
+
// 2. Generates docs/lib-meta.js with package metadata exports
|
|
10
|
+
// 3. Generates docs/lib-browser.js from src/lib/main.js (if it has named exports)
|
|
11
|
+
//
|
|
12
|
+
// This file is part of the Example Suite for `agentic-lib` see: https://github.com/xn-intenton-z2a/agentic-lib
|
|
13
|
+
// This file is licensed under the MIT License. For details, see LICENSE-MIT
|
|
14
|
+
|
|
15
|
+
const fs = require("fs");
|
|
16
|
+
const path = require("path");
|
|
17
|
+
|
|
18
|
+
const docsDir = path.resolve("docs");
|
|
19
|
+
|
|
20
|
+
// Step 1: Create docs/ and copy src/web/* if it exists
|
|
21
|
+
fs.mkdirSync(docsDir, { recursive: true });
|
|
22
|
+
fs.writeFileSync(path.join(docsDir, ".nojekyll"), "");
|
|
23
|
+
|
|
24
|
+
const webDir = path.resolve("src", "web");
|
|
25
|
+
if (fs.existsSync(webDir)) {
|
|
26
|
+
for (const entry of fs.readdirSync(webDir, { withFileTypes: true })) {
|
|
27
|
+
const src = path.join(webDir, entry.name);
|
|
28
|
+
const dest = path.join(docsDir, entry.name);
|
|
29
|
+
if (entry.isFile()) {
|
|
30
|
+
fs.copyFileSync(src, dest);
|
|
31
|
+
} else if (entry.isDirectory()) {
|
|
32
|
+
fs.cpSync(src, dest, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Step 2: Generate docs/lib-meta.js with package metadata
|
|
38
|
+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
|
|
39
|
+
const metaLines = ["name", "version", "description"].map(
|
|
40
|
+
(k) => `export const ${k} = ${JSON.stringify(pkg[k])};`
|
|
41
|
+
);
|
|
42
|
+
fs.writeFileSync(path.join(docsDir, "lib-meta.js"), metaLines.join("\n") + "\n");
|
|
43
|
+
console.log("Wrote docs/lib-meta.js");
|
|
44
|
+
|
|
45
|
+
// Step 3: Generate docs/lib-browser.js from src/lib/main.js named exports
|
|
46
|
+
// Parse the main module for `export function` and `export async function` declarations
|
|
47
|
+
// and re-emit them as a standalone browser-compatible module.
|
|
48
|
+
const mainPath = path.resolve("src", "lib", "main.js");
|
|
49
|
+
if (fs.existsSync(mainPath)) {
|
|
50
|
+
const mainSrc = fs.readFileSync(mainPath, "utf8");
|
|
51
|
+
// Match named export functions: export function foo(...) { ... } or export async function foo(...)
|
|
52
|
+
const exportRegex = /^export\s+(async\s+)?function\s+(\w+)/gm;
|
|
53
|
+
const exportNames = [];
|
|
54
|
+
let match;
|
|
55
|
+
while ((match = exportRegex.exec(mainSrc)) !== null) {
|
|
56
|
+
exportNames.push(match[2]);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (exportNames.length > 0) {
|
|
60
|
+
// Extract the function bodies by finding each export function and copying it verbatim
|
|
61
|
+
const lines = mainSrc.split("\n");
|
|
62
|
+
const functionBodies = [];
|
|
63
|
+
for (let i = 0; i < lines.length; i++) {
|
|
64
|
+
if (/^export\s+(async\s+)?function\s+\w+/.test(lines[i])) {
|
|
65
|
+
// Collect lines until we find the closing brace at column 0
|
|
66
|
+
const fnLines = [lines[i]];
|
|
67
|
+
let braceDepth = 0;
|
|
68
|
+
for (let j = i; j < lines.length; j++) {
|
|
69
|
+
for (const ch of lines[j]) {
|
|
70
|
+
if (ch === "{") braceDepth++;
|
|
71
|
+
if (ch === "}") braceDepth--;
|
|
72
|
+
}
|
|
73
|
+
if (j > i) fnLines.push(lines[j]);
|
|
74
|
+
if (braceDepth === 0 && j >= i) {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
functionBodies.push(fnLines.join("\n"));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const header = [
|
|
83
|
+
"// docs/lib-browser.js",
|
|
84
|
+
"// Generated browser-compatible module exposing named exports from src/lib/main.js.",
|
|
85
|
+
"// Auto-generated by build-web.cjs — do not edit manually.",
|
|
86
|
+
"",
|
|
87
|
+
].join("\n");
|
|
88
|
+
|
|
89
|
+
fs.writeFileSync(
|
|
90
|
+
path.join(docsDir, "lib-browser.js"),
|
|
91
|
+
header + functionBodies.join("\n\n") + "\n"
|
|
92
|
+
);
|
|
93
|
+
console.log(
|
|
94
|
+
`Wrote docs/lib-browser.js (${exportNames.length} exports: ${exportNames.join(", ")})`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"main": "src/lib/main.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "npm run build:web",
|
|
9
|
-
"build:web": "
|
|
9
|
+
"build:web": "node .github/agentic-lib/scripts/build-web.cjs",
|
|
10
10
|
"test": "vitest --run tests/unit/*.test.js",
|
|
11
11
|
"test:unit": "vitest --run --coverage tests/unit/*.test.js",
|
|
12
12
|
"test:behaviour": "npm run build:web && npx playwright test --config playwright.config.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@xn-intenton-z2a/agentic-lib": "^7.2.
|
|
20
|
+
"@xn-intenton-z2a/agentic-lib": "^7.2.11"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@playwright/test": "^1.58.0",
|