Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ Renders a space in a plugin-provided format. Use `sctx render list [space]` to l

- `markdown.bullets` — Indented bullet list tree (outputs to stdout or `--out <file>`).
- `markdown.directory` — Markdown space directory with one file per node. Writes to `--out <dir>` (refuses to overwrite existing files unless `--force` is passed). Flat directory by default, or organized into per-type subfolders with `--data folders=type` or when configured with `typeInference.folderMap`. Without `--out`, prints a summary of files to be written.
- `map-views.html` — One self-contained interactive HTML file of the space and its map views, with `--out <file>`. Options: [sctx-map-views](https://github.com/mindsocket/structured-context-map-views/tree/main/packages/sctx-map-views#readme).

### Show space tree

Expand Down
3 changes: 3 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"mdast-util-to-string": "^4.0.0",
"remark-gfm": "^4.0.1",
"remark-parse": "^11.0.0",
"sctx-map-views": "^0.6.2",
"unified": "^11.0.5",
"unist-util-visit": "^5.1.0"
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/builtin-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { normalizePluginName } from './util';
export const BUILTIN_PLUGIN_NAMES = {
markdown: `${PLUGIN_PREFIX}markdown`,
mermaid: `${PLUGIN_PREFIX}mermaid`,
mapViews: `${PLUGIN_PREFIX}map-views`,
miro: `${PLUGIN_PREFIX}miro`,
} as const;

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { mapViewsPlugin } from './map-views';
import { markdownPlugin } from './markdown';
import { mermaidPlugin } from './mermaid';
import { miroPlugin } from './miro';
import type { StructuredContextPlugin } from './util';

/** All built-in plugins, in default load order. */
export const builtinPlugins: StructuredContextPlugin[] = [markdownPlugin, mermaidPlugin, miroPlugin];
export const builtinPlugins: StructuredContextPlugin[] = [markdownPlugin, mermaidPlugin, miroPlugin, mapViewsPlugin];
15 changes: 15 additions & 0 deletions src/plugins/map-views/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BUILTIN_PLUGIN_NAMES } from '../builtin-names';
import type { StructuredContextPlugin } from '../util';

/** Loads the `sctx-map-views` package only to render: it bundles the map view library, which would slow every command's start. */
export const mapViewsPlugin: StructuredContextPlugin = {
name: BUILTIN_PLUGIN_NAMES.mapViews,
configSchema: { type: 'object', additionalProperties: false },
render: {
formats: [{ name: 'html', description: 'Self-contained interactive HTML page of the space and its map views' }],
async render(context, graph, options) {
const { default: plugin } = (await import('sctx-map-views')) as { default: StructuredContextPlugin };
return plugin.render!.render(context, graph, options);
},
},
};
3 changes: 2 additions & 1 deletion tests/plugins/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ describe('loadPlugins', () => {
describe('built-in plugins', () => {
it('always includes built-in plugins when no map is given', async () => {
const loaded = await loadPlugins({}, CONFIG_DIR);
expect(loaded).toHaveLength(3);
expect(loaded).toHaveLength(4);
expect(loaded.map((l) => l.plugin.name)).toContain('sctx-markdown');
expect(loaded.map((l) => l.plugin.name)).toContain('sctx-mermaid');
expect(loaded.map((l) => l.plugin.name)).toContain('sctx-miro');
expect(loaded.map((l) => l.plugin.name)).toContain('sctx-map-views');
expect(loaded.find((l) => l.plugin.name === 'sctx-markdown')!.pluginConfig).toEqual({});
expect(loaded.find((l) => l.plugin.name === 'sctx-mermaid')!.pluginConfig).toEqual({});
expect(loaded.find((l) => l.plugin.name === 'sctx-miro')!.pluginConfig).toEqual({});
Expand Down
30 changes: 30 additions & 0 deletions tests/plugins/map-views.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import plugin from 'sctx-map-views';
import { mapViewsPlugin } from '../../src/plugins/map-views';
import { executeRender } from '../../src/render/render';
import { makeSpaceContext } from '../helpers/context';

let dir: string;
beforeAll(() => {
dir = mkdtempSync(join(tmpdir(), 'sctx-map-views-'));
mkdirSync(join(dir, 'space'));
writeFileSync(join(dir, 'space', 'Vision.md'), '---\ntype: vision\n---\n# Vision\n');
});
afterAll(() => rmSync(dir, { recursive: true, force: true }));

describe('built-in map-views plugin', () => {
it('offers the formats of the package it imports on render', () => {
expect(mapViewsPlugin.render!.formats).toEqual(plugin.render!.formats);
});

it('renders a space to one HTML page', async () => {
const page = (await executeRender('map-views.html', makeSpaceContext(join(dir, 'space')), {})) as string;
const snapshots = JSON.parse(/id="sctx-snapshots">(.*?)<\/script>/s.exec(page)![1]!);
expect(snapshots).toHaveLength(1);
expect(snapshots[0].graph.nodes).toHaveLength(1);
expect(snapshots[0].definitions.map((d: { id: string }) => d.id)).toContain('sctx-map-view://core/strategy-tree');
});
});
Loading