11import child_process from 'child_process' ;
22import * as fs from 'fs' ;
33import * as path from 'path' ;
4- import { fileURLToPath } from 'url' ;
54import packageJson from '../apps/studio/package.json' with { type : 'json' } ;
65
7- const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
86const fileArchitecture = process . env . FILE_ARCHITECTURE ;
97
108if ( ! fileArchitecture ) {
@@ -13,7 +11,7 @@ if ( ! fileArchitecture ) {
1311 ) ;
1412}
1513
16- const outDir = path . resolve ( __dirname , '../apps/studio/out' ) ;
14+ const outDir = path . resolve ( import . meta . dirname , '../apps/studio/out' ) ;
1715
1816const appPath = path . resolve (
1917 outDir ,
@@ -26,8 +24,14 @@ const dmgPath = path.resolve(
2624 `${ packageJson . productName } -darwin-${ fileArchitecture } .dmg`
2725) ;
2826
29- const volumeIconPath = path . resolve ( __dirname , '../apps/studio/assets/studio-app-icon.icns' ) ;
30- const backgroundPath = path . resolve ( __dirname , '../apps/studio/assets/dmg-background.png' ) ;
27+ const volumeIconPath = path . resolve (
28+ import . meta. dirname ,
29+ '../apps/studio/assets/studio-app-icon.icns'
30+ ) ;
31+ const backgroundPath = path . resolve (
32+ import . meta. dirname ,
33+ '../apps/studio/assets/dmg-background.png'
34+ ) ;
3135
3236const dmgSpecs = {
3337 title : packageJson . productName ,
@@ -50,9 +54,13 @@ if ( fs.existsSync( dmgPath ) ) {
5054}
5155fs . mkdirSync ( path . dirname ( dmgPath ) , { recursive : true } ) ;
5256
53- const specsFile = path . resolve ( __dirname , '..' , 'appdmg-specs.json' ) ;
57+ const specsFile = path . resolve ( import . meta . dirname , '..' , 'appdmg-specs.json' ) ;
5458fs . writeFileSync ( specsFile , JSON . stringify ( dmgSpecs ) ) ;
55- child_process . execSync (
56- [ path . join ( __dirname , '..' , 'node_modules' , '.bin' , `appdmg` ) , specsFile , dmgPath ] . join ( ' ' )
57- ) ;
58- fs . unlinkSync ( specsFile ) ;
59+ const appdmgBin = path . join ( import . meta. dirname , '..' , 'node_modules' , '.bin' , 'appdmg' ) ;
60+ try {
61+ child_process . execFileSync ( appdmgBin , [ specsFile , dmgPath ] ) ;
62+ } finally {
63+ if ( fs . existsSync ( specsFile ) ) {
64+ fs . unlinkSync ( specsFile ) ;
65+ }
66+ }
0 commit comments