2016-05-25 14:37:27 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const fs = require('fs-extra')
|
|
|
|
const cp = require('child_process')
|
2016-05-25 14:47:51 +00:00
|
|
|
const path = require('path')
|
2016-05-25 14:37:27 +00:00
|
|
|
const distInfo = require('./dist-info')
|
|
|
|
|
|
|
|
const distPath = distInfo.getDistPath()
|
|
|
|
const productName = distInfo.getProductName()
|
|
|
|
|
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
packageOSX()
|
|
|
|
} else if (process.platform === 'win32') {
|
|
|
|
packageWindows()
|
|
|
|
} else {
|
|
|
|
console.error(`I dunno how to package for ${process.platform} :(`)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
function packageOSX () {
|
2016-05-25 20:49:06 +00:00
|
|
|
const dest = distInfo.getOSXZipPath()
|
2016-05-25 14:37:27 +00:00
|
|
|
fs.removeSync(dest)
|
|
|
|
|
|
|
|
cp.execSync(`ditto -ck --keepParent ${distPath}/${productName}.app ${dest}`)
|
|
|
|
console.log(`Zipped to ${dest}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
function packageWindows () {
|
2016-05-25 14:47:51 +00:00
|
|
|
const electronInstaller = require('electron-winstaller')
|
2016-05-25 15:10:30 +00:00
|
|
|
const outputDir = path.join(distPath, '..', 'installer')
|
2016-07-04 05:25:36 +00:00
|
|
|
const setupCertificatePath = path.join(__dirname, 'setup-windows-certificate.ps1')
|
|
|
|
const cleanupCertificatePath = path.join(__dirname, 'cleanup-windows-certificate.ps1')
|
|
|
|
|
|
|
|
if (process.env.APPVEYOR) {
|
|
|
|
cp.execSync(`powershell ${setupCertificatePath}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
const certificatePath = path.join(__dirname, 'windows-certificate.pfx')
|
|
|
|
|
2016-05-25 14:47:51 +00:00
|
|
|
electronInstaller
|
|
|
|
.createWindowsInstaller({
|
|
|
|
appDirectory: distPath,
|
2016-05-25 15:10:30 +00:00
|
|
|
outputDirectory: outputDir,
|
2016-05-25 14:47:51 +00:00
|
|
|
authors: distInfo.getCompanyName(),
|
2016-07-04 05:25:36 +00:00
|
|
|
exe: `${productName}.exe`,
|
|
|
|
signWithParams: `/f ${certificatePath} /p ${process.env.WINDOWS_CERT_PASSWORD} /tr http://timestamp.digicert.com /td sha256`
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
console.log(`Installers created in ${outputDir}`)
|
|
|
|
cp.execSync(`powershell ${cleanupCertificatePath}`)
|
2016-05-25 14:47:51 +00:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2016-07-04 05:25:36 +00:00
|
|
|
cp.execSync(`powershell ${cleanupCertificatePath}`)
|
2016-05-25 14:47:51 +00:00
|
|
|
console.error(`Error packaging: ${e}`)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
2016-05-25 14:37:27 +00:00
|
|
|
}
|