@@ -2,25 +2,16 @@ import { exec } from 'node:child_process';
22import * as fs from 'node:fs' ;
33import * as path from 'node:path' ;
44import { MakerDMG } from '@electron-forge/maker-dmg' ;
5+ import { MakerSquirrel } from '@electron-forge/maker-squirrel' ;
56import { MakerZIP } from '@electron-forge/maker-zip' ;
67import { FusesPlugin } from '@electron-forge/plugin-fuses' ;
78import { VitePlugin } from '@electron-forge/plugin-vite' ;
8- import type { ForgeConfig } from '@electron-forge/shared-types' ;
9+ import { PublisherGithub } from '@electron-forge/publisher-github' ;
10+ import { type ForgeConfig } from '@electron-forge/shared-types' ;
911import { FuseV1Options , FuseVersion } from '@electron/fuses' ;
12+ import { type TargetPlatform } from '@electron/packager' ;
1013
11- // function getRunnerTarget (platform: string, arch: string) => {
12- // if (platform === 'darwin') {
13- // if (arch === 'arm64') {
14- // return 'aarch64-apple-darwin';
15- // } else if (arch === 'x64') {
16- // return 'x86_64-apple-darwin';
17- // } else {
18- // throw new Error(`Unsupported architecture: ${arch}`);
19- // }
20- // } else {
21- // throw new Error(`Unsupported platform: ${platform}`);
22- // }
23- // };
14+ const runnerPackageDirPath = path . join ( __dirname , '../runner' ) ;
2415
2516function execAsync (
2617 command : string ,
@@ -37,20 +28,39 @@ function execAsync(
3728 } ) ;
3829}
3930
40- // Get runner build path
41- const binRunnerBinaryPath = path . join ( __dirname , 'bin/toolbase-runner' ) ;
42- const runnerPackageDirPath = path . join ( __dirname , '../runner' ) ;
43- const runnerPackageBinaryPath = path . join (
44- runnerPackageDirPath ,
45- `out/toolbase-runner` ,
46- ) ;
31+ function getRunnerPaths ( platform : TargetPlatform ) {
32+ switch ( platform ) {
33+ case 'darwin' :
34+ case 'mas' :
35+ case 'linux' :
36+ return {
37+ binLocalRunnerRelativePath : './bin/toolbase-runner' ,
38+ binRunnerBinaryPath : path . join ( __dirname , 'bin/toolbase-runner' ) ,
39+ runnerPackageBinaryPath : path . join (
40+ runnerPackageDirPath ,
41+ `out/toolbase-runner` ,
42+ ) ,
43+ } ;
44+ case 'win32' :
45+ return {
46+ binLocalRunnerRelativePath : './bin/toolbase-runner.exe' ,
47+ binRunnerBinaryPath : path . join ( __dirname , 'bin/toolbase-runner.exe' ) ,
48+ runnerPackageBinaryPath : path . join (
49+ runnerPackageDirPath ,
50+ `out/toolbase-runner.exe` ,
51+ ) ,
52+ } ;
53+ }
54+
55+ throw new Error ( `Unsupported platform: ${ platform } ` ) ;
56+ }
4757
4858const config : ForgeConfig = {
4959 packagerConfig : {
5060 asar : true ,
5161 icon : './icons/icon' ,
5262 // Include the runner binary
53- extraResource : [ './bin/toolbase-runner' ] ,
63+ // extraResource: ['./bin/toolbase-runner', './bin/toolbase-runner.exe '],
5464 osxSign : {
5565 identity : process . env . APPLE_IDENTITY ,
5666 } ,
@@ -61,7 +71,7 @@ const config: ForgeConfig = {
6171 } ,
6272 } ,
6373 hooks : {
64- async generateAssets ( ) {
74+ async generateAssets ( config , platform , arch ) {
6575 // @important - This does some smart logic of only rebuilding the runner if necessary, but feels like it could cause lots of headaches.
6676 // toolbase-runner exists in bin/
6777 // if (fs.existsSync(binRunnerBinaryPath)) {
@@ -88,27 +98,52 @@ const config: ForgeConfig = {
8898 // return;
8999 // }
90100
101+ const {
102+ binLocalRunnerRelativePath,
103+ binRunnerBinaryPath,
104+ runnerPackageBinaryPath,
105+ } = getRunnerPaths ( platform ) ;
106+
91107 // Create it if it doesn't exist
92108 fs . mkdirSync ( path . dirname ( binRunnerBinaryPath ) , { recursive : true } ) ;
93109
94110 // Build on demand for the target platform and architecture and copy
95- await execAsync ( 'deno task build' , runnerPackageDirPath ) ;
111+ const { stdout, stderr } = await execAsync (
112+ `deno task build -p ${ platform } -a ${ arch } ` ,
113+ runnerPackageDirPath ,
114+ ) ;
115+
116+ console . log ( stdout , stderr ) ;
117+
96118 fs . copyFileSync ( runnerPackageBinaryPath , binRunnerBinaryPath ) ;
97119
98120 console . log (
99- `Built and copied "toolbase-runner" from "${ runnerPackageBinaryPath } " to "${ binRunnerBinaryPath } "` ,
121+ `Built and copied "toolbase-runner" from "${ runnerPackageBinaryPath } " to "${ binRunnerBinaryPath } for ${ platform } - ${ arch } "` ,
100122 ) ;
123+
124+ // Add to our config
125+ config . packagerConfig . extraResource = [ binLocalRunnerRelativePath ] ;
101126 } ,
102127 } ,
103128 rebuildConfig : { } ,
104129 makers : [
130+ new MakerSquirrel ( { } ) ,
105131 new MakerZIP ( { } , [ 'darwin' ] ) ,
106132 //@ts -expect-error MakerDMS has incorrect types.
107133 new MakerDMG ( {
108134 overwrite : true ,
109135 icon : './icons/icon.icns' ,
110136 } ) ,
111137 ] ,
138+ publishers : [
139+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
140+ new PublisherGithub ( {
141+ repository : { owner : 'toolbase-ai' , name : 'toolbase' } ,
142+ prerelease : false ,
143+ draft : true ,
144+ generateReleaseNotes : true ,
145+ } ) ,
146+ ] ,
112147 plugins : [
113148 new VitePlugin ( {
114149 // `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc.
0 commit comments