github-desktop/script/package.ts

139 lines
4 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,
2023-06-20 15:31:24 +00:00
isPublishable,
2023-06-21 11:34:15 +00:00
getBundleSizes,
2023-06-27 15:55:51 +00:00
getDistRoot,
getDistArchitecture,
2017-10-15 06:05:28 +00:00
} from './dist-info'
import { isGitHubActions } from './build-platforms'
2023-06-21 11:34:15 +00:00
import { existsSync, rmSync, writeFileSync } from 'fs'
import { getVersion } from '../app/package-info'
import { rename } from 'fs/promises'
import { join } from 'path'
2017-10-15 06:05:28 +00:00
const distPath = getDistPath()
const productName = getProductName()
const outputDir = getDistRoot()
2016-05-25 14:37:27 +00:00
if (process.platform === 'darwin') {
packageOSX()
} else if (process.platform === 'win32') {
packageWindows()
} else {
console.error(`I don't know how to package for ${process.platform} :(`)
2016-05-25 14:37:27 +00:00
process.exit(1)
}
2023-06-27 15:55:51 +00:00
console.log('Writing bundle size info…')
2023-06-21 11:34:15 +00:00
writeFileSync(
2023-06-27 15:55:51 +00:00
path.join(getDistRoot(), 'bundle-size.json'),
2023-06-21 11:34:15 +00:00
JSON.stringify(getBundleSizes())
)
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 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()
}
2023-06-20 15:31:24 +00:00
if (isGitHubActions() && isPublishable()) {
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}`))
.then(async () => {
// electron-winstaller (more specifically Squirrel.Windows) doesn't let
// us control the name of the nuget packages but we want them to include
// the architecture similar to how the setup exe and msi do so we'll just
// have to rename them here after the fact.
const arch = getDistArchitecture()
const prefix = `${getWindowsIdentifierName()}-${getVersion()}`
for (const kind of shouldMakeDelta() ? ['full', 'delta'] : ['full']) {
const from = join(outputDir, `${prefix}-${kind}.nupkg`)
const to = join(outputDir, `${prefix}-${arch}-${kind}.nupkg`)
console.log(`Renaming ${from} to ${to}`)
await rename(from, to)
}
})
.catch(e => {
console.error(`Error packaging: ${e}`)
process.exit(1)
})
2016-05-25 14:37:27 +00:00
}