-
-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This PR adds a new make type for Windows, "appx", which generates Windows Store packages ISSUES CLOSED: #27
- Loading branch information
There are no files selected for viewing
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); | ||
}; |
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.