mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 22:09:08 +08:00
feat: custom maker dmg (#3501)
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
export interface CodeSignOptions {
|
||||
'signing-identity': string;
|
||||
identifier?: string;
|
||||
}
|
||||
|
||||
export interface DMGContents {
|
||||
x: number;
|
||||
y: number;
|
||||
type: 'link' | 'file' | 'position';
|
||||
path: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface WindowPositionOptions {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
export interface WindowSizeOptions {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export interface WindowOptions {
|
||||
position?: WindowPositionOptions;
|
||||
size?: WindowSizeOptions;
|
||||
}
|
||||
|
||||
export interface AdditionalDMGOptions {
|
||||
'background-color'?: string;
|
||||
'icon-size'?: number;
|
||||
window?: WindowOptions;
|
||||
'code-sign'?: CodeSignOptions;
|
||||
}
|
||||
|
||||
export interface MakerDMGConfig {
|
||||
/**
|
||||
* The application name
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* Path to the background for the DMG window
|
||||
*/
|
||||
background: string;
|
||||
/**
|
||||
* Path to the icon to use for the app in the DMG window
|
||||
*/
|
||||
icon: string;
|
||||
/**
|
||||
* Overwrite an existing DMG file if if already exists
|
||||
*/
|
||||
overwrite?: boolean;
|
||||
/**
|
||||
* Enable debug message output
|
||||
*/
|
||||
debug?: boolean;
|
||||
/**
|
||||
* How big to make the icon for the app in the DMG
|
||||
*/
|
||||
iconSize?: number;
|
||||
/**
|
||||
* Disk image format
|
||||
*
|
||||
* Default: UDZO
|
||||
*/
|
||||
format?: 'UDRW' | 'UDRO' | 'UDCO' | 'UDZO' | 'UDBZ' | 'ULFO';
|
||||
file: string;
|
||||
/**
|
||||
* Additional options to pass through to node-appdmng
|
||||
*
|
||||
* All available options are available in the [`appdmg` docs](https://github.com/LinusU/node-appdmg)
|
||||
*/
|
||||
additionalDMGOptions?: AdditionalDMGOptions;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { cp, mkdtemp } from 'node:fs/promises';
|
||||
import os from 'node:os';
|
||||
import { join, resolve } from 'node:path';
|
||||
|
||||
import type { MakerOptions } from '@electron-forge/maker-base';
|
||||
import { MakerBase } from '@electron-forge/maker-base';
|
||||
import type { ForgePlatform } from '@electron-forge/shared-types';
|
||||
|
||||
import type { MakerDMGConfig } from './config';
|
||||
|
||||
export default class MakerDMG extends MakerBase<MakerDMGConfig> {
|
||||
name = 'dmg';
|
||||
|
||||
defaultPlatforms: ForgePlatform[] = ['darwin', 'mas'];
|
||||
|
||||
override isSupportedOnCurrentPlatform(): boolean {
|
||||
return process.platform === 'darwin';
|
||||
}
|
||||
|
||||
override async make({
|
||||
dir,
|
||||
makeDir,
|
||||
appName,
|
||||
packageJSON,
|
||||
targetArch,
|
||||
}: MakerOptions): Promise<string[]> {
|
||||
const outPath = resolve(makeDir, `${this.config.name || appName}.dmg`);
|
||||
const forgeDefaultOutPath = resolve(
|
||||
makeDir,
|
||||
`${appName}-${packageJSON.version}-${targetArch}.dmg`
|
||||
);
|
||||
|
||||
await this.ensureFile(outPath);
|
||||
|
||||
const args = [
|
||||
'--volname',
|
||||
appName,
|
||||
'--window-size',
|
||||
'610',
|
||||
'365',
|
||||
'--background',
|
||||
this.config.background,
|
||||
'--icon-size',
|
||||
'128',
|
||||
'--icon',
|
||||
`${appName}.app`,
|
||||
'176',
|
||||
'192',
|
||||
'--hide-extension',
|
||||
`${appName}.app`,
|
||||
'--app-drop-link',
|
||||
'423',
|
||||
'192',
|
||||
];
|
||||
|
||||
const tempDir = await mkdtemp(join(os.tmpdir(), 'electron-forge-dmg-'));
|
||||
const filePath = join(tempDir, `${appName}.app`);
|
||||
try {
|
||||
await cp(this.config.file, filePath, {
|
||||
recursive: true,
|
||||
});
|
||||
args.push(outPath, filePath);
|
||||
|
||||
execFileSync('create-dmg', args, {
|
||||
cwd: dir,
|
||||
env: process.env,
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
});
|
||||
} finally {
|
||||
// await rm(filePath, { force: true });
|
||||
}
|
||||
|
||||
return [forgeDefaultOutPath];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user