This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 974
/
buildPackage.js
187 lines (164 loc) · 6.33 KB
/
buildPackage.js
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
var VersionInfo = require('./lib/versionInfo')
var execute = require('./lib/execute')
const ignoredPaths = require('./lib/ignoredPaths')
const config = require('./lib/config')
const path = require('path')
const isWindows = process.platform === 'win32'
const isDarwin = process.platform === 'darwin'
var arch = 'x64'
const isLinux = process.platform === 'linux'
var env = {
NODE_ENV: 'production',
CHANNEL: process.env.CHANNEL,
REF: process.env.REF || null,
REFERRAL_API_KEY: process.env.REFERRAL_API_KEY
}
const channel = env.CHANNEL
const ref = env.REF
var channels = { nightly: true, developer: true, beta: true, dev: true }
if (!channels[channel]) {
throw new Error('CHANNEL environment variable must be set to nightly, developer, beta or dev')
}
var appIcon
if (isWindows) {
appIcon = `res/${channel}/app.ico`
if (process.env.TARGET_ARCH === 'ia32') {
arch = 'ia32'
}
} else if (isDarwin) {
appIcon = `res/${channel}/app.icns`
} else {
appIcon = `res/${channel}/app.png`
}
var appName
switch (channel) {
case 'nightly':
appName = 'Brave-Nightly'
break
case 'developer':
appName = 'Brave-Developer'
break
case 'beta':
appName = 'Brave-Beta'
break
case 'dev':
appName = 'Brave'
break
default:
throw new Error('CHANNEL environment variable must be set to nightly, developer, beta or dev')
}
if (isLinux) {
appName = appName.toLowerCase()
}
if (isWindows) {
appName = appName.replace(/-/, '')
}
var productDirName = 'brave'
if (channel !== 'dev') {
productDirName += `-${channel}`
}
const buildDir = appName + '-' + process.platform + '-' + arch
console.log('Writing buildConfig.js...')
config.writeBuildConfig(
{
channel: channel,
BROWSER_LAPTOP_REV: require('git-rev-sync').long(),
nodeEnv: env.NODE_ENV,
ref: ref || null,
referralAPI: env.REFERRAL_API_KEY
},
'buildConfig.js'
)
var cmds = ['echo cleaning up target...']
if (isWindows) {
cmds = cmds.concat([
'cmd.exe /c for /d %x in (*-win32-x64) do rmdir /s /q "%x"',
'cmd.exe /c for /d %x in (*-win32-ia32) do rmdir /s /q "%x"'
])
// Remove the destination folder
cmds = cmds.concat([
'(if exist dist rmdir /s /q dist)'
])
} else {
cmds = cmds.concat([
'rm -Rf ' + '*-' + process.platform + '-' + arch,
'rm -Rf dist',
`rm -f *.tar.bz2`
])
}
cmds = cmds.concat([
'echo done',
'echo starting build...'
])
console.log('Building version ' + VersionInfo.braveVersion + ' in ' + buildDir + ' with Electron ' + VersionInfo.electronVersion)
cmds = cmds.concat([
'"./node_modules/.bin/webpack"',
// NOTE: api.nodesecurity.io seems to be down?
// 'npm run checks',
`node ./node_modules/electron-packager/cli.js . ${appName}` +
' --overwrite=true' +
' --ignore="' + ignoredPaths.join('|') + '"' +
' --platform=' + process.platform +
' --arch=' + arch +
` --name="${appName}"` +
' --version=' + VersionInfo.electronVersion +
' --icon=' + appIcon +
' --asar=true' +
' --app-version=' + VersionInfo.braveVersion +
' --build-version=' + VersionInfo.electronVersion +
' --protocol="http" --protocol-name="HTTP Handler"' +
' --protocol="https" --protocol-name="HTTPS Handler"' +
` --product-dir-name="${productDirName}"` +
' --version-string.CompanyName="Brave Software"' +
` --version-string.ProductName="${appName}"` +
' --version-string.Copyright="Copyright 2017, Brave Software"' +
` --version-string.FileDescription="${appName}"`
])
function BuildManifestFile () {
const fs = require('fs')
const fileContents = fs.readFileSync('./res/Update.VisualElementsManifest.xml', 'utf8')
const versionedFileContents = fileContents.replace(/{{braveVersion}}/g, 'app-' + VersionInfo.braveVersion)
fs.writeFileSync('temp.VisualElementsManifest.xml', versionedFileContents, 'utf8')
}
if (isLinux) {
cmds.push('ncp ./app/extensions ' + path.join(buildDir, 'resources', 'extensions'))
} else if (isDarwin) {
const macAppName = `${appName}.app`
cmds.push('ncp ./app/extensions ' + path.join(buildDir, macAppName, 'Contents', 'Resources', 'extensions'))
} else if (isWindows) {
BuildManifestFile()
cmds.push('move .\\temp.VisualElementsManifest.xml "' + path.join(buildDir, 'resources', 'Update.VisualElementsManifest.xml') + '"')
cmds.push('copy .\\res\\start-tile-70.png "' + path.join(buildDir, 'resources', 'start-tile-70.png') + '"')
cmds.push('copy .\\res\\start-tile-150.png "' + path.join(buildDir, 'resources', 'start-tile-150.png') + '"')
cmds.push('makensis.exe -DARCH=' + arch + ` res/${channel}/braveDefaults.nsi`)
cmds.push('ncp ./app/extensions ' + path.join(buildDir, 'resources', 'extensions'))
// Make sure the Brave.exe binary is squirrel aware so we get squirrel events and so that Squirrel doesn't auto create shortcuts.
cmds.push(`"node_modules/rcedit/bin/rcedit.exe" ./${appName}-win32-` + arch + `/${appName}.exe --set-version-string "SquirrelAwareVersion" "1"`)
}
// Verify tor binaries and bundle with Brave
var torPath
if (isDarwin) {
torPath = path.join(buildDir, `${appName}.app`, 'Contents', 'Resources', 'extensions', 'bin')
} else {
torPath = path.join(buildDir, 'resources', 'extensions', 'bin')
}
cmds.push('npm run package-tor ' + torPath)
if (isDarwin) {
const macAppName = `${appName}.app`
cmds.push('mkdirp ' + path.join(buildDir, macAppName, 'Contents', 'Resources', 'app.asar.unpacked', 'node_modules', 'node-anonize2-relic-emscripten'))
cmds.push('ncp ' + path.join('node_modules', 'node-anonize2-relic-emscripten', 'anonize2.js.mem') + ' ' + path.join(buildDir, macAppName, 'Contents', 'Resources', 'app.asar.unpacked', 'node_modules', 'node-anonize2-relic-emscripten', 'anonize2.js.mem'))
} else {
cmds.push('mkdirp ' + path.join(buildDir, 'resources', 'app.asar.unpacked', 'node_modules', 'node-anonize2-relic-emscripten'))
cmds.push('ncp ' + path.join('node_modules', 'node-anonize2-relic-emscripten', 'anonize2.js.mem') + ' ' + path.join(buildDir, 'resources', 'app.asar.unpacked', 'node_modules', 'node-anonize2-relic-emscripten', 'anonize2.js.mem'))
}
execute(cmds, env, (err) => {
if (err) {
console.error('buildPackage failed', err)
process.exit(1)
}
config.clearBuildConfig()
console.log('done')
})