mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-24 18:02:47 +08:00
feat: custom maker dmg (#3501)
This commit is contained in:
7
packages/maker-dmg/README.md
Normal file
7
packages/maker-dmg/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# @affine/maker-dmg
|
||||
|
||||
## Pre-requisites
|
||||
|
||||
```shell
|
||||
brew install create-dmg
|
||||
```
|
||||
18
packages/maker-dmg/package.json
Normal file
18
packages/maker-dmg/package.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@affine/maker-dmg",
|
||||
"version": "1.0.0",
|
||||
"main": "dist/maker.js",
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"dev": "vite build --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@electron-forge/maker-base": "^6.2.1",
|
||||
"@electron-forge/shared-types": "^6.2.1",
|
||||
"fs-extra": "^11.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.1.6",
|
||||
"vite": "^4.4.7"
|
||||
}
|
||||
}
|
||||
21
packages/maker-dmg/project.json
Normal file
21
packages/maker-dmg/project.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@affine/maker-dmg",
|
||||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "library",
|
||||
"sourceRoot": "packages/maker-dmg/src",
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nx/vite:build",
|
||||
"options": {
|
||||
"outputPath": "packages/maker-dmg/dist"
|
||||
}
|
||||
},
|
||||
"serve": {
|
||||
"executor": "@nx/vite:build",
|
||||
"options": {
|
||||
"outputPath": "packages/maker-dmg/dist",
|
||||
"watch": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
74
packages/maker-dmg/src/config.ts
Normal file
74
packages/maker-dmg/src/config.ts
Normal file
@@ -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;
|
||||
}
|
||||
77
packages/maker-dmg/src/maker.ts
Normal file
77
packages/maker-dmg/src/maker.ts
Normal file
@@ -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];
|
||||
}
|
||||
}
|
||||
9
packages/maker-dmg/tsconfig.json
Normal file
9
packages/maker-dmg/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["./src"],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"noEmit": false,
|
||||
"outDir": "lib"
|
||||
}
|
||||
}
|
||||
29
packages/maker-dmg/vite.config.ts
Normal file
29
packages/maker-dmg/vite.config.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { fileURLToPath } from 'url';
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
const root = fileURLToPath(new URL('.', import.meta.url));
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
emptyOutDir: true,
|
||||
minify: false,
|
||||
lib: {
|
||||
entry: {
|
||||
maker: resolve(root, 'src/maker.ts'),
|
||||
},
|
||||
formats: ['cjs'],
|
||||
},
|
||||
rollupOptions: {
|
||||
output: {
|
||||
exports: 'named',
|
||||
},
|
||||
external: [
|
||||
'@electron-forge/maker-base',
|
||||
'@electron-forge/shared-types',
|
||||
/^node:/,
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user