/
MakerPKG.ts
44 lines (32 loc) · 1.33 KB
/
MakerPKG.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import path from 'path';
import { MakerBase, MakerOptions } from '@electron-forge/maker-base';
import { ForgePlatform } from '@electron-forge/shared-types';
import { flatAsync } from '@electron/osx-sign';
import { MakerPKGConfig } from './Config';
export default class MakerPKG extends MakerBase<MakerPKGConfig> {
name = 'pkg';
defaultPlatforms: ForgePlatform[] = ['darwin', 'mas'];
isSupportedOnCurrentPlatform(): boolean {
return process.platform === 'darwin';
}
async make({ dir, makeDir, appName, packageJSON, targetPlatform, targetArch }: MakerOptions): Promise<string[]> {
if (!this.isValidTargetPlatform(targetPlatform)) {
throw new Error(`The pkg maker only supports targeting "mas" and "darwin" builds. You provided "${targetPlatform}".`);
}
const name = this.config.name || `${appName}-${packageJSON.version}-${targetArch}`;
const outPath = path.resolve(makeDir, `${name}.pkg`);
await this.ensureFile(outPath);
const pkgConfig = {
...this.config,
app: path.resolve(dir, `${appName}.app`),
pkg: outPath,
platform: targetPlatform,
};
await flatAsync(pkgConfig);
return [outPath];
}
private isValidTargetPlatform(platform: string): platform is 'darwin' | 'mas' {
return this.defaultPlatforms.includes(platform);
}
}
export { MakerPKG, MakerPKGConfig };