|
16 | 16 | const darwinInfoPlistBase = require('./build/darwin-info-base.json') |
17 | 17 | const exec = require('child_process').exec |
18 | 18 | const fs = require('fs-extra') |
19 | | - const gulp = require('gulp') |
20 | 19 | const packageJsonFirstLoad = require('./package.json') |
21 | 20 | const path = require('path') |
22 | 21 | const plist = require('plist') |
|
127 | 126 | // |
128 | 127 |
|
129 | 128 | /** Copies static resource files into the result directory */ |
130 | | - gulp.task( 'copyResourceFiles', callback => { |
| 129 | + async function copyResourceFiles ( ) { |
| 130 | + console.log("--> Coping resource files") |
131 | 131 | function copyNodeModules ( handle ) { |
132 | 132 | const address = path.join( 'node_modules', handle ) |
133 | 133 | copyToBinaryFromDir( address, address ) |
|
140 | 140 | copyToBinaryFromDir( 'windows' ) |
141 | 141 | copyToBinaryFromDir( 'winserver' ) |
142 | 142 |
|
143 | | - |
144 | | - |
145 | 143 | // design files |
146 | 144 | copyToBinaryFromDir( 'resources' ) |
147 | 145 | copyToBinaryFromDir( 'designs/icon/file-icon-darwin/icns' ) |
|
150 | 148 | OrchestraNodeModules.forEach( x => copyNodeModules( x ) ) |
151 | 149 |
|
152 | 150 | // package |
153 | | - copyFile( |
| 151 | + await copyFile( |
154 | 152 | getLocalPath( 'package.json' ), |
155 | 153 | getLocalPath( path.join( pathToResultDir , 'package.json' ) ) |
156 | 154 | ) |
157 | | - |
158 | | - callback() |
159 | | - }) |
| 155 | + } |
160 | 156 |
|
161 | 157 | // |
162 | 158 | // ─── GETTING COMMIT COUNT ─────────────────────────────────────────────────────── |
163 | 159 | // |
164 | 160 |
|
165 | | - gulp.task( 'get-commit-counts', callback => { |
166 | | - const commitCountFilePath = |
167 | | - `./${pathToResultDir}/about/commit-count.txt` |
168 | | - const githubOrchestraRepositoryAPI = |
169 | | - 'https://api.github.com/repos/pmkary/orchestra/stats/contributors' |
170 | | - |
171 | | - try { |
172 | | - new Promise (( resolve, reject ) => { |
173 | | - const rejectHandler = ( ) => |
174 | | - reject('Could not connect to GitHub') |
175 | | - |
176 | | - const options = { |
177 | | - url: githubOrchestraRepositoryAPI, |
178 | | - method: 'GET', |
179 | | - headers: { |
180 | | - 'User-Agent': 'Super Agent/0.0.1', |
181 | | - 'Content-Type': 'application/x-www-form-urlencoded' |
182 | | - }, |
183 | | - } |
| 161 | + async function getCommitCounts ( ) { |
| 162 | + return new Promise ( callback => { |
| 163 | + const commitCountFilePath = |
| 164 | + `./${pathToResultDir}/about/commit-count.txt` |
| 165 | + const githubOrchestraRepositoryAPI = |
| 166 | + 'https://api.github.com/repos/pmkary/orchestra/stats/contributors' |
184 | 167 |
|
185 | | - request( options, ( error, response, body ) => { |
186 | | - if ( !error && response.statusCode == 200 ) |
187 | | - try { |
188 | | - const data = JSON.parse( body )[ 0 ].total.toString( ) |
189 | | - resolve( data ) |
190 | | - } catch ( parseError ) { |
| 168 | + try { |
| 169 | + new Promise (( resolve, reject ) => { |
| 170 | + const rejectHandler = ( ) => |
| 171 | + reject('Could not connect to GitHub') |
| 172 | + |
| 173 | + const options = { |
| 174 | + url: githubOrchestraRepositoryAPI, |
| 175 | + method: 'GET', |
| 176 | + headers: { |
| 177 | + 'User-Agent': 'Super Agent/0.0.1', |
| 178 | + 'Content-Type': 'application/x-www-form-urlencoded' |
| 179 | + }, |
| 180 | + } |
| 181 | + |
| 182 | + request( options, ( error, response, body ) => { |
| 183 | + if ( !error && response.statusCode == 200 ) |
| 184 | + try { |
| 185 | + const data = JSON.parse( body )[ 0 ].total.toString( ) |
| 186 | + resolve( data ) |
| 187 | + } catch ( parseError ) { |
| 188 | + rejectHandler( ) |
| 189 | + } |
| 190 | + else |
191 | 191 | rejectHandler( ) |
192 | | - } |
193 | | - else |
194 | | - rejectHandler( ) |
| 192 | + }) |
| 193 | + }) |
| 194 | + .then( GitHubCommitCount => { |
| 195 | + fs.writeFileSync( commitCountFilePath, GitHubCommitCount ) |
| 196 | + callback( ) |
| 197 | + }) |
| 198 | + .catch( e => { |
| 199 | + callback( e ) |
195 | 200 | }) |
196 | | - }) |
197 | | - .then( GitHubCommitCount => { |
198 | | - fs.writeFileSync( commitCountFilePath, GitHubCommitCount ) |
199 | | - callback( ) |
200 | | - }) |
201 | | - .catch( e => { |
202 | | - callback( e ) |
203 | | - }) |
204 | 201 |
|
205 | | - } catch ( error ) { |
206 | | - try { |
207 | | - shell( 'git', 'rev-list', '--all', '--count', |
208 | | - '>', commitCountFilePath ) |
209 | | - callback( ) |
| 202 | + } catch ( error ) { |
| 203 | + try { |
| 204 | + shell( 'git', 'rev-list', '--all', '--count', |
| 205 | + '>', commitCountFilePath ) |
| 206 | + callback( ) |
210 | 207 |
|
211 | | - } catch ( error2 ) { |
212 | | - callback('Could not save latest commits count') |
| 208 | + } catch ( error2 ) { |
| 209 | + callback('Could not save latest commits count') |
| 210 | + } |
213 | 211 | } |
214 | | - } |
215 | | - }) |
| 212 | + }) |
| 213 | + } |
216 | 214 |
|
217 | 215 | // |
218 | 216 | // ─── SHEETS ───────────────────────────────────────────────────────────────────── |
219 | 217 | // |
220 | 218 |
|
221 | 219 | /** Compiles the Less style sheets */ |
222 | | - gulp.task( 'sheets', async callback => { |
| 220 | + async function sheets ( ) { |
| 221 | + console.log("--> Making sheets") |
223 | 222 | const thisDir = (...x) => path.join( __dirname, ...x ) |
224 | 223 |
|
225 | | - shell('lessc', |
| 224 | + await shell('lessc', |
226 | 225 | thisDir( 'sheets', 'ui.less' ), |
227 | 226 | thisDir( '_compiled', 'style.css' ) |
228 | | - ).then(( ) => { |
229 | | - callback( ) |
230 | | - }).catch(( err ) => { |
231 | | - callback( err ) |
232 | | - }) |
233 | | - }) |
| 227 | + ) |
| 228 | + } |
234 | 229 |
|
235 | 230 | // |
236 | 231 | // ─── ELECTRON PACKER ──────────────────────────────────────────────────────────── |
237 | 232 | // |
238 | 233 |
|
239 | 234 | async function packOrchestraForDarwin ( ) { |
| 235 | + console.log( "--> Packing for Darwin" ) |
240 | 236 | const iconFile = |
241 | 237 | ( isProductionBuild ? './designs/icon/icns/icon.icns' |
242 | 238 | : './designs/icon-nightly/icns/icon.icns' |
|
248 | 244 | ' _compiled', |
249 | 245 | '"' + packageJson.productName + '"', |
250 | 246 | '--platform=darwin', |
251 | | - '--arch=x64', |
| 247 | + '--arch=arm64', |
252 | 248 | '--overwrite=true', |
253 | 249 | '--app-bundle-id="us.kary.orchestra"', |
254 | 250 | '--app-copyright="' + CopyrightNotice + '"', |
|
267 | 263 |
|
268 | 264 |
|
269 | 265 | function updateDarwinInfoPlistFile ( ) { |
| 266 | + console.log( "--> Updating Darwin Info Plist" ) |
270 | 267 | // data |
271 | 268 | const plistFilePath = |
272 | 269 | ( isProductionBuild ? '_release/Orchestra-darwin-x64/Orchestra.app/Contents/Info.plist' |
|
293 | 290 |
|
294 | 291 |
|
295 | 292 | async function createMacDMGImage ( ) { |
| 293 | + console.log( "--> Creating Mac DMG Image" ) |
296 | 294 | const orchestraMacAppAddress = |
297 | 295 | "_release/Orchestra-darwin-x64/Orchestra.app" |
298 | 296 |
|
|
315 | 313 | // |
316 | 314 |
|
317 | 315 | async function packOrchestraForLinux ( ) { |
| 316 | + console.log( "--> Packing for Linux" ) |
318 | 317 | const iconFile = |
319 | 318 | ( isProductionBuild ? './designs/icon/icon.png' |
320 | 319 | : './designs/icon-nightly/icns/icon.icns' |
|
344 | 343 |
|
345 | 344 |
|
346 | 345 | async function createDebianDEBInstaller ( ) { |
| 346 | + console.log( "--> Create DEB File..." ) |
347 | 347 | await shell( |
348 | 348 | 'electron-installer-debian', |
349 | 349 | '--src _release/Orchestra-linux-x64', |
|
360 | 360 | // to be continued... |
361 | 361 | } |
362 | 362 |
|
| 363 | +// |
| 364 | +// ─── COMPILE ──────────────────────────────────────────────────────────────────── |
| 365 | +// |
| 366 | + |
| 367 | + async function compile ( ) { |
| 368 | + console.log( "--> Compiling" ) |
| 369 | + await copyResourceFiles( ) |
| 370 | + await sheets( ) |
| 371 | + } |
| 372 | + |
363 | 373 | // |
364 | 374 | // ─── PACK ─────────────────────────────────────────────────────────────────────── |
365 | 375 | // |
366 | 376 |
|
367 | | - gulp.task( 'pack-orchestra', gulp.series('copyResourceFiles', 'sheets', async callback => { |
| 377 | + async function packOrchestra ( ) { |
| 378 | + console.log ( "--> Packing Orchestra" ) |
| 379 | + await compile( ) |
| 380 | + |
368 | 381 | async function packFunctionBody ( ) { |
369 | | - if ( argv.debug ) |
370 | | - return await shell( 'npm', 'run', 'electron' ) |
| 382 | + if ( argv.debug ) { |
| 383 | + console.log( "--> Running electron") |
| 384 | + await shell( 'npm', 'run', 'electron' ) |
| 385 | + return |
| 386 | + } |
371 | 387 |
|
372 | 388 | if ( argv.pack ) |
373 | 389 | await buildAllPlatforms( ) |
|
376 | 392 | await createInstallersForAllPlatforms( ) |
377 | 393 | } |
378 | 394 |
|
379 | | - packFunctionBody( ) |
380 | | - .then( callback ) |
381 | | - .catch( callback ) |
382 | | - })) |
| 395 | + await packFunctionBody( ) |
| 396 | + } |
383 | 397 |
|
384 | 398 | // |
385 | 399 | // ─── BUILD FOR ALL PLATFORMS ──────────────────────────────────────────────────── |
386 | 400 | // |
387 | 401 |
|
388 | 402 | async function buildAllPlatforms ( ) { |
| 403 | + console.log( "--> Building all platforms" ) |
389 | 404 | const platformFunctions = [ ] |
390 | 405 |
|
391 | 406 | if ( argv.mac ) |
392 | | - platformFunctions.push( packOrchestraForDarwin ) |
| 407 | + await packOrchestraForDarwin( ) |
393 | 408 |
|
394 | 409 | if ( argv.win ) |
395 | | - platformFunctions.push( packOrchestraForWindows ) |
| 410 | + await packOrchestraForWindows( ) |
396 | 411 |
|
397 | 412 | if ( argv.linux ) |
398 | | - platformFunctions.push( packOrchestraForLinux ) |
399 | | - |
400 | | - await runAsyncFunctions( platformFunctions ) |
| 413 | + await packOrchestraForLinux( ) |
401 | 414 | } |
402 | 415 |
|
403 | 416 | // |
404 | 417 | // ─── CREATE INSTALLERS FOR ALL PLATFORMS ──────────────────────────────────────── |
405 | 418 | // |
406 | 419 |
|
407 | 420 | async function createInstallersForAllPlatforms ( ) { |
408 | | - const platformFunctions = [ ] |
| 421 | + console.log( "--> Making Installer" ) |
409 | 422 |
|
410 | 423 | if ( argv.mac ) |
411 | | - platformFunctions.push( createMacDMGImage ) |
| 424 | + await createMacDMGImage( ) |
412 | 425 |
|
413 | 426 | if ( argv.linux ) |
414 | | - platformFunctions.push( createDebianDEBInstaller ) |
415 | | - |
416 | | - await runAsyncFunctions(platformFunctions) |
| 427 | + await createDebianDEBInstaller( ) |
417 | 428 | } |
418 | 429 |
|
419 | 430 | // |
420 | 431 | // ─── RUN MANY ASYNC FUNCTIONS ─────────────────────────────────────────────────── |
421 | 432 | // |
422 | 433 |
|
423 | | - async function runAsyncFunctions ( functions ) { |
424 | | - await Promise.all( functions.map( func => func( ) ) ) |
| 434 | + main ( ); async function main ( ) { |
| 435 | + try { |
| 436 | + await packOrchestra( ) |
| 437 | + } catch ( error ) { |
| 438 | + console.error( error ) |
| 439 | + } |
425 | 440 | } |
426 | 441 |
|
427 | | -// |
428 | | -// ─── AFTER PACK ───────────────────────────────────────────────────────────────── |
429 | | -// |
430 | | - |
431 | | - gulp.task( 'build-orchestra', gulp.series('pack-orchestra', ( callback ) => { |
432 | | - callback( ) |
433 | | - })) |
434 | | - |
435 | | -// |
436 | | -// ─── MAIN ─────────────────────────────────────────────────────────────────────── |
437 | | -// |
438 | | - |
439 | | - /** Where everything starts */ |
440 | | - gulp.task( 'default', gulp.series('build-orchestra', ( ) => { })) |
441 | | - |
442 | 442 | // ──────────────────────────────────────────────────────────────────────────────── |
0 commit comments