forked from ethereum/solc-bin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update
executable file
·160 lines (138 loc) · 4.4 KB
/
update
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
#!/usr/bin/env node
'use strict'
const fs = require('fs')
const path = require('path')
const semver = require('semver')
const ethUtil = require('ethereumjs-util')
const swarmhash = require('swarmhash')
// This script updates the index files list.js and list.txt in the bin directory,
// as well as the soljson-latest.js files.
fs.readdir(path.join(__dirname, '/bin'), function (err, files) {
if (err) {
throw err
}
function buildVersion (build) {
var version = build.version
if (build.prerelease && build.prerelease.length > 0) {
version += '-' + build.prerelease
}
if (build.build && build.build.length > 0) {
version += '+' + build.build
}
return version
}
function readFile (file) {
return fs.readFileSync(path.join(__dirname, '/bin', file))
}
// ascending list (oldest version first)
const parsedList = files
.map(function (file) { return file.match(/^soljson-v([0-9.]*)(-([^+]*))?(\+(.*))?.js$/) })
.filter(function (version) { return version })
.map(function (pars) { return { path: pars[0], version: pars[1], prerelease: pars[3], build: pars[5] } })
.map(function (pars) {
const fileContent = readFile(pars.path)
pars.longVersion = buildVersion(pars)
pars.keccak256 = '0x' + ethUtil.sha3(fileContent).toString('hex')
pars.urls = [ 'bzzr://' + swarmhash(fileContent).toString('hex') ]
return pars
})
.sort(function (a, b) {
// NOTE: a vs. b (the order is important), because we want oldest first in the list
return semver.compare(a.longVersion, b.longVersion)
})
// descending list
const releases = parsedList
.slice().reverse()
.reduce(function (prev, next) {
if (next.prerelease === undefined) {
prev[next.version] = next.path
}
return prev
}, {})
// descending list
const buildNames = parsedList
.slice().reverse()
.map(function (ver) { return ver.path })
const latestRelease = parsedList
.slice().reverse()
.filter(function (version) {
if (version.prerelease === undefined) {
return version
}
})
.map(function (version) {
return version.version
})[0]
// latest build (nightly)
const latestBuildFile = buildNames[0]
// latest release
const latestReleaseFile = releases[latestRelease]
// Write bin/list.txt
// A descending list of file names.
fs.writeFile(path.join(__dirname, '/bin/list.txt'), buildNames.join('\n'), function (err) {
if (err) {
throw err
}
console.log('Updated bin/list.txt')
})
// Write bin/list.json
// Ascending list of builds and descending map of releases.
fs.writeFile(path.join(__dirname, '/bin/list.json'), JSON.stringify({ builds: parsedList, releases: releases, latestRelease: latestRelease }, null, 2), function (err) {
if (err) {
throw err
}
console.log('Updated bin/list.json')
})
// Write bin/list.js
// Descending list of build filenames and descending map of releases.
fs.writeFile(path.join(__dirname, '/bin/list.js'), generateLegacyListJS(buildNames, releases), function (err) {
if (err) {
throw err
}
console.log('Updated bin/list.js')
})
// Read latest release file
fs.readFile(path.join(__dirname, '/bin/', latestReleaseFile), function (err, data) {
if (err) {
throw err
}
// Copy to bin/soljson-latest.js
fs.writeFile(path.join(__dirname, '/bin/soljson-latest.js'), data, function (err) {
if (err) {
throw err
}
console.log('Updated bin/soljson-latest.js')
})
// Copy to soljson.js
fs.writeFile(path.join(__dirname, '/soljson.js'), data, function (err) {
if (err) {
throw err
}
console.log('Updated soljson.js')
})
})
// Read latest build file
fs.readFile(path.join(__dirname, '/bin/', latestBuildFile), function (err, data) {
if (err) {
throw err
}
// Copy to bin/soljson-nightly.js
fs.writeFile(path.join(__dirname, '/bin/soljson-nightly.js'), data, function (err) {
if (err) {
throw err
}
console.log('Updated bin/soljson-nightly.js')
})
})
})
function generateLegacyListJS (builds, releases) {
return `
var soljsonSources = ${JSON.stringify(builds, null, 2)};
var soljsonReleases = ${JSON.stringify(releases, null, 2)};
if (typeof(module) !== 'undefined')
module.exports = {
'allVersions': soljsonSources,
'releases': soljsonReleases
};
`
}