mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-18 17:05:48 +00:00
A document-mode plugin under packages/plugin-dev/document-mode/ that renders the active work context's tasks as an editable TipTap document. Per-context doc state is persisted as a last-writer-wins JSON blob via PluginAPI.persistDataSynced; task identity (title, done state, hierarchy) stays in NgRx and is reached through PluginAPI.updateTask and the ANY_TASK_UPDATE hook. It registers a work-context header button and embeds itself into the work-view embed slot added in the preceding commit. See docs/plans/2026-05-21-document-mode-tiptap-plugin.md for the full design. Squashed from the feat/doc-mode-v4 work; full per-step history is preserved in the archive/doc-mode-v4-full-history branch and the doc-mode-v4-pre-squash tag.
73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { build } = require('esbuild');
|
|
|
|
const ROOT_DIR = path.join(__dirname, '..');
|
|
const SRC_DIR = path.join(ROOT_DIR, 'src');
|
|
const DIST_DIR = path.join(ROOT_DIR, 'dist');
|
|
|
|
async function buildPlugin() {
|
|
console.log('Building document-mode plugin with esbuild...');
|
|
|
|
if (fs.existsSync(DIST_DIR)) {
|
|
fs.rmSync(DIST_DIR, { recursive: true });
|
|
}
|
|
fs.mkdirSync(DIST_DIR);
|
|
|
|
// Background script — runs in the host page context, registers UI + hooks.
|
|
console.log('Building plugin.js (background)...');
|
|
await build({
|
|
entryPoints: [path.join(SRC_DIR, 'background.ts')],
|
|
bundle: true,
|
|
outfile: path.join(DIST_DIR, 'plugin.js'),
|
|
platform: 'browser',
|
|
target: 'es2020',
|
|
format: 'iife',
|
|
globalName: 'DocumentModePlugin',
|
|
logLevel: 'info',
|
|
minify: true,
|
|
sourcemap: false,
|
|
});
|
|
|
|
// Editor bundle — runs inside the iframe, hosts TipTap.
|
|
console.log('Building editor.js (iframe)...');
|
|
await build({
|
|
entryPoints: [path.join(SRC_DIR, 'ui', 'editor.ts')],
|
|
bundle: true,
|
|
outfile: path.join(DIST_DIR, 'editor.js'),
|
|
platform: 'browser',
|
|
target: 'es2020',
|
|
format: 'iife',
|
|
logLevel: 'info',
|
|
minify: true,
|
|
sourcemap: false,
|
|
});
|
|
|
|
// The iframe is loaded via blob URL, so relative <script src="editor.js">
|
|
// does not resolve. Inline the bundle into index.html instead.
|
|
const editorJs = fs.readFileSync(path.join(DIST_DIR, 'editor.js'), 'utf8');
|
|
const rawHtml = fs.readFileSync(path.join(SRC_DIR, 'ui', 'index.html'), 'utf8');
|
|
// Function-form replacement so `$&`, ``$`` ``, etc. in the bundle aren't
|
|
// interpreted as replace() back-references. Also escape any literal
|
|
// `</script>` inside the JS so the HTML parser doesn't close the tag early.
|
|
const safeEditorJs = editorJs.replace(/<\/script>/gi, '<\\/script>');
|
|
const inlinedHtml = rawHtml.replace(
|
|
/<script src="editor\.js"><\/script>/,
|
|
() => `<script>${safeEditorJs}</script>`,
|
|
);
|
|
fs.writeFileSync(path.join(DIST_DIR, 'index.html'), inlinedHtml);
|
|
fs.copyFileSync(
|
|
path.join(SRC_DIR, 'manifest.json'),
|
|
path.join(DIST_DIR, 'manifest.json'),
|
|
);
|
|
fs.copyFileSync(path.join(SRC_DIR, 'icon.svg'), path.join(DIST_DIR, 'icon.svg'));
|
|
|
|
console.log('\nBuild complete! Output in dist/');
|
|
}
|
|
|
|
buildPlugin().catch((err) => {
|
|
console.error('Build failed:', err);
|
|
process.exit(1);
|
|
});
|