github-desktop/script/package.ts

205 lines
5 KiB
TypeScript
Raw Normal View History

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'
)
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'
)
if (!fs.existsSync(iconSource)) {
2017-03-29 03:49:55 +00:00
console.error(`expected setup icon not found at location: ${iconSource}`)
process.exit(1)
}
2017-07-13 13:36:37 +00:00
const splashScreenPath = path.resolve(
__dirname,
'../app/static/logos/win32-installer-splash.gif'
)
if (!fs.existsSync(splashScreenPath)) {
2017-07-13 13:36:37 +00:00
console.error(
`expected setup splash screen gif not found at location: ${splashScreenPath}`
)
process.exit(1)
}
2017-05-16 08:36:27 +00:00
const iconUrl = 'https://desktop.githubusercontent.com/app-icon.ico'
2017-10-15 06:05:28 +00:00
const nugetPkgName = getWindowsIdentifierName()
2017-10-15 06:02:33 +00:00
const options: electronInstaller.Options = {
name: nugetPkgName,
appDirectory: distPath,
outputDirectory: outputDir,
2017-10-15 06:05:28 +00:00
authors: getCompanyName(),
iconUrl: iconUrl,
setupIcon: iconSource,
loadingGif: splashScreenPath,
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()
}
if (process.env.APPVEYOR) {
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`
}
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)
})
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()
}
})
})
}
function packageAppImage() {
// 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:
//
// libburn : SORRY : Neither stdio-path nor its directory exist
//
// 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')
fs.removeSync(makeDir)
fs.mkdirSync(makeDir)
2017-10-15 06:26:35 +00:00
const installer: ElectronInstallerAppImage = require('electron-installer-appimage')
2017-10-15 06:02:33 +00:00
const options = {
dir: distPath,
targetArch: 'x64',
}
return installer.default(options).then(() => {
// Second, we need to move the relevant files from dist/make up to
// the installers directory so it's alongside the other packages
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
}