forked from desktop/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·277 lines (235 loc) · 7.85 KB
/
build
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/usr/bin/env node
'use strict'
const path = require('path')
const cp = require('child_process')
const fs = require('fs-extra')
const packager = require('electron-packager')
const legalEagle = require('legal-eagle')
const projectRoot = path.join(__dirname, '..')
const outRoot = path.join(projectRoot, 'out')
const distInfo = require('./dist-info')
const isPublishableBuild = distInfo.getReleaseChannel() !== 'development'
console.log(`Building for ${distInfo.getReleaseChannel()}…`)
console.log('Removing old distribution…')
fs.removeSync(path.join(projectRoot, 'dist'))
console.log('Copying dependencies…')
copyDependencies()
console.log('Packaging emoji…')
copyEmoji()
console.log('Copying static resources…')
copyStaticResources()
const isFork = process.env.TRAVIS_SECURE_ENV_VARS !== 'true'
if (process.platform === 'darwin' && process.env.TRAVIS && !isFork) {
console.log('Setting up keychain…')
cp.execSync(path.join(__dirname, 'setup-macos-keychain'))
}
console.log('Updating our licenses dump…')
updateLicenseDump(err => {
if (err) {
console.error(
'Error updating the license dump. This is fatal for a published build.'
)
console.error(err)
if (isPublishableBuild) {
process.exit(1)
return
}
}
console.log('Packaging…')
packageApp((err, appPaths) => {
if (err) {
console.error(err)
process.exit(1)
} else {
console.log(`Built to ${appPaths}`)
process.exit(0)
}
})
})
function packageApp(callback) {
const options = {
name: distInfo.getExecutableName(),
platform: process.platform,
arch: 'x64',
asar: false, // TODO: Probably wanna enable this down the road.
out: path.join(projectRoot, 'dist'),
icon: path.join(projectRoot, 'app', 'static', 'logos', 'icon-logo'),
dir: outRoot,
overwrite: true,
tmpdir: false,
derefSymlinks: false,
prune: false, // We'll prune them ourselves below.
ignore: [
'/node_modules/electron($|/)',
'/node_modules/electron-packager($|/)',
'/\\.git($|/)',
'/node_modules/\\.bin($|/)',
],
appCopyright: 'Copyright © 2017 GitHub, Inc.',
// macOS
appBundleId: distInfo.getBundleID(),
appCategoryType: 'public.app-category.developer-tools',
protocols: [
{
name: distInfo.getBundleID(),
schemes: [
isPublishableBuild
? 'x-github-desktop-auth'
: 'x-github-desktop-dev-auth',
'x-github-client',
'github-mac',
],
},
],
osxSign: true,
// Windows
win32metadata: {
CompanyName: distInfo.getCompanyName(),
FileDescription: '',
OriginalFilename: '',
ProductName: distInfo.getProductName(),
InternalName: distInfo.getProductName(),
},
}
packager(options, (err, appPaths) => {
if (err) {
callback(err, null)
} else {
callback(null, appPaths)
}
})
}
function copyEmoji() {
const copyImages = () => {
const source = path.join(projectRoot, 'gemoji', 'images', 'emoji')
const destination = path.join(outRoot, 'emoji')
fs.removeSync(destination)
fs.copySync(source, destination)
}
const copyJson = () => {
const source = path.join(projectRoot, 'gemoji', 'db', 'emoji.json')
const destination = path.join(outRoot, 'emoji.json')
fs.removeSync(destination)
fs.copySync(source, destination)
}
copyImages()
copyJson()
}
function copyStaticResources() {
const dirName = process.platform
const platformSpecific = path.join(projectRoot, 'app', 'static', dirName)
const common = path.join(projectRoot, 'app', 'static', 'common')
const destination = path.join(outRoot, 'static')
fs.removeSync(destination)
if (fs.existsSync(platformSpecific)) {
fs.copySync(platformSpecific, destination)
}
fs.copySync(common, destination, { clobber: false })
}
function copyDependencies() {
const originalPackage = require(path.join(projectRoot, 'app', 'package.json'))
const commonConfig = require(path.resolve(__dirname, '../app/webpack.common'))
const externals = commonConfig.externals
const oldDependencies = originalPackage.dependencies
const newDependencies = {}
for (var [name, spec] of Object.entries(oldDependencies)) {
if (externals.indexOf(name) !== -1) {
newDependencies[name] = spec
}
}
const oldDevDependencies = originalPackage.devDependencies
const newDevDependencies = {}
if (!isPublishableBuild) {
for (var [name, spec] of Object.entries(oldDevDependencies)) {
if (externals.indexOf(name) !== -1) {
newDevDependencies[name] = spec
}
}
}
// The product name changes depending on whether it's a prod build or dev
// build, so that we can have them running side by side.
const updatedPackage = Object.assign({}, originalPackage, {
productName: distInfo.getProductName(),
dependencies: newDependencies,
devDependencies: newDevDependencies,
})
if (isPublishableBuild) {
delete updatedPackage.devDependencies
}
fs.writeFileSync(
path.join(outRoot, 'package.json'),
JSON.stringify(updatedPackage)
)
fs.removeSync(path.resolve(outRoot, 'node_modules'))
if (
Object.keys(newDependencies).length ||
Object.keys(newDevDependencies).length
) {
console.log(' Installing npm dependencies…')
cp.execSync('npm install', { cwd: outRoot, env: process.env })
}
if (!isPublishableBuild) {
console.log(
' Installing 7zip (dependency for electron-devtools-installer)'
)
const sevenZipSource = path.resolve(projectRoot, 'app/node_modules/7zip')
const sevenZipDestination = path.resolve(outRoot, 'node_modules/7zip')
fs.mkdirpSync(sevenZipDestination)
fs.copySync(sevenZipSource, sevenZipDestination)
}
console.log(' Copying git environment…')
const gitDir = path.resolve(outRoot, 'git')
fs.removeSync(gitDir)
fs.mkdirpSync(gitDir)
fs.copySync(path.resolve(projectRoot, 'app/node_modules/dugite/git'), gitDir)
}
function updateLicenseDump(callback) {
const appRoot = path.join(projectRoot, 'app')
const outPath = path.join(outRoot, 'static', 'licenses.json')
const licenseOverrides = require('./license-overrides')
legalEagle(
{ path: appRoot, overrides: licenseOverrides, omitPermissive: true },
(err, summary) => {
if (err) {
callback(err)
return
}
if (Object.keys(summary).length > 0) {
const overridesPath = path.join(__dirname, 'license-overrides.js')
let licensesMessage = ''
for (const key in summary) {
const license = summary[key]
licensesMessage += `${key} (${license.repository}): ${license.license}\n`
}
const message = `The following dependencies have unknown or non-permissive licenses. Check it out and update ${overridesPath} if appropriate:\n${licensesMessage}`
callback(new Error(message))
} else {
legalEagle(
{ path: appRoot, overrides: licenseOverrides },
(err, summary) => {
if (err) {
callback(err)
return
}
// legal-eagle still chooses to ignore the LICENSE at the root
// this injects the current license and pins the source URL before we
// dump the JSON file to disk
const licenseSource = path.join(projectRoot, 'LICENSE')
const licenseText = fs.readFileSync(licenseSource, {
encoding: 'utf-8',
})
const appVersion = distInfo.getVersion()
summary[`desktop@${appVersion}`] = {
repository: 'https://github.com/desktop/desktop',
license: 'MIT',
source: `https://github.com/desktop/desktop/blob/release-${appVersion}/LICENSE`,
sourceText: licenseText,
}
fs.writeFileSync(outPath, JSON.stringify(summary), 'utf8')
callback(null)
}
)
}
}
)
}