mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 06:19:43 +08:00
44 lines
2.6 KiB
JavaScript
44 lines
2.6 KiB
JavaScript
import { packager } from '@electron/packager';
|
|
import { cp, mkdir, rm, symlink } from 'node:fs/promises';
|
|
import { execFileSync } from 'node:child_process';
|
|
import path from 'node:path';
|
|
import { appRoot } from './target.mjs';
|
|
import { PACKAGER, stageApp } from './stage.mjs';
|
|
|
|
/** Shared by platforms/macos-arm64 and platforms/macos-x64: a signed .app inside a DMG. */
|
|
export async function packageMac(target) {
|
|
const { stage, version, pkg, out } = await stageApp(target);
|
|
// With APPLE_SIGNING_IDENTITY ("Developer ID Application: …") the app gets a
|
|
// hardened-runtime Developer ID signature; otherwise it is signed ad hoc.
|
|
const identity = process.env.APPLE_SIGNING_IDENTITY;
|
|
const entitlements = path.join(appRoot, 'assets/entitlements.mac.plist');
|
|
const [built] = await packager({
|
|
...PACKAGER, dir: stage, out,
|
|
appVersion: version, buildVersion: version, electronVersion: pkg.devDependencies.electron,
|
|
platform: 'darwin', arch: target.arch, icon: path.join(appRoot, 'assets/icon.icns'),
|
|
extraResource: [target.seed],
|
|
appCategoryType: 'public.app-category.education',
|
|
extendInfo: {
|
|
NSMicrophoneUsageDescription: 'Open DeepTutor uses the microphone when you speak to your tutor.',
|
|
NSCameraUsageDescription: 'Open DeepTutor uses the camera when you capture learning material.',
|
|
NSLocalNetworkUsageDescription: 'Open DeepTutor runs its learning services on this Mac.',
|
|
},
|
|
...(identity ? { osxSign: { identity, optionsForFile: () => ({ hardenedRuntime: true, entitlements }) } } : {}),
|
|
});
|
|
const bundle = path.join(built, 'Open DeepTutor.app');
|
|
if (!identity) execFileSync('/usr/bin/codesign', ['--force', '--deep', '--sign', '-', bundle], { stdio: 'inherit' });
|
|
execFileSync('/usr/bin/codesign', ['--verify', '--deep', '--strict', bundle], { stdio: 'inherit' });
|
|
|
|
const dmgStage = path.join(target.local, 'dmg');
|
|
const dmg = path.join(out, `${target.artifact}-v${version}.dmg`);
|
|
await rm(dmgStage, { recursive: true, force: true });
|
|
await mkdir(dmgStage, { recursive: true });
|
|
await cp(bundle, path.join(dmgStage, 'Open DeepTutor.app'), { recursive: true, verbatimSymlinks: true });
|
|
await cp(path.join(built, 'LICENSES.chromium.html'), path.join(dmgStage, 'LICENSES.chromium.html'));
|
|
await symlink('/Applications', path.join(dmgStage, 'Applications'));
|
|
await rm(dmg, { force: true });
|
|
execFileSync('/usr/bin/hdiutil', ['create', '-volname', 'Open DeepTutor', '-srcfolder', dmgStage, '-fs', 'APFS', '-format', 'ULFO', dmg], { stdio: 'inherit' });
|
|
await rm(dmgStage, { recursive: true, force: true });
|
|
return [bundle, dmg];
|
|
}
|