#!/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 iconLocation = path.join(__dirname, '..', 'app', 'static', 'icon.ico') if (!fs.existsSync(iconLocation)) { console.error(`expected icon not found at location: ${iconLocation}`) process.exit(1) } const certificatePath = path.join(__dirname, 'windows-certificate.pfx') const options = { appDirectory: distPath, outputDirectory: outputDir, authors: distInfo.getCompanyName(), iconUrl: iconLocation, setupIcon: iconLocation, exe: `${productName}.exe` } if (process.env.APPVEYOR) { options.signWithParams = `/f ${certificatePath} /p ${process.env.WINDOWS_CERT_PASSWORD} /tr http://timestamp.digicert.com /td sha256` } electronInstaller .createWindowsInstaller(options) .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) }) }