Skip to content

Commit

Permalink
feat: add electronZipDir option (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
malept authored Dec 27, 2019
1 parent 6d8c81d commit 9b8bd9c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
12 changes: 12 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ parameters include, but are not limited to:
- `rejectUnauthorized` (*Boolean* - default: `true`): Whether SSL certificates are required to be
valid when downloading Electron.

**Note:** `download` sub-options will have no effect if [`electronZipDir`](#electronzipdir) is set.

##### `electronVersion`

Expand All @@ -239,6 +240,17 @@ valid versions. If omitted, it will use the version of the nearest local install
`electron`, `electron-prebuilt-compile`, or `electron-prebuilt`, defined in `package.json` in either
`dependencies` or `devDependencies`.

##### `electronZipDir`

*String*

The local path to a directory containing Electron ZIP files for Electron Packager to unzip, instead
of downloading them. The ZIP filenames should be in the same format as the ones downloaded from the
Electron releases site.

**Note:** Setting this option prevents the [`download`](#download) sub-options from being used, as
the functionality gets skipped over.

##### `extraResource`

*String* or *Array* of *String*s
Expand Down
22 changes: 21 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,28 @@ class Packager {
}
}

async getElectronZipPath (downloadOpts) {
if (this.opts.electronZipDir) {
if (await fs.pathExists(this.opts.electronZipDir)) {
const zipPath = path.resolve(
this.opts.electronZipDir,
`electron-v${downloadOpts.version}-${downloadOpts.platform}-${downloadOpts.arch}.zip`
)
if (!await fs.pathExists(zipPath)) {
throw new Error(`The specified Electron ZIP file does not exist: ${zipPath}`)
}

return zipPath
}

throw new Error(`The specified Electron ZIP directory does not exist: ${this.opts.electronZipDir}`)
} else {
return download.downloadElectronZip(downloadOpts)
}
}

async packageForPlatformAndArch (downloadOpts) {
const zipPath = await download.downloadElectronZip(downloadOpts)
const zipPath = await this.getElectronZipPath(downloadOpts)
// Create delegated options object with specific platform and arch, for output directory naming
const comboOpts = {
...this.opts,
Expand Down
36 changes: 30 additions & 6 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ test('cannot build apps where the name ends in " Helper"', async t => {
platform: 'linux'
}

try {
await packager(opts)
} catch (err) {
return t.is(err.message, 'Application names cannot end in " Helper" due to limitations on macOS')
}
throw new Error('should not finish')
await t.throwsAsync(async () => packager(opts), 'Application names cannot end in " Helper" due to limitations on macOS')
})

test('deprecatedParameter moves value in deprecated param to new param if new param is not set', (t) => {
Expand Down Expand Up @@ -279,3 +274,32 @@ test.serial('dir: relative path', util.testSinglePlatform(async (t, opts) => {
const finalPath = (await packager(opts))[0]
t.is(path.join(t.context.workDir, 'ElectronTest-linux-x64'), finalPath, 'paths returned')
}))

test.serial('electronZipDir success', util.testSinglePlatform(async (t, opts) => {
const customDir = path.join(t.context.tempDir, 'download')
opts.dir = util.fixtureSubdir('basic')
opts.electronZipDir = customDir
await fs.ensureDir(customDir)
const zipPath = await download.downloadElectronZip(download.createDownloadOpts(opts, 'linux', 'x64'))
await fs.copy(zipPath, path.join(customDir, path.basename(zipPath)))

const paths = await packager(opts)
t.is(1, paths.length, '1 bundle created')
}))

test.serial('electronZipDir does not exist', util.testSinglePlatform(async (t, opts) => {
const customDir = path.join(t.context.tempDir, 'does-not-exist')
opts.dir = util.fixtureSubdir('basic')
opts.electronZipDir = customDir

await t.throwsAsync(async () => packager(opts), /Electron ZIP directory does not exist/)
}))

test.serial('electronZipDir: ZIP file does not exist', util.testSinglePlatform(async (t, opts) => {
const customDir = path.join(t.context.tempDir, 'download')
opts.dir = util.fixtureSubdir('basic')
opts.electronZipDir = customDir
await fs.ensureDir(customDir)

await t.throwsAsync(async () => packager(opts), /Electron ZIP file does not exist/)
}))
1 change: 1 addition & 0 deletions usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ download a list of sub-options to pass to @electron/get. They are spec
checks.
electron-version the version of Electron that is being packaged, see
https://github.com/electron/electron/releases
electron-zip-dir the local path to a directory containing Electron ZIP files
executable-name the name of the executable file, sans file extension. Defaults to appname
extra-resource a file to copy into the app's resources directory
icon the local path to an icon file to use as the icon for the app.
Expand Down

0 comments on commit 9b8bd9c

Please sign in to comment.