@whzxc/agent-design-gallery 0.0.0-stage → 0.7.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 +69 -0
- package/README.md +218 -2
- package/package.json +43 -4
- package/public/access.css +10 -0
- package/public/app.js +1674 -0
- package/public/arrangement-worker.js +11 -0
- package/public/arrangement.js +49 -0
- package/public/assets.js +356 -0
- package/public/auth.js +69 -0
- package/public/favicon.svg +6 -0
- package/public/hub.css +67 -0
- package/public/hub.html +33 -0
- package/public/hub.js +165 -0
- package/public/icons.js +50 -0
- package/public/index.html +70 -0
- package/public/instance-actions.js +27 -0
- package/public/labels.js +122 -0
- package/public/layout.js +119 -0
- package/public/relationships.js +28 -0
- package/public/selection.js +20 -0
- package/public/style.css +194 -0
- package/public/switcher.css +37 -0
- package/public/switcher.js +176 -0
- package/public/token-catalog.js +129 -0
- package/public/tokens.css +61 -0
- package/public/view-route.js +66 -0
- package/src/cli-output.mjs +236 -0
- package/src/cli.mjs +176 -0
- package/src/http.mjs +38 -0
- package/src/hub/auth.mjs +41 -0
- package/src/hub/instances.mjs +99 -0
- package/src/hub/proxy.mjs +30 -0
- package/src/hub/registry.mjs +181 -0
- package/src/hub.mjs +128 -0
- package/src/lifecycle.mjs +109 -0
- package/src/link.mjs +55 -0
- package/src/open.mjs +61 -0
- package/src/perf.mjs +12 -0
- package/src/server.mjs +679 -0
- package/src/service.mjs +184 -0
- package/src/toolkit/arch-browser.mjs +40 -0
- package/src/toolkit/arch-git.mjs +55 -0
- package/src/toolkit/arch-overlay.mjs +225 -0
- package/src/toolkit/arch.mjs +221 -0
- package/src/toolkit/asset-rules.mjs +14 -0
- package/src/toolkit/browser.mjs +33 -0
- package/src/toolkit/build-store.mjs +266 -0
- package/src/toolkit/build-worker.mjs +35 -0
- package/src/toolkit/build.mjs +147 -0
- package/src/toolkit/commands.mjs +345 -0
- package/src/toolkit/compare.mjs +222 -0
- package/src/toolkit/config.mjs +136 -0
- package/src/toolkit/document.mjs +85 -0
- package/src/toolkit/migrate.mjs +85 -0
- package/src/toolkit/project.mjs +172 -0
- package/src/toolkit/results.mjs +44 -0
- package/src/toolkit/runtime.d.ts +14 -0
- package/src/toolkit/runtime.mjs +54 -0
- package/src/toolkit/text.mjs +12 -0
- package/src/toolkit/tokens.mjs +37 -0
- package/src/viewer-cache.mjs +85 -0
package/src/open.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { loadConfig } from './toolkit/config.mjs';
|
|
3
|
+
import { registerInstance } from './hub/instances.mjs';
|
|
4
|
+
import { defaultStateDirectory } from './hub/registry.mjs';
|
|
5
|
+
import { existsSync, unlinkSync } from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { startServer } from './server.mjs';
|
|
8
|
+
import { previewTarget, previewURL } from './link.mjs';
|
|
9
|
+
import { CliError, asCliError, sanitize } from './cli-output.mjs';
|
|
10
|
+
import { cleanup } from './toolkit/results.mjs';
|
|
11
|
+
|
|
12
|
+
export async function open(positionals, values, {
|
|
13
|
+
cwd = process.cwd(), startViewer = startServer, register = registerInstance, spawnBrowser = spawn,
|
|
14
|
+
onDiagnostic, onFatal,
|
|
15
|
+
} = {}) {
|
|
16
|
+
if (positionals.length > 1) throw new CliError('USAGE_INVALID','Expected one directory. Run adg --help.');
|
|
17
|
+
const target = previewTarget(values), port = values.port === undefined ? 0 : Number(values.port);
|
|
18
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new CliError('USAGE_INVALID','--port must be an integer from 0 to 65535.');
|
|
19
|
+
const input = path.resolve(cwd,positionals[0] ?? '.');
|
|
20
|
+
const config = await loadConfig(input);
|
|
21
|
+
if (values.base !== undefined && (!target.asset || target.asset.endsWith('.mmd'))) await (await import('./toolkit/arch-git.mjs')).resolveBase(config,values.base);
|
|
22
|
+
const directory = config.root === input && existsSync(config.design) ? config.design : input;
|
|
23
|
+
const stateDirectory = path.resolve(cwd,values['state-dir'] ?? defaultStateDirectory);
|
|
24
|
+
const server = await startViewer({directory,port,stateDirectory,onDiagnostic,onFatal});
|
|
25
|
+
let instance;
|
|
26
|
+
try { instance = await register({directory:server.directory,port:server.port,id:server.id,stateDirectory}); }
|
|
27
|
+
catch (cause) {
|
|
28
|
+
const primary = asCliError(cause);
|
|
29
|
+
await cleanup(() => server.close(),primary);
|
|
30
|
+
throw primary;
|
|
31
|
+
}
|
|
32
|
+
const exitCleanup = () => { try { unlinkSync(instance.file); } catch {} };
|
|
33
|
+
process.once('exit',exitCleanup);
|
|
34
|
+
const url = previewURL(server.url,target).href;
|
|
35
|
+
let closing;
|
|
36
|
+
return {
|
|
37
|
+
id:server.id,url,port:server.port,directory:server.directory,stateDirectory,
|
|
38
|
+
close() {
|
|
39
|
+
return closing ??= (async () => {
|
|
40
|
+
let primary;
|
|
41
|
+
try { await server.close(); }
|
|
42
|
+
catch (cause) { primary = new CliError('SHUTDOWN_FAILED',cause.message,{cause}); }
|
|
43
|
+
try { await cleanup(() => instance.remove(),primary); }
|
|
44
|
+
catch (cause) { primary = cause; }
|
|
45
|
+
finally { process.off('exit',exitCleanup); }
|
|
46
|
+
if (primary) throw primary;
|
|
47
|
+
})();
|
|
48
|
+
},
|
|
49
|
+
openBrowser() {
|
|
50
|
+
if (values['no-open']) return;
|
|
51
|
+
const command = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'rundll32.exe' : 'xdg-open';
|
|
52
|
+
const args = process.platform === 'win32' ? ['url.dll,FileProtocolHandler',url] : [url];
|
|
53
|
+
const warn=()=>{
|
|
54
|
+
const diagnostic={code:'BROWSER_OPEN_FAILED',message:`Open ${url} in your browser.`,next:[]};
|
|
55
|
+
if(onDiagnostic)onDiagnostic(diagnostic);else console.error(sanitize(diagnostic.message));
|
|
56
|
+
};
|
|
57
|
+
try {const child=spawnBrowser(command,args,{stdio:'ignore',detached:true});child.on('error',warn);child.unref();}
|
|
58
|
+
catch {warn();}
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
package/src/perf.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { appendFileSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
// Opt-in local diagnostics. Epoch timestamps align Node and browser spans.
|
|
4
|
+
const destination = process.env.ADG_PERF_LOG;
|
|
5
|
+
export function perfSpan(phase, source, detail = {}) {
|
|
6
|
+
if (!destination) return;
|
|
7
|
+
const start = performance.timeOrigin + performance.now();
|
|
8
|
+
return (extra = {}) => appendFileSync(destination, JSON.stringify({
|
|
9
|
+
phase, source, start, end: performance.timeOrigin + performance.now(),
|
|
10
|
+
pid: process.pid, ...detail, ...extra,
|
|
11
|
+
}) + '\n');
|
|
12
|
+
}
|