-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.js
More file actions
executable file
·119 lines (97 loc) · 2.94 KB
/
release.js
File metadata and controls
executable file
·119 lines (97 loc) · 2.94 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
#!/usr/bin/env node
const Releaser = require('./lib/releaser')
const path = require('path')
const fs = require('fs')
const replicator = require('@hyperswarm/replicator')
if (!process.argv[2]) {
const a = new Releaser('./hyperupdate/darwin')
const b = new Releaser('./hyperupdate/linux')
const c = new Releaser('./hyperupdate/win32')
a.ready(function () {
b.ready(function () {
c.ready(function () {
console.log('Hyperupdate release config:')
console.log({
darwin: a.key.toString('hex'),
linux: b.key.toString('hex'),
win32: c.key.toString('hex')
})
})
})
})
return
}
const dist = process.argv[2]
const dirs = fs.readdirSync(dist)
const platforms = []
if (dirs.includes('mac')) {
const app = firstApp(path.join(dist, 'mac'))
if (app) platforms.push(parse(app))
}
if (dirs.includes('linux-unpacked')) platforms.push(parse(path.join(dist, 'linux-unpacked')))
if (dirs.includes('win-unpacked')) platforms.push(parse(path.join(dist, 'win-unpacked')))
if (!dirs.length) platforms.push(parse(dist))
loop()
function loop () {
if (!platforms.length) return
release(platforms.shift(), loop)
}
function firstApp (dir) {
const all = fs.readdirSync(dir)
for (const app of all) {
if (app.endsWith('.app')) return path.join(dir, app)
}
return null
}
function release ({ platform, version, folder }, cb) {
const r = new Releaser('./hyperupdate/' + platform)
const prefix = '[' + platform + ']'
console.log(prefix, 'Releasing ' + folder)
r.ready(function () {
console.log(prefix, 'Hyperupdate key: ' + r.key.toString('hex'))
console.log(prefix, 'Adding release....')
r.getLatestReleaseInfo(function (err, release) {
if (err) throw err
if (release && release.version === version) return done(null, null)
r.addRelease(folder, { version }, done)
function done (err, newRelease) {
if (err) throw err
if (newRelease) console.log(prefix, 'Added release', newRelease)
else console.log(prefix, 'Release already added...', release)
console.log(prefix, 'Swarming...')
replicator(r, {
announceLocalAddress: true,
lookup: true,
announce: true
})
if (cb) cb()
}
})
})
}
function parse (folder) {
const dir = path.basename(folder)
const parent = path.basename(path.dirname(folder))
if (parent === 'mac') {
return {
platform: 'darwin',
version: require(path.resolve(folder, '../../../package.json')).version,
folder
}
}
if (dir === 'linux-unpacked') {
return {
platform: 'linux',
version: require(path.resolve(folder, '../../package.json')).version,
folder
}
}
if (dir === 'win-unpacked') {
return {
platform: 'win32',
version: require(path.resolve(folder, '../../package.json')).version,
folder
}
}
throw new Error('Unsupported dist. Use the unpacked folder or .app file.')
}