-
Notifications
You must be signed in to change notification settings - Fork 3
/
lock.js
68 lines (60 loc) · 1.66 KB
/
lock.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
'use strict'
const ops = require('./ops')
const sums = require('./sums')
const mvn = require('./mvn')
const GEN_BANNER = 'Generated by up.js --uplock, do not edit, manual edits will be overridden'
const LOCKFILE = '.up.lock.json'
function exists() {
return ops.exists(LOCKFILE)
}
function load() {
if (!exists()) {
throw `File '${LOCKFILE}' is not found, please restore it or regenerate by running with --uplock --lib`
}
let lockdata = JSON.parse(ops.read(LOCKFILE))
let libs = lockdata.libs.map(l => {
if ((l.options || {}).internal) {
return [l.target, [], l.options]
}
let jars = l.jars.map(toCoordsSavingChecksum(mvn.EXT.jar_sum, l.options))
l.srcs.forEach(toCoordsSavingChecksum(mvn.EXT.src_sum, l.options)) // cache only
return [l.target, jars, l.options]
})
return libs
function toCoordsSavingChecksum(ext, options) {
return j => {
let jar = mvn.coords(j.coords, options)
// this is not 'good' but it's the current design,
// we side-effectly fill checksum cache
sums.set(jar, ext, j.sha1)
return jar
}
}
}
function store(libs) {
let lockdata = {
note: GEN_BANNER,
libs: libs.map(l => ({
target: String(l.target),
options: l.options,
jars: l.options.internal ? [] : l.jars.map(outputJar),
srcs: l.options.internal ? [] : l.srcs.map(outputSrc),
}))
}
return ops.write(LOCKFILE, JSON.stringify(lockdata, null, 2))
function outputJar(j) {
return {
coords: String(j),
sha1: j.checksumJar
}
}
function outputSrc(j) {
return {
coords: String(j),
sha1: j.checksumSrc,
}
}
}
module.exports = {
exists, load, store
}