Files
genoffice/tools/build-stale-preloads.mjs
T
merrick-2002andGenOffice f68df70e22 Sync snapshot (2026-08-20) (#123)
- Add fully local PDF to Word, PowerPoint, and Excel conversion
- Add bring-your-own-key AI providers - Claude, OpenAI, Gemini, DeepSeek, Kimi, GLM, Qwen, Doubao, MiniMax, Grok, Mistral, OpenRouter, and custom OpenAI-compatible endpoints - with a refreshed AI settings UI
- Rework the Slides AI editing surface: canonical edit-op registry, atomic transactions with rollback, durable element ids, and batched apply_ops
- Improve Slides fidelity: chart, font, gradient, table-style, and text-shaping fixes, plus PPT-parity line editing and adjust handles
- Polish Docs: password-protection dialogs, anchored-image wrapping fixes, and selection and clipboard fixes
- Add themed dropdowns suite-wide with accent-derived selection states

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-08-21 00:33:18 +08:00

47 lines
1.8 KiB
JavaScript

/**
* Rebuild app preloads whose sources are newer than the built artifact.
*
* In dev mode the shell loads each app's preload from apps/<app>/out/preload/
* straight off disk; `npm run dev` only starts renderer vite servers and never
* rebuilds preloads, so after a pull the artifact can silently miss newly added
* preload APIs (calls fail with "... is not a function" in the renderer console
* only). Runs as the root `predev` hook: a fresh tree is a fast no-op, a stale
* app gets a full `electron-vite build` (the only entry point that emits the
* preload bundle).
*/
import { existsSync, readdirSync, statSync } from 'node:fs'
import { join } from 'node:path'
import { spawnSync } from 'node:child_process'
const APPS = ['docs', 'sheets', 'slides', 'pdf', 'markdown']
/** Newest mtime (ms) under dir, 0 when missing. */
function newestMtime(dir) {
if (!existsSync(dir)) return 0
let newest = 0
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const p = join(dir, entry.name)
newest = Math.max(newest, entry.isDirectory() ? newestMtime(p) : statSync(p).mtimeMs)
}
return newest
}
const stale = APPS.filter((app) => {
const artifact = join('apps', app, 'out', 'preload', 'index.js')
const built = existsSync(artifact) ? statSync(artifact).mtimeMs : 0
// shared/ is included: preloads import IPC channel/type modules from there
const src = Math.max(
newestMtime(join('apps', app, 'src', 'preload')),
newestMtime(join('apps', app, 'src', 'shared')),
)
return src > built
})
if (stale.length) {
console.log(`Rebuilding stale preloads: ${stale.join(', ')}`)
for (const app of stale) {
const r = spawnSync('npm', ['run', 'build', '-w', `@genoffice/${app}`], { stdio: 'inherit' })
if (r.status !== 0) process.exit(r.status ?? 1)
}
}