-
Notifications
You must be signed in to change notification settings - Fork 3
/
grab.js
51 lines (44 loc) · 1.36 KB
/
grab.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
'use strict'
const paths = require('path')
const mvn = require('./mvn')
const buck = require('./buck')
const syms = require('./syms')
const ops = require('./ops')
const byTarget = {}
const byPath = {}
const GEN_BANNER = '# generated by `node up --grab`, manual edits will be overridden'
// simple session-level (single cli execution) memoization of what have been generated
const wasGenerated = {}
function toBuckRule(g) {
return buck.ruleRemoteFile(g.target, g.coords, g.type, g.ext, g.ext + mvn.EXT.sum)
}
module.exports = {
stage(target, coords, options) {
options = options || {}
target = buck.target(target)
coords = mvn.coords(coords, options)
let ext = options.ext || paths.extname(target.goal) || mvn.EXT.jar
let type = options.type || 'data'
let key = String(target)
let grabee = byTarget[key] || (byTarget[key] = {
target, coords, options, ext, type
})
;(byPath[target.path] || (byPath[target.path] = [])).push(grabee)
},
genBuckfiles() {
for (let p in byPath) this.genBuckfile(p)
},
genBuckfile(path) {
if (path in wasGenerated) return
let content = [
GEN_BANNER,
...(byPath[path] || []).map(toBuckRule)
].join('\n')
ops.write(paths.join(path, 'BUCK'), content)
wasGenerated[path] = true
},
get(target) {
let r = buck.info(target)[0]
return r && syms.outputOf(r)
}
}