-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathpackager.js
63 lines (60 loc) · 1.82 KB
/
packager.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
var path = require('path')
var bozon = require('../bozon')
var Checker = require('../utils/checker')
var Builder = require('../building/builder')
var Packager = (function () {
function Packager (platform, environment) {
Checker.ensure()
this.name = require(path.join(process.cwd(), 'package.json')).name
this.version = require('../../package.json').versions['electron']
this.platform = platform
this.environment = environment
this.electronBuilder = bozon.requireLocal('electron-builder')
this.electronPackager = bozon.requireLocal('electron-packager-tf')
}
Packager.prototype.build = function () {
new Builder(this.platform, this.environment).run()
if (this.environment === 'test') {
return this.testBuild(this.platform)
} else {
return this.productionBuild(this.platform, this.environment)
}
}
Packager.prototype.testBuild = function (platform) {
var _this = this
var options = {
name: this.name,
version: this.version,
platform: process.platform,
arch: process.arch,
dir: path.join('builds', 'test'),
out: path.join('.tmp')
}
var promise = new Promise(function (resolve, reject) {
_this.electronPackager(options, function (err, appPaths) {
if (err) {
console.log(err)
reject()
} else {
resolve()
}
})
})
return promise
}
Packager.prototype.productionBuild = function (platform, environment) {
return this.electronBuilder.build({
targets: this.electronBuilder.Platform[platform.toUpperCase()].createTarget(),
devMetadata: {
directories: {
app: path.join('builds', environment),
buildResources: 'resources',
output: 'packages'
}
}
})
}
return Packager
}
)()
module.exports = Packager