-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(maker): add support for Windows Store (AppX) packages
This PR adds a new make type for Windows, "appx", which generates Windows Store packages ISSUES CLOSED: #27
- Loading branch information
1 parent
ac7a20b
commit 74a1216
Showing
9 changed files
with
102 additions
and
6 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
Binary file not shown.
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,88 @@ | ||
import windowsStore from 'electron-windows-store'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { spawnPromise, findActualExecutable } from 'spawn-rx'; | ||
|
||
import { ensureDirectory } from '../../util/ensure-output'; | ||
|
||
// NB: This is not a typo, we require AppXs to be built on 64-bit | ||
// but if we're running in a 32-bit node.js process, we're going to | ||
// be Wow64 redirected | ||
const windowsSdkPath = process.arch === 'x64' ? | ||
'C:\\Program Files (x86)\\Windows Kits\\10\\bin\\x64' : | ||
'C:\\Program Files\\Windows Kits\\10\\bin\\x64'; | ||
|
||
function findSdkTool(exe) { | ||
let sdkTool = path.join(windowsSdkPath, exe); | ||
if (!fs.existsSync(sdkTool)) { | ||
sdkTool = findActualExecutable(exe, []).cmd; | ||
} | ||
|
||
if (!fs.existsSync(sdkTool)) { | ||
throw new Error(`Can't find ${exe} in PATH, you probably need to install the Windows SDK`); | ||
} | ||
|
||
return sdkTool; | ||
} | ||
|
||
function spawnSdkTool(exe, params) { | ||
return spawnPromise(findSdkTool(exe), params); | ||
} | ||
|
||
export async function createDefaultCertificate(publisherName, outPath) { | ||
const defaultPvk = path.resolve(__dirname, '..', '..', '..', 'res', 'default.pvk'); | ||
const targetCert = path.join(outPath, 'default.cer'); | ||
const targetPfx = path.join(outPath, 'default.pfx'); | ||
|
||
await spawnSdkTool( | ||
'makecert.exe', | ||
['-r', '-h', '0', '-n', `CN=${publisherName}`, '-eku', '1.3.6.1.5.5.7.3.3', '-pe', '-sv', defaultPvk, targetCert]); | ||
|
||
await spawnSdkTool('pvk2pfx.exe', ['-pvk', defaultPvk, '-spc', targetCert, '-pfx', targetPfx]); | ||
|
||
return targetPfx; | ||
} | ||
|
||
export default async (dir, appName, targetArch, forgeConfig, packageJSON) => { // eslint-disable-line | ||
const outPath = path.resolve(dir, `../make/appx/${targetArch}`); | ||
await ensureDirectory(outPath); | ||
|
||
const opts = Object.assign({}, forgeConfig.windowsStoreConfig, { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
inputDirectory: dir, | ||
outputDirectory: outPath, | ||
publisher: packageJSON.author, | ||
flatten: false, | ||
deploy: false, | ||
packageVersion: `${packageJSON.version}.0`, | ||
packageName: appName.replace(/-/g, ''), | ||
packageDisplayName: appName, | ||
packageDescription: packageJSON.description || appName, | ||
packageExecutable: `app\\${appName}.exe`, | ||
windowsKit: path.dirname(findSdkTool('makeappx.exe')), | ||
}); | ||
|
||
if (!opts.devCert) { | ||
opts.devCert = await createDefaultCertificate(opts.publisher, outPath); | ||
} | ||
|
||
if (!opts.publisher.match(/^CN=/)) { | ||
This comment has been minimized.
Sorry, something went wrong.
jacobq
Contributor
|
||
opts.publisher = `CN=${opts.publisher}`; | ||
} | ||
|
||
if (opts.packageVersion.match(/-/)) { | ||
if (opts.makeVersionWinStoreCompatible) { | ||
const noBeta = opts.packageVersion.replace(/-.*/, ''); | ||
opts.packageVersion = `${noBeta}.0`; | ||
} else { | ||
const err = "Windows Store version numbers don't support semver beta tags. To" + | ||
'automatically fix this, set makeVersionWinStoreCompatible to true or ' + | ||
'explicitly set packageVersion to a version of the format X.Y.Z.A'; | ||
|
||
throw new Error(err); | ||
} | ||
} | ||
|
||
delete opts.makeVersionWinStoreCompatible; | ||
|
||
await windowsStore(opts); | ||
}; |
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
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
Why is the forgeConfig overridden by package.json? For example, I would like to be able to set
opts.publisher
separately from theauthor
field in my package.json configuration.