-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(maker-pkg): add new maker for .pkg files on macOS
- Loading branch information
1 parent
dab06d9
commit 8728baa
Showing
6 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@electron-forge/maker-pkg", | ||
"version": "6.0.0-beta.3", | ||
"description": "PKG maker for Electron Forge", | ||
"repository": "https://github.com/electron-userland/electron-forge", | ||
"author": "Samuel Attard", | ||
"license": "MIT", | ||
"main": "dist/MakerPKG.js", | ||
"typings": "dist/MakerPKG.d.ts", | ||
"scripts": { | ||
"test": "mocha --require ts-node/register test/**/*_spec.ts test/**/**/*_spec.ts --opts ../../../mocha.opts" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.0.0", | ||
"chai-as-promised": "^7.0.0", | ||
"mocha": "^5.0.0", | ||
"proxyquire": "^2.0.1", | ||
"sinon": "^4.1.2" | ||
}, | ||
"engines": { | ||
"node": ">= 6.0" | ||
}, | ||
"dependencies": { | ||
"@electron-forge/maker-base": "6.0.0-beta.3", | ||
"@electron-forge/shared-types": "^6.0.0-beta.3", | ||
"electron-osx-sign": "^0.4.10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export interface MakerPKGConfig { | ||
/** | ||
* Name of certificate to use when signing. | ||
* | ||
* Default to be selected with respect to platform from keychain or keychain | ||
* by system default. | ||
*/ | ||
identity?: string; | ||
/** | ||
* Flag to enable/disable validation for signing identity. If enabled, the | ||
* identity provided will be validated in the keychain specified. | ||
* | ||
* Default: `true`. | ||
*/ | ||
'identity-validation'?: boolean; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
/** | ||
* Path to install the bundle. Default to `/Applications`. | ||
*/ | ||
install?: string; | ||
/** | ||
* The keychain name. | ||
* | ||
* Default: System default keychain. | ||
*/ | ||
keychain?: string; | ||
/** | ||
* Path to a directory containing pre and/or post install scripts | ||
*/ | ||
scripts?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import MakerBase, { MakerOptions } from '@electron-forge/maker-base'; | ||
import { ForgePlatform } from '@electron-forge/shared-types'; | ||
import { flatAsync } from 'electron-osx-sign'; | ||
|
||
import { MakerPKGConfig } from './Config'; | ||
|
||
import path from 'path'; | ||
|
||
export default class MakerDMG extends MakerBase<MakerPKGConfig> { | ||
name = 'pkg'; | ||
defaultPlatforms: ForgePlatform[] = ['darwin', 'mas']; | ||
|
||
isSupportedOnCurrentPlatform() { | ||
return process.platform === 'darwin'; | ||
} | ||
|
||
async make({ | ||
dir, | ||
makeDir, | ||
appName, | ||
packageJSON, | ||
targetPlatform, | ||
}: MakerOptions) { | ||
if (!['darwin', 'mas'].includes(targetPlatform)) { | ||
throw `The pkg maker only supports targetting "mas" and "darwin" builds. You provided "${targetPlatform}"`; | ||
} | ||
|
||
const outPath = path.resolve(makeDir, `${appName}-${packageJSON.version}.pkg`); | ||
|
||
await this.ensureFile(outPath); | ||
|
||
const pkgConfig = Object.assign({}, this.config, { | ||
app: path.resolve(dir, `${appName}.app`), | ||
pkg: outPath, | ||
platform: targetPlatform, | ||
}); | ||
await flatAsync(pkgConfig); | ||
|
||
return [outPath]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import MakerBase from '@electron-forge/maker-base'; | ||
|
||
import { expect } from 'chai'; | ||
import path from 'path'; | ||
import proxyquire from 'proxyquire'; | ||
import { stub, SinonStub } from 'sinon'; | ||
|
||
import { MakerPKGConfig } from '../src/Config'; | ||
|
||
class MakerImpl extends MakerBase<MakerPKGConfig> { name = 'test'; defaultPlatforms = [] } | ||
|
||
describe('MakerPKG', () => { | ||
let MakerDMG: typeof MakerImpl; | ||
let ensureFileStub: SinonStub; | ||
let eosStub: SinonStub; | ||
let renameStub: SinonStub; | ||
let config: MakerPKGConfig; | ||
let maker: MakerImpl; | ||
let createMaker: () => void; | ||
|
||
const dir = '/my/test/dir/out'; | ||
const makeDir = '/my/test/dir/make'; | ||
const appName = 'My Test App'; | ||
const targetArch = process.arch; | ||
const packageJSON = { version: '1.2.3' }; | ||
|
||
beforeEach(() => { | ||
ensureFileStub = stub().returns(Promise.resolve()); | ||
eosStub = stub(); | ||
renameStub = stub().returns(Promise.resolve()); | ||
config = {}; | ||
|
||
MakerDMG = proxyquire.noPreserveCache().noCallThru().load('../src/MakerPKG', { | ||
'../../util/ensure-output': { ensureFile: ensureFileStub }, | ||
'electron-osx-sign': { | ||
flatAsync: eosStub, | ||
}, | ||
'fs-extra': { | ||
rename: renameStub, | ||
}, | ||
}).default; | ||
createMaker = () => { | ||
maker = new MakerDMG(config); | ||
maker.ensureFile = ensureFileStub; | ||
}; | ||
createMaker(); | ||
}); | ||
|
||
it('should pass through correct defaults', async () => { | ||
await (maker.make as any)({ dir, makeDir, appName, targetArch, targetPlatform: 'mas', packageJSON }); | ||
const opts = eosStub.firstCall.args[0]; | ||
expect(opts).to.deep.equal({ | ||
app: path.resolve(`${dir}/My Test App.app`), | ||
pkg: path.resolve(`${dir.substr(0, dir.length - 4)}/make/My Test App-1.2.3.pkg`), | ||
platform: 'mas' | ||
}); | ||
}); | ||
|
||
it('should throw an error on invalid platform', async () => { | ||
await expect((maker.make as any)({ dir, makeDir, appName, targetArch, targetPlatform: 'win32', packageJSON })) | ||
.to.eventually.be.rejectedWith('The pkg maker only supports targetting "mas" and "darwin" builds. You provided "win32"'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 comment
on commit 8728baa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job
Estelle brunk