Files
next-ai-draw-io/scripts/afterPack.cjs
T
dayuan.jiang 610ba6872d refactor(electron): remove the configuration-preset system and read .env with dotenv
- delete electron/settings, the settings preload and window, the
  config-presets IPC channels, the Configuration menu and the preset
  watcher in scripts/electron-dev.mjs; config-manager.ts keeps only the
  user locale (still read from config-presets.json so the saved
  language survives)
- electron/main/env-loader.ts parses .env with dotenv instead of a
  hand-written parser; electron:compile bundles dependencies
- drop the unreachable development branches in port-manager.ts and
  next-server.ts, the duplicated locale normalisation in menu-i18n.ts,
  the unused electronAPI members, resources/entitlements.mac.plist
- scripts/copy-dereferenced.cjs shared by afterPack and
  prepare-electron-build
- CI: delete ci.yml, move type check and concurrency into test.yml,
  Node 24 everywhere, docker-build only on main
- remove unused dependencies (@xmldom/xmldom, remark-gfm,
  @anthropic-ai/tokenizer, @testing-library/user-event, concurrently,
  wait-on, eslint, eslint-config-next, @vitest/coverage-v8, shx),
  .eslintrc.json and the vitest coverage block
2026-10-12 08:11:10 +09:00

65 lines
2.4 KiB
JavaScript

/**
* electron-builder afterPack hook
* Copies node_modules to the standalone directory in the packaged app
* and ad-hoc signs macOS apps for offline draw.io bundle compatibility
*/
const { existsSync } = require("fs")
const path = require("path")
const { execSync } = require("child_process")
const copyDereferenced = require("./copy-dereferenced.cjs")
module.exports = async (context) => {
const appOutDir = context.appOutDir
const resourcesDir = path.join(
appOutDir,
context.packager.platform.name === "mac"
? `${context.packager.appInfo.productFilename}.app/Contents/Resources`
: "resources",
)
const standaloneDir = path.join(resourcesDir, "standalone")
const sourceNodeModules = path.join(
context.packager.projectDir,
"electron-standalone",
"node_modules",
)
const targetNodeModules = path.join(standaloneDir, "node_modules")
console.log(`[afterPack] Copying node_modules to ${targetNodeModules}`)
if (existsSync(sourceNodeModules) && existsSync(standaloneDir)) {
copyDereferenced(sourceNodeModules, targetNodeModules)
console.log("[afterPack] node_modules copied successfully")
} else {
console.error("[afterPack] Source or target directory not found!")
console.error(
` Source: ${sourceNodeModules} exists: ${existsSync(sourceNodeModules)}`,
)
console.error(
` Target dir: ${standaloneDir} exists: ${existsSync(standaloneDir)}`,
)
throw new Error(
"[afterPack] Failed: Required directories not found. " +
"Ensure 'npm run electron:prepare' was run before building.",
)
}
// Ad-hoc sign macOS apps to fix signature issues with bundled draw.io files
if (context.packager.platform.name === "mac") {
const appPath = path.join(
appOutDir,
`${context.packager.appInfo.productFilename}.app`,
)
console.log(`[afterPack] Ad-hoc signing macOS app: ${appPath}`)
try {
execSync(`codesign --force --deep --sign - "${appPath}"`, {
stdio: "inherit",
})
console.log("[afterPack] Ad-hoc signing completed successfully")
} catch (error) {
console.error("[afterPack] Ad-hoc signing failed:", error.message)
throw error
}
}
}