forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage-application.js
More file actions
276 lines (259 loc) · 8.26 KB
/
Copy pathpackage-application.js
File metadata and controls
276 lines (259 loc) · 8.26 KB
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
'use strict';
const assert = require('assert');
const childProcess = require('child_process');
const electronPackager = require('electron-packager');
const fs = require('fs-extra');
const hostArch = require('@electron/get').getHostArch;
const includePathInPackagedApp = require('./include-path-in-packaged-app');
const getLicenseText = require('./get-license-text');
const path = require('path');
const spawnSync = require('./spawn-sync');
const template = require('lodash.template');
const CONFIG = require('../config');
const HOST_ARCH = hostArch();
module.exports = function() {
const appName = getAppName();
console.log(
`Running electron-packager on ${
CONFIG.intermediateAppPath
} with app name "${appName}"`
);
return runPackager({
appBundleId: 'com.github.atom',
appCopyright: `Copyright © 2014-${new Date().getFullYear()} GitHub, Inc. All rights reserved.`,
appVersion: CONFIG.appMetadata.version,
arch: process.platform === 'darwin' ? 'x64' : HOST_ARCH, // OS X is 64-bit only
asar: { unpack: buildAsarUnpackGlobExpression() },
buildVersion: CONFIG.appMetadata.version,
derefSymlinks: false,
download: { cache: CONFIG.electronDownloadPath },
dir: CONFIG.intermediateAppPath,
electronVersion: CONFIG.appMetadata.electronVersion,
extendInfo: path.join(
CONFIG.repositoryRootPath,
'resources',
'mac',
'atom-Info.plist'
),
helperBundleId: 'com.github.atom.helper',
icon: path.join(
CONFIG.repositoryRootPath,
'resources',
'app-icons',
CONFIG.channel,
'atom'
),
name: appName,
out: CONFIG.buildOutputPath,
overwrite: true,
platform: process.platform,
// Atom doesn't have devDependencies, but if prune is true, it will delete the non-standard packageDependencies.
prune: false,
win32metadata: {
CompanyName: 'GitHub, Inc.',
FileDescription: 'Atom',
ProductName: CONFIG.appName
}
}).then(packagedAppPath => {
let bundledResourcesPath;
if (process.platform === 'darwin') {
bundledResourcesPath = path.join(
packagedAppPath,
'Contents',
'Resources'
);
setAtomHelperVersion(packagedAppPath);
} else if (process.platform === 'linux') {
bundledResourcesPath = path.join(packagedAppPath, 'resources');
chmodNodeFiles(packagedAppPath);
} else {
bundledResourcesPath = path.join(packagedAppPath, 'resources');
}
return copyNonASARResources(packagedAppPath, bundledResourcesPath).then(
() => {
console.log(`Application bundle created at ${packagedAppPath}`);
return packagedAppPath;
}
);
});
};
function copyNonASARResources(packagedAppPath, bundledResourcesPath) {
console.log(`Copying non-ASAR resources to ${bundledResourcesPath}`);
fs.copySync(
path.join(
CONFIG.repositoryRootPath,
'apm',
'node_modules',
'atom-package-manager'
),
path.join(bundledResourcesPath, 'app', 'apm'),
{ filter: includePathInPackagedApp }
);
if (process.platform !== 'win32') {
// Existing symlinks on user systems point to an outdated path, so just symlink it to the real location of the apm binary.
// TODO: Change command installer to point to appropriate path and remove this fallback after a few releases.
fs.symlinkSync(
path.join('..', '..', 'bin', 'apm'),
path.join(
bundledResourcesPath,
'app',
'apm',
'node_modules',
'.bin',
'apm'
)
);
fs.copySync(
path.join(CONFIG.repositoryRootPath, 'atom.sh'),
path.join(bundledResourcesPath, 'app', 'atom.sh')
);
}
if (process.platform === 'darwin') {
fs.copySync(
path.join(CONFIG.repositoryRootPath, 'resources', 'mac', 'file.icns'),
path.join(bundledResourcesPath, 'file.icns')
);
} else if (process.platform === 'linux') {
fs.copySync(
path.join(
CONFIG.repositoryRootPath,
'resources',
'app-icons',
CONFIG.channel,
'png',
'1024.png'
),
path.join(packagedAppPath, 'atom.png')
);
} else if (process.platform === 'win32') {
[
'atom.sh',
'atom.js',
'apm.cmd',
'apm.sh',
'file.ico',
'folder.ico'
].forEach(file =>
fs.copySync(
path.join('resources', 'win', file),
path.join(bundledResourcesPath, 'cli', file)
)
);
// Customize atom.cmd for the channel-specific atom.exe name (e.g. atom-beta.exe)
generateAtomCmdForChannel(bundledResourcesPath);
}
console.log(`Writing LICENSE.md to ${bundledResourcesPath}`);
return getLicenseText().then(licenseText => {
fs.writeFileSync(
path.join(bundledResourcesPath, 'LICENSE.md'),
licenseText
);
});
}
function setAtomHelperVersion(packagedAppPath) {
const frameworksPath = path.join(packagedAppPath, 'Contents', 'Frameworks');
const helperPListPath = path.join(
frameworksPath,
'Atom Helper.app',
'Contents',
'Info.plist'
);
console.log(`Setting Atom Helper Version for ${helperPListPath}`);
spawnSync('/usr/libexec/PlistBuddy', [
'-c',
`Add CFBundleVersion string ${CONFIG.appMetadata.version}`,
helperPListPath
]);
spawnSync('/usr/libexec/PlistBuddy', [
'-c',
`Add CFBundleShortVersionString string ${CONFIG.appMetadata.version}`,
helperPListPath
]);
}
function chmodNodeFiles(packagedAppPath) {
console.log(`Changing permissions for node files in ${packagedAppPath}`);
childProcess.execSync(
`find "${packagedAppPath}" -type f -name *.node -exec chmod a-x {} \\;`
);
}
function buildAsarUnpackGlobExpression() {
const unpack = [
'*.node',
'ctags-config',
'ctags-darwin',
'ctags-linux',
'ctags-win32.exe',
path.join('**', 'node_modules', 'spellchecker', '**'),
path.join('**', 'node_modules', 'dugite', 'git', '**'),
path.join('**', 'node_modules', 'github', 'bin', '**'),
path.join('**', 'node_modules', 'vscode-ripgrep', 'bin', '**'),
path.join('**', 'resources', 'atom.png')
];
return `{${unpack.join(',')}}`;
}
function getAppName() {
if (process.platform === 'darwin') {
return CONFIG.appName;
} else if (process.platform === 'win32') {
return CONFIG.channel === 'stable' ? 'atom' : `atom-${CONFIG.channel}`;
} else {
return 'atom';
}
}
async function runPackager(options) {
const packageOutputDirPaths = await electronPackager(options);
assert(
packageOutputDirPaths.length === 1,
'Generated more than one electron application!'
);
return renamePackagedAppDir(packageOutputDirPaths[0]);
}
function renamePackagedAppDir(packageOutputDirPath) {
let packagedAppPath;
if (process.platform === 'darwin') {
const appBundleName = getAppName() + '.app';
packagedAppPath = path.join(CONFIG.buildOutputPath, appBundleName);
if (fs.existsSync(packagedAppPath)) fs.removeSync(packagedAppPath);
fs.renameSync(
path.join(packageOutputDirPath, appBundleName),
packagedAppPath
);
} else if (process.platform === 'linux') {
const appName =
CONFIG.channel !== 'stable' ? `atom-${CONFIG.channel}` : 'atom';
let architecture;
if (HOST_ARCH === 'ia32') {
architecture = 'i386';
} else if (HOST_ARCH === 'x64') {
architecture = 'amd64';
} else {
architecture = HOST_ARCH;
}
packagedAppPath = path.join(
CONFIG.buildOutputPath,
`${appName}-${CONFIG.appMetadata.version}-${architecture}`
);
if (fs.existsSync(packagedAppPath)) fs.removeSync(packagedAppPath);
fs.renameSync(packageOutputDirPath, packagedAppPath);
} else {
packagedAppPath = path.join(CONFIG.buildOutputPath, CONFIG.appName);
if (process.platform === 'win32' && HOST_ARCH !== 'ia32') {
packagedAppPath += ` ${process.arch}`;
}
if (fs.existsSync(packagedAppPath)) fs.removeSync(packagedAppPath);
fs.renameSync(packageOutputDirPath, packagedAppPath);
}
return packagedAppPath;
}
function generateAtomCmdForChannel(bundledResourcesPath) {
const atomCmdTemplate = fs.readFileSync(
path.join(CONFIG.repositoryRootPath, 'resources', 'win', 'atom.cmd')
);
const atomCmdContents = template(atomCmdTemplate)({
atomExeName: CONFIG.executableName
});
fs.writeFileSync(
path.join(bundledResourcesPath, 'cli', 'atom.cmd'),
atomCmdContents
);
}