@@ -45,6 +45,7 @@ const { arch: osArch } = require('os')
45
45
const { createGunzip } = require ( 'zlib' )
46
46
const { basename, join } = require ( 'path' )
47
47
const packager = require ( 'electron-packager' )
48
+ const { serialHooks } = require ( 'electron-packager/src/hooks' )
48
49
const { copy, emptyDir, remove } = require ( 'fs-extra' )
49
50
const { createReadStream, createWriteStream, readdir } = require ( 'fs' )
50
51
const { exec } = require ( 'child_process' )
@@ -60,7 +61,7 @@ const nodePty = 'node-pty-prebuilt-multiarch'
60
61
* @param this baseArgs from package() below
61
62
*
62
63
*/
63
- async function buildWebpack ( buildPath , electronVersion , targetPlatform , targetArch , callback ) {
64
+ async function buildWebpack ( buildPath , electronVersion , targetPlatform , targetArch ) {
64
65
const CLIENT_HOME = this . dir
65
66
66
67
console . log ( 'buildPath' , buildPath )
@@ -106,24 +107,19 @@ async function buildWebpack(buildPath, electronVersion, targetPlatform, targetAr
106
107
)
107
108
108
109
await Promise . all ( asyncs )
109
- callback ( )
110
110
}
111
111
112
112
/** afterCopy hook to copy in the platform-specific node-pty build */
113
- async function copyNodePty ( buildPath , electronVersion , targetPlatform , targetArch , callback ) {
114
- console . log ( 'copying node pty' )
115
- /* if (process.platform === targetPlatform && targetArch === osArch()) {
116
- // if the current platform matches the target platform, there is
117
- // nothing to do
118
- callback()
119
- } else */ {
113
+ function copyNodePty ( buildPath , electronVersion , targetPlatform , targetArch ) {
114
+ return new Promise ( ( resolve , reject ) => {
115
+ console . log ( 'copying node pty' )
120
116
const target = `${ targetPlatform } -${ targetArch } `
121
117
const sourceDir = join ( process . env . BUILDER_HOME , 'dist/electron/vendor' , nodePty , 'build' , target , 'electron' )
122
118
console . log ( 'sourceDir' , sourceDir )
123
119
124
120
readdir ( sourceDir , async ( err , files ) => {
125
121
if ( err ) {
126
- callback ( err )
122
+ reject ( err )
127
123
} else {
128
124
try {
129
125
await Promise . all (
@@ -149,32 +145,26 @@ async function copyNodePty(buildPath, electronVersion, targetPlatform, targetArc
149
145
} )
150
146
)
151
147
)
152
- callback ( )
148
+ resolve ( )
153
149
} catch ( err ) {
154
- callback ( err )
150
+ reject ( err )
155
151
}
156
152
}
157
153
} )
158
- }
154
+ } )
159
155
}
160
156
161
157
/** afterCopy hook to copy in headless build, etc. things that need to be codesigned */
162
- async function copySignableBits ( buildPath , electronVersion , targetPlatform , targetArch , callback ) {
158
+ async function copySignableBits ( buildPath , electronVersion , targetPlatform , targetArch ) {
163
159
// copy in launcher? it is important to copy this in before
164
160
// signing and notarizing, otherwise macOS/windows, when launching
165
161
// the app, will see unsigned content in the application bundle
166
- try {
167
- if ( this . launcher ) {
168
- const source = this . launcher
169
- const target = join ( buildPath , '..' , basename ( source ) ) // e.g. buildPath is Contents/Resources/app on macOS
170
- console . log ( `Copying in launcher for ${ targetPlatform } ${ targetArch } from ${ source } to ${ target } ` )
171
- await copy ( source , target )
172
- await remove ( source )
173
- }
174
- } catch ( err ) {
175
- console . error ( `Error copying in launcher for ${ targetPlatform } ${ targetArch } ` )
176
- console . error ( err )
177
- callback ( err )
162
+ if ( this . launcher ) {
163
+ const source = this . launcher
164
+ const target = join ( buildPath , '..' , basename ( source ) ) // e.g. buildPath is Contents/Resources/app on macOS
165
+ console . log ( `Copying in launcher for ${ targetPlatform } ${ targetArch } from ${ source } to ${ target } ` )
166
+ await copy ( source , target )
167
+ // NO!!! TODO find a better way to remove kubect-kui await remove(source)
178
168
}
179
169
180
170
// copy in the headless build?
@@ -185,8 +175,6 @@ async function copySignableBits(buildPath, electronVersion, targetPlatform, targ
185
175
await emptyDir ( target )
186
176
await copy ( source , target )
187
177
}
188
-
189
- callback ( )
190
178
}
191
179
/**
192
180
* Use electron-packager to create the application package
@@ -225,7 +213,7 @@ function package(baseArgs /*: { dir: string, name: string, platform: string, arc
225
213
} ,
226
214
227
215
// lifecycle hooks to copy in our extra bits
228
- afterCopy : [ buildWebpack . bind ( baseArgs ) , copyNodePty , copySignableBits . bind ( baseArgs ) ]
216
+ afterCopy : [ serialHooks ( [ buildWebpack . bind ( baseArgs ) , copyNodePty , copySignableBits . bind ( baseArgs ) ] ) ]
229
217
} )
230
218
231
219
console . log ( 'args' , args )
0 commit comments