Files
colanode/apps/mobile/scripts/copy-editor.js

76 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

Mobile: WebView-based page editor with TipTap (#345) * Mobile: replace inline page editor with WebView-based TipTap editor Replaces the plain-text block-by-block page editor with a Vite-built WebView that runs the full TipTap rich text editor. The editor HTML is bundled as a single self-contained asset, loaded via expo-asset and rendered in react-native-webview. Communication between RN and the WebView uses postMessage/onMessage bridge for init, mutations, queries, theme changes, and navigation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Mobile: reorganize WebView editor as standalone package Moves the editor WebView app from apps/mobile/src/editor-webview/ to apps/mobile/webviews/editor/ as a first-class build target with its own package.json, tsconfig.json, and vite.config.ts. This fixes TypeScript compilation (editor code no longer typechecked as React Native) and makes the build story clearer. - WebView editor is now at apps/mobile/webviews/editor/ - Built artifact copied to apps/mobile/assets/editor-dist/ on prestart - Vite dev server support for fast iteration - Tailwind CSS @source path fixed (../../../../packages/ui) - Page title editing restored via RenameNodeSheet - File preview now converts file:// to base64 data URLs for WebView - WebView hidden until ready to avoid white flash - Keyboard accessory bar hidden on iOS Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 13:43:17 +01:00
/**
* Copies the built editor HTML from apps/mobile/webviews/editor into the
* mobile app's assets directory so Metro can bundle it.
*
* Always rebuilds when the source is newer than the copied asset, so that
* stale assets cannot sneak through.
*/
const {
cpSync,
existsSync,
mkdirSync,
readdirSync,
statSync,
} = require('node:fs');
Mobile: WebView-based page editor with TipTap (#345) * Mobile: replace inline page editor with WebView-based TipTap editor Replaces the plain-text block-by-block page editor with a Vite-built WebView that runs the full TipTap rich text editor. The editor HTML is bundled as a single self-contained asset, loaded via expo-asset and rendered in react-native-webview. Communication between RN and the WebView uses postMessage/onMessage bridge for init, mutations, queries, theme changes, and navigation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Mobile: reorganize WebView editor as standalone package Moves the editor WebView app from apps/mobile/src/editor-webview/ to apps/mobile/webviews/editor/ as a first-class build target with its own package.json, tsconfig.json, and vite.config.ts. This fixes TypeScript compilation (editor code no longer typechecked as React Native) and makes the build story clearer. - WebView editor is now at apps/mobile/webviews/editor/ - Built artifact copied to apps/mobile/assets/editor-dist/ on prestart - Vite dev server support for fast iteration - Tailwind CSS @source path fixed (../../../../packages/ui) - Page title editing restored via RenameNodeSheet - File preview now converts file:// to base64 data URLs for WebView - WebView hidden until ready to avoid white flash - Keyboard accessory bar hidden on iOS Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 13:43:17 +01:00
const { resolve } = require('node:path');
const { execSync } = require('node:child_process');
const editorDir = resolve(__dirname, '../webviews/editor');
const editorSrcDir = resolve(editorDir, 'src');
const editorHtmlFile = resolve(editorDir, 'editor.html');
const editorPackageFile = resolve(editorDir, 'package.json');
const editorTsConfigFile = resolve(editorDir, 'tsconfig.json');
const editorViteConfigFile = resolve(editorDir, 'vite.config.ts');
Mobile: WebView-based page editor with TipTap (#345) * Mobile: replace inline page editor with WebView-based TipTap editor Replaces the plain-text block-by-block page editor with a Vite-built WebView that runs the full TipTap rich text editor. The editor HTML is bundled as a single self-contained asset, loaded via expo-asset and rendered in react-native-webview. Communication between RN and the WebView uses postMessage/onMessage bridge for init, mutations, queries, theme changes, and navigation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Mobile: reorganize WebView editor as standalone package Moves the editor WebView app from apps/mobile/src/editor-webview/ to apps/mobile/webviews/editor/ as a first-class build target with its own package.json, tsconfig.json, and vite.config.ts. This fixes TypeScript compilation (editor code no longer typechecked as React Native) and makes the build story clearer. - WebView editor is now at apps/mobile/webviews/editor/ - Built artifact copied to apps/mobile/assets/editor-dist/ on prestart - Vite dev server support for fast iteration - Tailwind CSS @source path fixed (../../../../packages/ui) - Page title editing restored via RenameNodeSheet - File preview now converts file:// to base64 data URLs for WebView - WebView hidden until ready to avoid white flash - Keyboard accessory bar hidden on iOS Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 13:43:17 +01:00
const srcFile = resolve(editorDir, 'dist/editor.html');
const destDir = resolve(__dirname, '../assets/editor-dist');
const destFile = resolve(destDir, 'editor.html');
function getLatestMtimeMs(path) {
const stats = statSync(path);
if (!stats.isDirectory()) {
return stats.mtimeMs;
}
let latest = stats.mtimeMs;
for (const entry of readdirSync(path, { withFileTypes: true })) {
latest = Math.max(latest, getLatestMtimeMs(resolve(path, entry.name)));
}
return latest;
}
function editorSourceMtimeMs() {
return Math.max(
getLatestMtimeMs(editorSrcDir),
getLatestMtimeMs(editorHtmlFile),
getLatestMtimeMs(editorPackageFile),
getLatestMtimeMs(editorTsConfigFile),
getLatestMtimeMs(editorViteConfigFile)
);
}
Mobile: WebView-based page editor with TipTap (#345) * Mobile: replace inline page editor with WebView-based TipTap editor Replaces the plain-text block-by-block page editor with a Vite-built WebView that runs the full TipTap rich text editor. The editor HTML is bundled as a single self-contained asset, loaded via expo-asset and rendered in react-native-webview. Communication between RN and the WebView uses postMessage/onMessage bridge for init, mutations, queries, theme changes, and navigation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Mobile: reorganize WebView editor as standalone package Moves the editor WebView app from apps/mobile/src/editor-webview/ to apps/mobile/webviews/editor/ as a first-class build target with its own package.json, tsconfig.json, and vite.config.ts. This fixes TypeScript compilation (editor code no longer typechecked as React Native) and makes the build story clearer. - WebView editor is now at apps/mobile/webviews/editor/ - Built artifact copied to apps/mobile/assets/editor-dist/ on prestart - Vite dev server support for fast iteration - Tailwind CSS @source path fixed (../../../../packages/ui) - Page title editing restored via RenameNodeSheet - File preview now converts file:// to base64 data URLs for WebView - WebView hidden until ready to avoid white flash - Keyboard accessory bar hidden on iOS Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 13:43:17 +01:00
function needsBuild() {
if (!existsSync(srcFile)) return true;
return editorSourceMtimeMs() > statSync(srcFile).mtimeMs;
}
function needsCopy() {
if (!existsSync(srcFile)) return false;
Mobile: WebView-based page editor with TipTap (#345) * Mobile: replace inline page editor with WebView-based TipTap editor Replaces the plain-text block-by-block page editor with a Vite-built WebView that runs the full TipTap rich text editor. The editor HTML is bundled as a single self-contained asset, loaded via expo-asset and rendered in react-native-webview. Communication between RN and the WebView uses postMessage/onMessage bridge for init, mutations, queries, theme changes, and navigation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Mobile: reorganize WebView editor as standalone package Moves the editor WebView app from apps/mobile/src/editor-webview/ to apps/mobile/webviews/editor/ as a first-class build target with its own package.json, tsconfig.json, and vite.config.ts. This fixes TypeScript compilation (editor code no longer typechecked as React Native) and makes the build story clearer. - WebView editor is now at apps/mobile/webviews/editor/ - Built artifact copied to apps/mobile/assets/editor-dist/ on prestart - Vite dev server support for fast iteration - Tailwind CSS @source path fixed (../../../../packages/ui) - Page title editing restored via RenameNodeSheet - File preview now converts file:// to base64 data URLs for WebView - WebView hidden until ready to avoid white flash - Keyboard accessory bar hidden on iOS Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 13:43:17 +01:00
if (!existsSync(destFile)) return true;
return statSync(srcFile).mtimeMs > statSync(destFile).mtimeMs;
}
if (needsBuild()) {
console.log('[copy-editor] Building @colanode/mobile-editor...');
execSync('npm run build', { cwd: editorDir, stdio: 'inherit' });
}
if (needsCopy()) {
Mobile: WebView-based page editor with TipTap (#345) * Mobile: replace inline page editor with WebView-based TipTap editor Replaces the plain-text block-by-block page editor with a Vite-built WebView that runs the full TipTap rich text editor. The editor HTML is bundled as a single self-contained asset, loaded via expo-asset and rendered in react-native-webview. Communication between RN and the WebView uses postMessage/onMessage bridge for init, mutations, queries, theme changes, and navigation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Mobile: reorganize WebView editor as standalone package Moves the editor WebView app from apps/mobile/src/editor-webview/ to apps/mobile/webviews/editor/ as a first-class build target with its own package.json, tsconfig.json, and vite.config.ts. This fixes TypeScript compilation (editor code no longer typechecked as React Native) and makes the build story clearer. - WebView editor is now at apps/mobile/webviews/editor/ - Built artifact copied to apps/mobile/assets/editor-dist/ on prestart - Vite dev server support for fast iteration - Tailwind CSS @source path fixed (../../../../packages/ui) - Page title editing restored via RenameNodeSheet - File preview now converts file:// to base64 data URLs for WebView - WebView hidden until ready to avoid white flash - Keyboard accessory bar hidden on iOS Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 13:43:17 +01:00
mkdirSync(destDir, { recursive: true });
cpSync(srcFile, destFile);
console.log('[copy-editor] Copied editor.html to assets/editor-dist/');
} else {
console.log('[copy-editor] Asset up to date, skipping copy.');
}