github-desktop/script/package.ts

154 lines
3.9 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 cp from 'child_process'
import * as path from 'path'
2017-10-16 22:35:39 +00:00
import * as electronInstaller from 'electron-winstaller'
2017-11-20 01:30:16 +00:00
import { getProductName, getCompanyName } from '../app/package-info'
2017-10-15 06:05:28 +00:00
import {
getDistPath,
getOSXZipPath,
getWindowsIdentifierName,
getWindowsStandaloneName,
getWindowsInstallerName,
shouldMakeDelta,
getUpdatesURL,
getIconFileName,
2017-10-15 06:05:28 +00:00
} from './dist-info'
import { isAppveyor, isGitHubActions } from './build-platforms'
import { existsSync, rmSync } from 'fs'
2017-10-15 06:05:28 +00:00
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()
rmSync(dest, { recursive: true, force: true })
2016-05-25 14:37:27 +00:00
console.log('Packaging for macOS…')
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
}
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 (isAppveyor() || isGitHubActions()) {
console.log('Installing signing certificate…')
cp.execSync(`powershell ${setupCertificatePath}`, { stdio: 'inherit' })
}
2017-07-13 13:36:37 +00:00
const iconSource = path.join(
__dirname,
'..',
'app',
'static',
'logos',
`${getIconFileName()}.ico`
2017-07-13 13:36:37 +00:00
)
if (!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 (!existsSync(splashScreenPath)) {
2017-07-13 13:36:37 +00:00
console.error(
2017-12-12 05:21:47 +00:00
`expected setup splash screen gif not found at location: ${splashScreenPath}`
2017-07-13 13:36:37 +00:00
)
process.exit(1)
}
2022-02-15 14:08:15 +00:00
const iconUrl =
'https://desktop.githubusercontent.com/github-desktop/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()) {
const url = new URL(getUpdatesURL())
// Make sure Squirrel.Windows isn't affected by partially or completely
// disabled releases.
url.searchParams.set('bypassStaggeredRelease', '1')
options.remoteReleases = url.toString()
}
if (isAppveyor() || isGitHubActions()) {
const certificatePath = path.join(__dirname, 'windows-certificate.pfx')
2020-06-24 18:28:06 +00:00
options.signWithParams = `/f ${certificatePath} /p ${process.env.WINDOWS_CERT_PASSWORD} /tr http://timestamp.digicert.com /td sha256 /fd sha256`
}
console.log('Packaging for Windows…')
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
function packageLinux() {
const electronBuilder = path.resolve(
__dirname,
'..',
'node_modules',
'.bin',
'electron-builder'
)
2017-07-28 11:21:48 +00:00
const configPath = path.resolve(__dirname, 'electron-builder-linux.yml')
const args = [
'build',
'--prepackaged',
distPath,
'--x64',
'--config',
configPath,
]
console.log('Packaging for Linux…')
cp.spawnSync(electronBuilder, args, { stdio: 'inherit' })
2017-07-28 11:21:48 +00:00
}