Every Archify page can show its file's YAML in place. Diagrams get Diagram | Graph | Source (Graph only inside a model), main.archify Model | Graph | Source, registry and decision pages View | Source, and the Graph page a Source segment. 2D | 3D moves left of that switch and hides while Source shows. The YAML opens in a CodeMirror editor inside the page (dist/source.js, loaded on first use), themed with the page's colours. Edits go to the VS Code document as WorkspaceEdits; outside changes come back to the page. Undo and redo are the editor's own, since VS Code sends ⌘Z in a focused webview to the webview; save and find stay VS Code's. Problems come from the host only (what the Problems panel holds for the file) and are counted on the Source segment; completion and hover come from the schema, folded into one draft-07 document per diagram type. The host now checks .archify files against the extension's schema with ajv on the YAML as written, before archify validate, and checks .archify-registry files against the registry schema for the first time. Registry and decision pages become text editor providers. While Source shows, new renders wait and appear when the picture comes back. Show Source switches the page to Source; Open in Text Editor (the editor title button) opens the text beside it, as Show Source did. The decision schema is no longer given to the YAML extension. Fixed: YAML errors in registry and decision files were reported on line 1; "Webview is disposed" when a diagram closed mid-render; the model heading under the toolbar in narrow editors.
90 lines
2.7 KiB
JavaScript
90 lines
2.7 KiB
JavaScript
import * as esbuild from 'esbuild';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const production = process.argv.includes('--production');
|
|
const watch = process.argv.includes('--watch');
|
|
const tests = process.argv.includes('--tests');
|
|
|
|
const common = {
|
|
bundle: true,
|
|
format: 'cjs',
|
|
platform: 'node',
|
|
target: 'node20',
|
|
sourcemap: !production,
|
|
minify: production,
|
|
logLevel: 'info',
|
|
// jsonc-parser's UMD entry uses dynamic requires esbuild cannot follow.
|
|
mainFields: ['module', 'main'],
|
|
};
|
|
|
|
// codemirror-json-schema formats schema descriptions with markdown-it and
|
|
// shiki (about 400 KB); a small stub does what our descriptions need.
|
|
const stubMarkdown = {
|
|
name: 'stub-markdown',
|
|
setup(build) {
|
|
build.onResolve({ filter: /utils\/markdown(\.js)?$/ }, (args) =>
|
|
args.importer.includes('codemirror-json-schema') ? { path: path.resolve('src/webview/source/markdownStub.ts') } : undefined,
|
|
);
|
|
},
|
|
};
|
|
|
|
if (tests) {
|
|
// Unit tests cover the modules that do not import 'vscode'; the
|
|
// integration suite runs inside VS Code, which provides it.
|
|
const entryPoints = fs.readdirSync('test')
|
|
.filter((file) => file.endsWith('.test.ts'))
|
|
.map((file) => path.join('test', file));
|
|
await esbuild.build({ ...common, entryPoints, outdir: 'out/test', sourcemap: true });
|
|
await esbuild.build({
|
|
...common,
|
|
entryPoints: ['test/integration/suite.ts'],
|
|
outfile: 'out/test/integration/suite.js',
|
|
external: ['vscode'],
|
|
sourcemap: true,
|
|
});
|
|
} else {
|
|
const contexts = await Promise.all([
|
|
esbuild.context({
|
|
...common,
|
|
entryPoints: ['src/extension.ts'],
|
|
outfile: 'dist/extension.js',
|
|
external: ['vscode'],
|
|
}),
|
|
// Runs inside the Archify page in the webview; three.js is bundled in.
|
|
esbuild.context({
|
|
...common,
|
|
format: 'iife',
|
|
platform: 'browser',
|
|
target: 'es2022',
|
|
entryPoints: ['src/viewer3d/index.ts'],
|
|
outfile: 'dist/viewer3d.js',
|
|
}),
|
|
// The Graph page of a model; Cytoscape.js is bundled in.
|
|
esbuild.context({
|
|
...common,
|
|
format: 'iife',
|
|
platform: 'browser',
|
|
target: 'es2022',
|
|
entryPoints: ['src/graph/index.ts'],
|
|
outfile: 'dist/graph.js',
|
|
}),
|
|
// The Source view; CodeMirror is bundled in. Loaded the first time Source is chosen.
|
|
esbuild.context({
|
|
...common,
|
|
format: 'iife',
|
|
platform: 'browser',
|
|
target: 'es2022',
|
|
entryPoints: ['src/webview/source/index.ts'],
|
|
outfile: 'dist/source.js',
|
|
plugins: [stubMarkdown],
|
|
}),
|
|
]);
|
|
if (watch) {
|
|
await Promise.all(contexts.map((ctx) => ctx.watch()));
|
|
} else {
|
|
await Promise.all(contexts.map((ctx) => ctx.rebuild()));
|
|
await Promise.all(contexts.map((ctx) => ctx.dispose()));
|
|
}
|
|
}
|