forked from rockybars/atom-shell-packager
/
mac.js
383 lines (337 loc) · 15.8 KB
/
mac.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
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
var exec = require('child_process').exec
var fs = require('fs')
var path = require('path')
var packager = require('..')
var test = require('tape')
var waterfall = require('run-waterfall')
var config = require('./config.json')
var util = require('./util')
var plist = require('plist')
var filterCFBundleIdentifier = require('../mac').filterCFBundleIdentifier
function createIconTest (baseOpts, icon, iconPath) {
return function (t) {
t.timeoutAfter(config.timeout)
var opts = Object.create(baseOpts)
opts.icon = icon
var resourcesPath
waterfall([
function (cb) {
packager(opts, cb)
}, function (paths, cb) {
resourcesPath = path.join(paths[0], util.generateResourcesPath(opts))
fs.stat(resourcesPath, cb)
}, function (stats, cb) {
t.true(stats.isDirectory(), 'The output directory should contain the expected resources subdirectory')
util.areFilesEqual(iconPath, path.join(resourcesPath, 'atom.icns'), cb)
}, function (equal, cb) {
t.true(equal, 'atom.icns should be identical to the specified icon file')
cb()
}
], function (err) {
t.end(err)
})
}
}
function createAppVersionTest (baseOpts, appVersion, buildVersion) {
return function (t) {
t.timeoutAfter(config.timeout)
var plistPath
var opts = Object.create(baseOpts)
opts['app-version'] = opts['build-version'] = appVersion
if (buildVersion) {
opts['build-version'] = buildVersion
}
waterfall([
function (cb) {
packager(opts, cb)
}, function (paths, cb) {
plistPath = path.join(paths[0], opts.name + '.app', 'Contents', 'Info.plist')
fs.stat(plistPath, cb)
}, function (stats, cb) {
t.true(stats.isFile(), 'The expected Info.plist file should exist')
fs.readFile(plistPath, 'utf8', cb)
}, function (file, cb) {
var obj = plist.parse(file)
t.equal(obj.CFBundleVersion, '' + opts['build-version'], 'CFBundleVersion should reflect build-version')
t.equal(obj.CFBundleShortVersionString, '' + opts['app-version'], 'CFBundleShortVersionString should reflect app-version')
t.equal(typeof obj.CFBundleVersion, 'string', 'CFBundleVersion should be a string')
t.equal(typeof obj.CFBundleShortVersionString, 'string', 'CFBundleShortVersionString should be a string')
cb()
}
], function (err) {
t.end(err)
})
}
}
function createAppCategoryTypeTest (baseOpts, appCategoryType) {
return function (t) {
t.timeoutAfter(config.timeout)
var plistPath
var opts = Object.create(baseOpts)
opts['app-category-type'] = appCategoryType
waterfall([
function (cb) {
packager(opts, cb)
}, function (paths, cb) {
plistPath = path.join(paths[0], opts.name + '.app', 'Contents', 'Info.plist')
fs.stat(plistPath, cb)
}, function (stats, cb) {
t.true(stats.isFile(), 'The expected Info.plist file should exist')
fs.readFile(plistPath, 'utf8', cb)
}, function (file, cb) {
var obj = plist.parse(file)
t.equal(obj.LSApplicationCategoryType, opts['app-category-type'], 'LSApplicationCategoryType should reflect opts.["app-category-type"]')
cb()
}
], function (err) {
t.end(err)
})
}
}
function createAppBundleTest (baseOpts, appBundleId) {
return function (t) {
t.timeoutAfter(config.timeout)
var plistPath
var opts = Object.create(baseOpts)
if (appBundleId) {
opts['app-bundle-id'] = appBundleId
}
var defaultBundleName = 'com.electron.' + opts.name.toLowerCase()
var appBundleIdentifier = filterCFBundleIdentifier(opts['app-bundle-id'] || defaultBundleName)
waterfall([
function (cb) {
packager(opts, cb)
}, function (paths, cb) {
plistPath = path.join(paths[0], opts.name + '.app', 'Contents', 'Info.plist')
fs.stat(plistPath, cb)
}, function (stats, cb) {
t.true(stats.isFile(), 'The expected Info.plist file should exist')
fs.readFile(plistPath, 'utf8', cb)
}, function (file, cb) {
var obj = plist.parse(file)
t.equal(obj.CFBundleDisplayName, opts.name, 'CFBundleDisplayName should reflect opts.name')
t.equal(obj.CFBundleName, opts.name, 'CFBundleName should reflect opts.name')
t.equal(obj.CFBundleIdentifier, appBundleIdentifier, 'CFBundleName should reflect opts["app-bundle-id"] or fallback to default')
t.equal(typeof obj.CFBundleDisplayName, 'string', 'CFBundleDisplayName should be a string')
t.equal(typeof obj.CFBundleName, 'string', 'CFBundleName should be a string')
t.equal(typeof obj.CFBundleIdentifier, 'string', 'CFBundleIdentifier should be a string')
t.equal(/^[a-zA-Z0-9-.]*$/.test(obj.CFBundleIdentifier), true, 'CFBundleIdentifier should allow only alphanumeric (A-Z,a-z,0-9), hyphen (-), and period (.)')
cb()
}
], function (err) {
t.end(err)
})
}
}
function createAppHelpersBundleTest (baseOpts, helperBundleId, appBundleId) {
return function (t) {
t.timeoutAfter(config.timeout)
var tempPath, plistPath
var opts = Object.create(baseOpts)
if (helperBundleId) {
opts['helper-bundle-id'] = appBundleId
}
if (appBundleId) {
opts['app-bundle-id'] = appBundleId
}
var defaultBundleName = 'com.electron.' + opts.name.toLowerCase()
var appBundleIdentifier = filterCFBundleIdentifier(opts['app-bundle-id'] || defaultBundleName)
var helperBundleIdentifier = filterCFBundleIdentifier(opts['helper-bundle-id'] || appBundleIdentifier + '.helper')
waterfall([
function (cb) {
packager(opts, cb)
}, function (paths, cb) {
tempPath = paths[0]
plistPath = path.join(tempPath, opts.name + '.app', 'Contents', 'Frameworks', opts.name + ' Helper.app', 'Contents', 'Info.plist')
fs.stat(plistPath, cb)
}, function (stats, cb) {
t.true(stats.isFile(), 'The expected Info.plist file should exist in helper app')
fs.readFile(plistPath, 'utf8', cb)
}, function (file, cb) {
var obj = plist.parse(file)
t.equal(obj.CFBundleName, opts.name, 'CFBundleName should reflect opts.name in helper app')
t.equal(obj.CFBundleIdentifier, helperBundleIdentifier, 'CFBundleName should reflect opts["helper-bundle-id"], opts["app-bundle-id"] or fallback to default in helper app')
t.equal(typeof obj.CFBundleName, 'string', 'CFBundleName should be a string in helper app')
t.equal(typeof obj.CFBundleIdentifier, 'string', 'CFBundleIdentifier should be a string in helper app')
t.equal(/^[a-zA-Z0-9-.]*$/.test(obj.CFBundleIdentifier), true, 'CFBundleIdentifier should allow only alphanumeric (A-Z,a-z,0-9), hyphen (-), and period (.)')
// check helper EH
plistPath = path.join(tempPath, opts.name + '.app', 'Contents', 'Frameworks', opts.name + ' Helper EH.app', 'Contents', 'Info.plist')
fs.stat(plistPath, cb)
}, function (stats, cb) {
t.true(stats.isFile(), 'The expected Info.plist file should exist in helper EH app')
fs.readFile(plistPath, 'utf8', cb)
}, function (file, cb) {
var obj = plist.parse(file)
t.equal(obj.CFBundleName, opts.name + ' Helper EH', 'CFBundleName should reflect opts.name in helper EH app')
t.equal(obj.CFBundleDisplayName, opts.name + ' Helper EH', 'CFBundleDisplayName should reflect opts.name in helper EH app')
t.equal(obj.CFBundleExecutable, opts.name + ' Helper EH', 'CFBundleExecutable should reflect opts.name in helper EH app')
t.equal(obj.CFBundleIdentifier, helperBundleIdentifier + '.EH', 'CFBundleName should reflect opts["helper-bundle-id"], opts["app-bundle-id"] or fallback to default in helper EH app')
t.equal(typeof obj.CFBundleName, 'string', 'CFBundleName should be a string in helper EH app')
t.equal(typeof obj.CFBundleDisplayName, 'string', 'CFBundleDisplayName should be a string in helper EH app')
t.equal(typeof obj.CFBundleExecutable, 'string', 'CFBundleExecutable should be a string in helper EH app')
t.equal(typeof obj.CFBundleIdentifier, 'string', 'CFBundleIdentifier should be a string in helper EH app')
t.equal(/^[a-zA-Z0-9-.]*$/.test(obj.CFBundleIdentifier), true, 'CFBundleIdentifier should allow only alphanumeric (A-Z,a-z,0-9), hyphen (-), and period (.)')
// check helper NP
plistPath = path.join(tempPath, opts.name + '.app', 'Contents', 'Frameworks', opts.name + ' Helper NP.app', 'Contents', 'Info.plist')
fs.stat(plistPath, cb)
}, function (stats, cb) {
t.true(stats.isFile(), 'The expected Info.plist file should exist in helper NP app')
fs.readFile(plistPath, 'utf8', cb)
}, function (file, cb) {
var obj = plist.parse(file)
t.equal(obj.CFBundleName, opts.name + ' Helper NP', 'CFBundleName should reflect opts.name in helper NP app')
t.equal(obj.CFBundleDisplayName, opts.name + ' Helper NP', 'CFBundleDisplayName should reflect opts.name in helper NP app')
t.equal(obj.CFBundleExecutable, opts.name + ' Helper NP', 'CFBundleExecutable should reflect opts.name in helper NP app')
t.equal(obj.CFBundleIdentifier, helperBundleIdentifier + '.NP', 'CFBundleName should reflect opts["helper-bundle-id"], opts["app-bundle-id"] or fallback to default in helper NP app')
t.equal(typeof obj.CFBundleName, 'string', 'CFBundleName should be a string in helper NP app')
t.equal(typeof obj.CFBundleDisplayName, 'string', 'CFBundleDisplayName should be a string in helper NP app')
t.equal(typeof obj.CFBundleExecutable, 'string', 'CFBundleExecutable should be a string in helper NP app')
t.equal(typeof obj.CFBundleIdentifier, 'string', 'CFBundleIdentifier should be a string in helper NP app')
t.equal(/^[a-zA-Z0-9-.]*$/.test(obj.CFBundleIdentifier), true, 'CFBundleIdentifier should allow only alphanumeric (A-Z,a-z,0-9), hyphen (-), and period (.)')
cb()
}
], function (err) {
t.end(err)
})
}
}
function createAppHumanReadableCopyrightTest (baseOpts, humanReadableCopyright) {
return function (t) {
t.timeoutAfter(config.timeout)
var plistPath
var opts = Object.create(baseOpts)
opts['app-copyright'] = humanReadableCopyright
waterfall([
function (cb) {
packager(opts, cb)
}, function (paths, cb) {
plistPath = path.join(paths[0], opts.name + '.app', 'Contents', 'Info.plist')
fs.stat(plistPath, cb)
}, function (stats, cb) {
t.true(stats.isFile(), 'The expected Info.plist file should exist')
fs.readFile(plistPath, 'utf8', cb)
}, function (file, cb) {
var obj = plist.parse(file)
t.equal(obj.NSHumanReadableCopyright, opts['app-copyright'], 'NSHumanReadableCopyright should reflect opts["app-copyright"]')
cb()
}
], function (err) {
t.end(err)
})
}
}
// Share testing script with platform darwin and mas
module.exports = function (baseOpts) {
util.setup()
test('helper app paths test', function (t) {
t.timeoutAfter(config.timeout)
function getHelperExecutablePath (helperName) {
return path.join(helperName + '.app', 'Contents', 'MacOS', helperName)
}
var opts = Object.create(baseOpts)
var frameworksPath
waterfall([
function (cb) {
packager(opts, cb)
}, function (paths, cb) {
frameworksPath = path.join(paths[0], opts.name + '.app', 'Contents', 'Frameworks')
// main Helper.app is already tested in basic test suite; test its executable and the other helpers
fs.stat(path.join(frameworksPath, getHelperExecutablePath(opts.name + ' Helper')), cb)
}, function (stats, cb) {
t.true(stats.isFile(), 'The Helper.app executable should reflect opts.name')
fs.stat(path.join(frameworksPath, opts.name + ' Helper EH.app'), cb)
}, function (stats, cb) {
t.true(stats.isDirectory(), 'The Helper EH.app should reflect opts.name')
fs.stat(path.join(frameworksPath, getHelperExecutablePath(opts.name + ' Helper EH')), cb)
}, function (stats, cb) {
t.true(stats.isFile(), 'The Helper EH.app executable should reflect opts.name')
fs.stat(path.join(frameworksPath, opts.name + ' Helper NP.app'), cb)
}, function (stats, cb) {
t.true(stats.isDirectory(), 'The Helper NP.app should reflect opts.name')
fs.stat(path.join(frameworksPath, getHelperExecutablePath(opts.name + ' Helper NP')), cb)
}, function (stats, cb) {
t.true(stats.isFile(), 'The Helper NP.app executable should reflect opts.name')
cb()
}
], function (err) {
t.end(err)
})
})
util.teardown()
var iconBase = path.join(__dirname, 'fixtures', 'monochrome')
var icnsPath = iconBase + '.icns'
util.setup()
test('icon test: .icns specified', createIconTest(baseOpts, icnsPath, icnsPath))
util.teardown()
util.setup()
test('icon test: .ico specified (should replace with .icns)', createIconTest(baseOpts, iconBase + '.ico', icnsPath))
util.teardown()
util.setup()
test('icon test: basename only (should add .icns)', createIconTest(baseOpts, iconBase, icnsPath))
util.teardown()
util.setup()
test('codesign test', function (t) {
t.timeoutAfter(config.timeout)
var opts = Object.create(baseOpts)
opts.sign = true // Ad-hoc
var appPath
waterfall([
function (cb) {
packager(opts, cb)
}, function (paths, cb) {
appPath = path.join(paths[0], opts.name + '.app')
fs.stat(appPath, cb)
}, function (stats, cb) {
t.true(stats.isDirectory(), 'The expected .app directory should exist')
exec('codesign -v ' + appPath, cb)
}, function (stdout, stderr, cb) {
t.pass('codesign should verify successfully')
cb()
}
], function (err) {
var notFound = err && err.code === 127
if (notFound) console.log('codesign not installed; skipped')
t.end(notFound ? null : err)
})
})
util.teardown()
util.setup()
test('app and build version test', createAppVersionTest(baseOpts, '1.1.0', '1.1.0.1234'))
util.teardown()
util.setup()
test('app version test', createAppVersionTest(baseOpts, '1.1.0'))
util.teardown()
util.setup()
test('app and build version integer test', createAppVersionTest(baseOpts, 12, 1234))
util.teardown()
util.setup()
test('app categoryType test', createAppCategoryTypeTest(baseOpts, 'public.app-category.developer-tools'))
util.teardown()
util.setup()
test('app bundle test', createAppBundleTest(baseOpts, 'com.electron.basetest'))
util.teardown()
util.setup()
test('app bundle (w/ special characters) test', createAppBundleTest(baseOpts, 'com.electron."bãśè tëßt!@#$%^&*()?\''))
util.teardown()
util.setup()
test('app bundle app-bundle-id fallback test', createAppBundleTest(baseOpts))
util.teardown()
util.setup()
test('app helpers bundle test', createAppHelpersBundleTest(baseOpts, 'com.electron.basetest.helper'))
util.teardown()
util.setup()
test('app helpers bundle (w/ special characters) test', createAppHelpersBundleTest(baseOpts, 'com.electron."bãśè tëßt!@#$%^&*()?\'.hęłpėr'))
util.teardown()
util.setup()
test('app helpers bundle helper-bundle-id fallback to app-bundle-id test', createAppHelpersBundleTest(baseOpts, null, 'com.electron.basetest'))
util.teardown()
util.setup()
test('app helpers bundle helper-bundle-id fallback to app-bundle-id (w/ special characters) test', createAppHelpersBundleTest(baseOpts, null, 'com.electron."bãśè tëßt!!@#$%^&*()?\''))
util.teardown()
util.setup()
test('app helpers bundle helper-bundle-id & app-bundle-id fallback test', createAppHelpersBundleTest(baseOpts))
util.teardown()
util.setup()
test('app humanReadableCopyright test', createAppHumanReadableCopyrightTest(baseOpts, 'Copyright © 2003–2015 Organization. All rights reserved.'))
util.teardown()
}