Chore/build npm (#9)

Co-authored-by: DigHuang <114602213+DigHuang@users.noreply.github.com>
Co-authored-by: Felix <24791380+vcfgv@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Haze
2026-02-09 15:10:08 +08:00
committed by GitHub
Unverified
parent 0b7f1c700e
commit de445ae3d5
37 changed files with 7359 additions and 1586 deletions

47
scripts/after-pack.cjs Normal file
View File

@@ -0,0 +1,47 @@
/**
* after-pack.cjs
*
* electron-builder afterPack hook.
*
* Problem: electron-builder respects .gitignore when copying extraResources.
* Since .gitignore contains "node_modules/", the openclaw bundle's
* node_modules directory is silently skipped during the extraResources copy.
*
* Solution: This hook runs AFTER electron-builder finishes packing. It manually
* copies build/openclaw/node_modules/ into the output resources directory,
* bypassing electron-builder's glob filtering entirely.
*/
const { cpSync, existsSync, readdirSync } = require('fs');
const { join } = require('path');
exports.default = async function afterPack(context) {
const appOutDir = context.appOutDir;
const platform = context.electronPlatformName; // 'win32' | 'darwin' | 'linux'
const src = join(__dirname, '..', 'build', 'openclaw', 'node_modules');
// On macOS, resources live inside the .app bundle
let resourcesDir;
if (platform === 'darwin') {
const appName = context.packager.appInfo.productFilename;
resourcesDir = join(appOutDir, `${appName}.app`, 'Contents', 'Resources');
} else {
resourcesDir = join(appOutDir, 'resources');
}
const dest = join(resourcesDir, 'openclaw', 'node_modules');
if (!existsSync(src)) {
console.warn('[after-pack] ⚠️ build/openclaw/node_modules not found. Run "pnpm run bundle:openclaw" first.');
return;
}
const depCount = readdirSync(src, { withFileTypes: true })
.filter(d => d.isDirectory() && d.name !== '.bin')
.length;
console.log(`[after-pack] Copying ${depCount} openclaw dependencies to ${dest} ...`);
cpSync(src, dest, { recursive: true });
console.log('[after-pack] ✅ openclaw node_modules copied successfully.');
};