github-desktop/script/package

60 lines
1.7 KiB
JavaScript

#!/usr/bin/env node
'use strict'
const fs = require('fs-extra')
const cp = require('child_process')
const path = require('path')
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 () {
const dest = distInfo.getOSXZipPath()
fs.removeSync(dest)
cp.execSync(`ditto -ck --keepParent ${distPath}/${productName}.app ${dest}`)
console.log(`Zipped to ${dest}`)
}
function packageWindows () {
const electronInstaller = require('electron-winstaller')
const outputDir = path.join(distPath, '..', 'installer')
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')
electronInstaller
.createWindowsInstaller({
appDirectory: distPath,
outputDirectory: outputDir,
authors: distInfo.getCompanyName(),
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}`)
})
.catch(e => {
cp.execSync(`powershell ${cleanupCertificatePath}`)
console.error(`Error packaging: ${e}`)
process.exit(1)
})
}