forked from desktop/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.ts
206 lines (179 loc) · 5.03 KB
/
package.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* eslint-disable no-sync */
import * as fs from 'fs-extra'
import * as cp from 'child_process'
import * as path from 'path'
import * as electronInstaller from 'electron-winstaller'
import { getProductName, getCompanyName } from '../app/package-info'
import {
getDistRoot,
getDistPath,
getOSXZipPath,
getWindowsIdentifierName,
getWindowsStandaloneName,
getWindowsInstallerName,
shouldMakeDelta,
getUpdatesURL,
} from './dist-info'
const distPath = getDistPath()
const productName = getProductName()
const outputDir = path.join(distPath, '..', 'installer')
if (process.platform === 'darwin') {
packageOSX()
} else if (process.platform === 'win32') {
packageWindows()
} else if (process.platform === 'linux') {
packageLinux()
} else {
console.error(`I dunno how to package for ${process.platform} :(`)
process.exit(1)
}
function packageOSX() {
const dest = getOSXZipPath()
fs.removeSync(dest)
cp.execSync(
`ditto -ck --keepParent "${distPath}/${productName}.app" "${dest}"`
)
console.log(`Zipped to ${dest}`)
}
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}`)
}
const iconSource = path.join(
__dirname,
'..',
'app',
'static',
'logos',
'icon-logo.ico'
)
if (!fs.existsSync(iconSource)) {
console.error(`expected setup icon not found at location: ${iconSource}`)
process.exit(1)
}
const splashScreenPath = path.resolve(
__dirname,
'../app/static/logos/win32-installer-splash.gif'
)
if (!fs.existsSync(splashScreenPath)) {
console.error(
`expected setup splash screen gif not found at location: ${
splashScreenPath
}`
)
process.exit(1)
}
const iconUrl = 'https://desktop.githubusercontent.com/app-icon.ico'
const nugetPkgName = getWindowsIdentifierName()
const options: electronInstaller.Options = {
name: nugetPkgName,
appDirectory: distPath,
outputDirectory: outputDir,
authors: getCompanyName(),
iconUrl: iconUrl,
setupIcon: iconSource,
loadingGif: splashScreenPath,
exe: `${nugetPkgName}.exe`,
title: productName,
setupExe: getWindowsStandaloneName(),
setupMsi: getWindowsInstallerName(),
}
if (shouldMakeDelta()) {
options.remoteReleases = getUpdatesURL()
}
if (process.env.APPVEYOR) {
const certificatePath = path.join(__dirname, 'windows-certificate.pfx')
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)
})
}
function packageRedhat() {
const installer: ElectronInstallerRedhat = require('electron-installer-redhat')
const options = {
src: distPath,
dest: outputDir,
arch: 'amd64',
}
return new Promise((resolve, reject) => {
console.log('Creating .rpm package...')
installer(options, err => {
if (err) {
reject(err)
} else {
resolve()
}
})
})
}
function packageDebian() {
const installer: ElectronInstallerDebian = require('electron-installer-debian')
const options = {
src: distPath,
dest: outputDir,
arch: 'amd64',
}
return new Promise((resolve, reject) => {
console.log('Creating .deb package...')
installer(options, err => {
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
const makeDir = path.join(getDistRoot(), 'make')
fs.removeSync(makeDir)
fs.mkdirSync(makeDir)
const installer: ElectronInstallerAppImage = require('electron-installer-appimage')
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}`)
})
}
async function packageLinux(): Promise<void> {
try {
await packageRedhat()
await packageDebian()
await packageAppImage()
console.log(`Successfully created packages at ${outputDir}`)
} catch (e) {
console.log(`error during packaging: ${e}`)
}
}