Skip to content

Commit 05c5dee

Browse files
authored
Merge pull request #403 from electron-userland/after-extract-hook
Add afterExtract hook Closes #354.
2 parents 3ffaaec + 20b87a4 commit 05c5dee

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

docs/api.md

+12
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ The non-`all` values correspond to the platform names used by [Electron releases
4545

4646
#### All Platforms
4747

48+
##### `afterExtract`
49+
50+
*Array of Functions*
51+
52+
An array of functions to be called after Electron has been extracted to a temporary directory. Each function is called with five parameters:
53+
54+
- `buildPath` (*String*): The path to the temporary folder where Electron has been extracted to
55+
- `electronVersion` (*String*): The version of electron you are packaging for
56+
- `platform` (*String*): The target platform you are packaging for
57+
- `arch` (*String*): The target architecture you are packaging for
58+
- `callback` (*Function*): Must be called once you have completed your actions
59+
4860
##### `all`
4961

5062
*Boolean*

index.js

+10
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ function createSeries (opts, archs, platforms) {
128128
},
129129
function (cb) {
130130
extract(zipPath, {dir: buildDir}, cb)
131+
},
132+
function (cb) {
133+
if (!opts.afterExtract || !Array.isArray(opts.afterExtract)) {
134+
cb()
135+
} else {
136+
var newFunctions = opts.afterExtract.map(function (fn) {
137+
return fn.bind(this, buildDir, version, platform, arch)
138+
})
139+
series(newFunctions, cb)
140+
}
131141
}
132142
], function () {
133143
require(supportedPlatforms[platform]).createApp(comboOpts, buildDir, callback)

test/hooks.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict'
2+
3+
const config = require('./config.json')
4+
const fs = require('fs')
5+
const packager = require('..')
6+
const path = require('path')
7+
const series = require('run-series')
8+
const test = require('tape')
9+
const util = require('./util')
10+
const waterfall = require('run-waterfall')
11+
12+
function verifyPackageExistence (finalPaths, callback) {
13+
series(finalPaths.map(function (finalPath) {
14+
return function (cb) {
15+
fs.stat(finalPath, cb)
16+
}
17+
}), function (err, statsResults) {
18+
if (err) return callback(null, false)
19+
20+
callback(null, statsResults.every(function (stats) {
21+
return stats.isDirectory()
22+
}))
23+
})
24+
}
25+
26+
util.setup()
27+
test('platform=all test (one arch) (afterExtract hook)', function (t) {
28+
t.timeoutAfter(config.timeout * 2) // 2 packages will be built during this test
29+
30+
var afterExtractCalled = false
31+
var opts = {
32+
name: 'basicTest',
33+
dir: path.join(__dirname, 'fixtures', 'basic'),
34+
version: config.version,
35+
arch: 'ia32',
36+
platform: 'all',
37+
afterExtract: [function testAfterExtract (buildPath, electronVersion, platform, arch, callback) {
38+
afterExtractCalled = true
39+
t.equal(electronVersion, opts.version, 'afterExtract electronVersion should be the same as the options object')
40+
t.equal(arch, opts.arch, 'afterExtract arch should be the same as the options object')
41+
callback()
42+
}]
43+
}
44+
45+
waterfall([
46+
function (cb) {
47+
packager(opts, cb)
48+
}, function (finalPaths, cb) {
49+
t.equal(finalPaths.length, 2, 'packager call should resolve with expected number of paths')
50+
t.true(afterExtractCalled, 'afterExtract methods should have been called')
51+
verifyPackageExistence(finalPaths, cb)
52+
}, function (exists, cb) {
53+
t.true(exists, 'Packages should be generated for both 32-bit platforms')
54+
cb()
55+
}
56+
], function (err) {
57+
t.end(err)
58+
})
59+
})
60+
util.teardown()

test/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ series([
2525
], function () {
2626
console.log('Running tests...')
2727
require('./basic')
28+
require('./hooks')
2829
require('./multitarget')
2930
require('./win32')
3031

0 commit comments

Comments
 (0)