1 | import MakerBase, { MakerOptions } from '@electron-forge/maker-base';
|
2 | import { ForgePlatform } from '@electron-forge/shared-types';
|
3 |
|
4 | import { convertVersion, createWindowsInstaller, Options as ElectronWinstallerOptions } from 'electron-winstaller';
|
5 | import fs from 'fs-extra';
|
6 | import path from 'path';
|
7 |
|
8 | type MakerSquirrelConfig = Omit<ElectronWinstallerOptions, 'appDirectory' | 'outputDirectory'>;
|
9 |
|
10 | export default class MakerSquirrel extends MakerBase<MakerSquirrelConfig> {
|
11 | name = 'squirrel';
|
12 |
|
13 | defaultPlatforms: ForgePlatform[] = ['win32'];
|
14 |
|
15 | isSupportedOnCurrentPlatform(): boolean {
|
16 | return this.isInstalled('electron-winstaller') && !process.env.DISABLE_SQUIRREL_TEST;
|
17 | }
|
18 |
|
19 | async make({ dir, makeDir, targetArch, packageJSON, appName, forgeConfig }: MakerOptions): Promise<string[]> {
|
20 | const outPath = path.resolve(makeDir, `squirrel.windows/${targetArch}`);
|
21 | await this.ensureDirectory(outPath);
|
22 |
|
23 | const winstallerConfig: ElectronWinstallerOptions = {
|
24 | name: packageJSON.name,
|
25 | title: appName,
|
26 | noMsi: true,
|
27 | exe: `${forgeConfig.packagerConfig.executableName || appName}.exe`,
|
28 | setupExe: `${appName}-${packageJSON.version} Setup.exe`,
|
29 | ...this.config,
|
30 | appDirectory: dir,
|
31 | outputDirectory: outPath,
|
32 | };
|
33 |
|
34 | await createWindowsInstaller(winstallerConfig);
|
35 |
|
36 | const nupkgVersion = convertVersion(packageJSON.version);
|
37 |
|
38 | const artifacts = [
|
39 | path.resolve(outPath, 'RELEASES'),
|
40 | path.resolve(outPath, winstallerConfig.setupExe || `${appName}Setup.exe`),
|
41 | path.resolve(outPath, `${winstallerConfig.name}-${nupkgVersion}-full.nupkg`),
|
42 | ];
|
43 | const deltaPath = path.resolve(outPath, `${winstallerConfig.name}-${nupkgVersion}-delta.nupkg`);
|
44 | if (winstallerConfig.remoteReleases || (await fs.pathExists(deltaPath))) {
|
45 | artifacts.push(deltaPath);
|
46 | }
|
47 | const msiPath = path.resolve(outPath, winstallerConfig.setupMsi || `${appName}Setup.msi`);
|
48 | if (!winstallerConfig.noMsi && (await fs.pathExists(msiPath))) {
|
49 | artifacts.push(msiPath);
|
50 | }
|
51 | return artifacts;
|
52 | }
|
53 | }
|