2017-10-19 23:04:47 +00:00
|
|
|
/* eslint-disable no-sync */
|
2016-05-25 14:37:27 +00:00
|
|
|
|
2017-10-15 06:05:28 +00:00
|
|
|
import * as fs from 'fs-extra'
|
|
|
|
import * as cp from 'child_process'
|
|
|
|
import * as path from 'path'
|
2017-10-16 22:35:39 +00:00
|
|
|
import * as electronInstaller from 'electron-winstaller'
|
2017-10-15 06:05:28 +00:00
|
|
|
import {
|
|
|
|
getDistRoot,
|
|
|
|
getDistPath,
|
|
|
|
getProductName,
|
|
|
|
getOSXZipPath,
|
|
|
|
getWindowsIdentifierName,
|
|
|
|
getCompanyName,
|
|
|
|
getWindowsStandaloneName,
|
|
|
|
getWindowsInstallerName,
|
|
|
|
shouldMakeDelta,
|
|
|
|
getUpdatesURL,
|
|
|
|
} from './dist-info'
|
|
|
|
|
|
|
|
const distPath = getDistPath()
|
|
|
|
const productName = getProductName()
|
2017-07-28 11:21:48 +00:00
|
|
|
const outputDir = path.join(distPath, '..', 'installer')
|
2016-05-25 14:37:27 +00:00
|
|
|
|
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
packageOSX()
|
|
|
|
} else if (process.platform === 'win32') {
|
|
|
|
packageWindows()
|
2017-07-28 11:21:48 +00:00
|
|
|
} else if (process.platform === 'linux') {
|
|
|
|
packageLinux()
|
2016-05-25 14:37:27 +00:00
|
|
|
} else {
|
|
|
|
console.error(`I dunno how to package for ${process.platform} :(`)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
2017-07-13 13:36:37 +00:00
|
|
|
function packageOSX() {
|
2017-10-15 06:05:28 +00:00
|
|
|
const dest = getOSXZipPath()
|
2016-05-25 14:37:27 +00:00
|
|
|
fs.removeSync(dest)
|
|
|
|
|
2017-07-13 13:36:37 +00:00
|
|
|
cp.execSync(
|
|
|
|
`ditto -ck --keepParent "${distPath}/${productName}.app" "${dest}"`
|
|
|
|
)
|
2016-05-25 14:37:27 +00:00
|
|
|
console.log(`Zipped to ${dest}`)
|
|
|
|
}
|
|
|
|
|
2017-07-13 13:36:37 +00:00
|
|
|
function packageWindows() {
|
|
|
|
const setupCertificatePath = path.join(
|
|
|
|
__dirname,
|
|
|
|
'setup-windows-certificate.ps1'
|
|
|
|
)
|
|
|
|
const cleanupCertificatePath = path.join(
|
|
|
|
__dirname,
|
|
|
|
'cleanup-windows-certificate.ps1'
|
|
|
|
)
|
2016-07-04 05:25:36 +00:00
|
|
|
|
|
|
|
if (process.env.APPVEYOR) {
|
|
|
|
cp.execSync(`powershell ${setupCertificatePath}`)
|
|
|
|
}
|
|
|
|
|
2017-07-13 13:36:37 +00:00
|
|
|
const iconSource = path.join(
|
|
|
|
__dirname,
|
|
|
|
'..',
|
|
|
|
'app',
|
|
|
|
'static',
|
|
|
|
'logos',
|
|
|
|
'icon-logo.ico'
|
|
|
|
)
|
2016-09-08 03:42:41 +00:00
|
|
|
|
2017-03-27 04:54:19 +00:00
|
|
|
if (!fs.existsSync(iconSource)) {
|
2017-03-29 03:49:55 +00:00
|
|
|
console.error(`expected setup icon not found at location: ${iconSource}`)
|
2016-09-08 03:42:41 +00:00
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
2017-07-13 13:36:37 +00:00
|
|
|
const splashScreenPath = path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../app/static/logos/win32-installer-splash.gif'
|
|
|
|
)
|
2017-05-11 19:11:01 +00:00
|
|
|
|
|
|
|
if (!fs.existsSync(splashScreenPath)) {
|
2017-07-13 13:36:37 +00:00
|
|
|
console.error(
|
|
|
|
`expected setup splash screen gif not found at location: ${splashScreenPath}`
|
|
|
|
)
|
2017-05-11 19:11:01 +00:00
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
2017-05-16 08:36:27 +00:00
|
|
|
const iconUrl = 'https://desktop.githubusercontent.com/app-icon.ico'
|
2017-03-27 04:54:19 +00:00
|
|
|
|
2017-10-15 06:05:28 +00:00
|
|
|
const nugetPkgName = getWindowsIdentifierName()
|
2017-10-15 06:02:33 +00:00
|
|
|
const options: electronInstaller.Options = {
|
2017-07-14 14:05:04 +00:00
|
|
|
name: nugetPkgName,
|
2016-09-27 01:47:48 +00:00
|
|
|
appDirectory: distPath,
|
|
|
|
outputDirectory: outputDir,
|
2017-10-15 06:05:28 +00:00
|
|
|
authors: getCompanyName(),
|
2017-03-27 04:54:19 +00:00
|
|
|
iconUrl: iconUrl,
|
|
|
|
setupIcon: iconSource,
|
2017-05-11 19:11:01 +00:00
|
|
|
loadingGif: splashScreenPath,
|
2017-07-14 14:05:04 +00:00
|
|
|
exe: `${nugetPkgName}.exe`,
|
|
|
|
title: productName,
|
2017-10-15 06:05:28 +00:00
|
|
|
setupExe: getWindowsStandaloneName(),
|
|
|
|
setupMsi: getWindowsInstallerName(),
|
2017-07-13 17:49:13 +00:00
|
|
|
}
|
|
|
|
|
2017-10-15 06:05:28 +00:00
|
|
|
if (shouldMakeDelta()) {
|
|
|
|
options.remoteReleases = getUpdatesURL()
|
2016-09-27 01:47:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.APPVEYOR) {
|
2017-03-27 09:47:35 +00:00
|
|
|
const certificatePath = path.join(__dirname, 'windows-certificate.pfx')
|
2017-07-13 13:36:37 +00:00
|
|
|
options.signWithParams = `/f ${certificatePath} /p ${process.env
|
|
|
|
.WINDOWS_CERT_PASSWORD} /tr http://timestamp.digicert.com /td sha256`
|
2016-09-27 01:47:48 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 14:47:51 +00:00
|
|
|
electronInstaller
|
2016-09-27 01:47:48 +00:00
|
|
|
.createWindowsInstaller(options)
|
2016-07-04 05:25:36 +00:00
|
|
|
.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
|
|
|
}
|
2017-07-28 11:21:48 +00:00
|
|
|
|
2017-07-29 14:34:11 +00:00
|
|
|
function packageRedhat() {
|
2017-10-15 06:26:35 +00:00
|
|
|
const installer: ElectronInstallerRedhat = require('electron-installer-redhat')
|
2017-07-29 14:34:11 +00:00
|
|
|
|
2017-10-15 06:02:33 +00:00
|
|
|
const options = {
|
2017-07-29 14:34:11 +00:00
|
|
|
src: distPath,
|
|
|
|
dest: outputDir,
|
|
|
|
arch: 'amd64',
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
console.log('Creating .rpm package...')
|
2017-10-15 06:26:35 +00:00
|
|
|
installer(options, err => {
|
2017-07-29 14:34:11 +00:00
|
|
|
if (err) {
|
|
|
|
reject(err)
|
|
|
|
} else {
|
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:21:48 +00:00
|
|
|
function packageDebian() {
|
2017-10-15 06:26:35 +00:00
|
|
|
const installer: ElectronInstallerDebian = require('electron-installer-debian')
|
2017-07-28 11:21:48 +00:00
|
|
|
|
2017-10-15 06:02:33 +00:00
|
|
|
const options = {
|
2017-07-28 11:21:48 +00:00
|
|
|
src: distPath,
|
|
|
|
dest: outputDir,
|
|
|
|
arch: 'amd64',
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
console.log('Creating .deb package...')
|
2017-10-15 06:26:35 +00:00
|
|
|
installer(options, err => {
|
2017-07-28 11:21:48 +00:00
|
|
|
if (err) {
|
|
|
|
reject(err)
|
|
|
|
} else {
|
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-01 21:48:29 +00:00
|
|
|
function packageAppImage() {
|
2017-10-02 01:35:08 +00:00
|
|
|
// Because electron-builder's CLI has some limits, we need to
|
|
|
|
// implement a couple of workarounds.
|
|
|
|
//
|
|
|
|
// First, it'll use `dist/make` for it's output directory, which
|
|
|
|
// results in this vague error when the directory doesn't exist:
|
2017-10-01 21:48:29 +00:00
|
|
|
//
|
|
|
|
// libburn : SORRY : Neither stdio-path nor its directory exist
|
|
|
|
//
|
2017-10-02 01:35:08 +00:00
|
|
|
// so let's just trash it (if already existing) and create the directory
|
2017-10-15 06:05:28 +00:00
|
|
|
const makeDir = path.join(getDistRoot(), 'make')
|
2017-10-01 21:48:29 +00:00
|
|
|
fs.removeSync(makeDir)
|
|
|
|
fs.mkdirSync(makeDir)
|
|
|
|
|
2017-10-15 06:26:35 +00:00
|
|
|
const installer: ElectronInstallerAppImage = require('electron-installer-appimage')
|
2017-10-01 21:48:29 +00:00
|
|
|
|
2017-10-15 06:02:33 +00:00
|
|
|
const options = {
|
2017-10-01 21:48:29 +00:00
|
|
|
dir: distPath,
|
|
|
|
targetArch: 'x64',
|
|
|
|
}
|
|
|
|
|
|
|
|
return installer.default(options).then(() => {
|
2017-10-02 01:35:08 +00:00
|
|
|
// Second, we need to move the relevant files from dist/make up to
|
|
|
|
// the installers directory so it's alongside the other packages
|
2017-10-01 21:48:29 +00:00
|
|
|
cp.execSync(`cp ${makeDir}/*.AppImage ${outputDir}`)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-15 06:26:35 +00:00
|
|
|
async function packageLinux(): Promise<void> {
|
2017-10-02 02:27:59 +00:00
|
|
|
try {
|
|
|
|
await packageRedhat()
|
|
|
|
await packageDebian()
|
|
|
|
await packageAppImage()
|
|
|
|
console.log(`Successfully created packages at ${outputDir}`)
|
|
|
|
} catch (e) {
|
|
|
|
console.log(`error during packaging: ${e}`)
|
|
|
|
}
|
2017-07-28 11:21:48 +00:00
|
|
|
}
|