| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- 'use strict';
- const { execFileSync } = require('node:child_process');
- const fs = require('node:fs');
- const path = require('node:path');
- /**
- * electron-builder afterPack hook.
- *
- * - Ensure the bundled luatos-cli has the executable bit.
- * - On macOS, ad-hoc sign (or sign with CSC_NAME) the sidecar binary. The app
- * bundle itself is handled by electron-builder; if no Developer ID is
- * configured, macOS users can still run the app after clearing quarantine.
- */
- module.exports = async function afterPack(context) {
- const productName = context.packager?.appInfo?.productFilename || 'LuatOS Flasher';
- const isMac = process.platform === 'darwin';
- const appDir = path.join(context.appOutDir, `${productName}.app`);
- const binDir = isMac
- ? path.join(appDir, 'Contents', 'Resources', 'bin')
- : path.join(context.appOutDir, 'resources', 'bin');
- const cli = path.join(binDir, isMac ? 'luatos-cli' : 'luatos-cli.exe');
- if (!fs.existsSync(cli)) {
- console.warn(`[afterPack] 未找到 ${cli}`);
- return;
- }
- if (!isMac) {
- console.log(`[afterPack] 已打包烧录内核:${cli}`);
- return;
- }
- try {
- fs.chmodSync(cli, 0o755);
- } catch (error) {
- console.warn(`[afterPack] chmod 失败:${error.message}`);
- }
- const identity = process.env.CSC_NAME || '-';
- try {
- execFileSync('codesign', ['--force', '--sign', identity, cli], { stdio: 'inherit' });
- console.log(`[afterPack] 已签名 ${cli}(identity=${identity})`);
- } catch (error) {
- console.warn(`[afterPack] codesign 失败(可忽略,稍后可手动签):${error.message}`);
- }
- };
|