-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmappings.js
94 lines (83 loc) · 1.96 KB
/
mappings.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
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
/**
* creates the mapping databases
*/
const http = require('http');
const fs = require('fs')
let series_file = process.argv[2];
let host = process.argv[3]
let inputdata = fs.readFileSync(process.argv[2]);
let info = JSON.parse(inputdata);
//const auth = "admin:1qaz@WSX"
function recreate(db, document, data) {
let sets = http.request(
{
method:"DELETE", host, port:5984, path:`/${db}`
},
res => {
let buffer = [];
res.on('data',data => buffer.push(data))
res.on('end',
_ => {
console.log(`deleted ${db} with ${buffer.join('')}`)
let create = http.request(
{
method:"PUT", host, port:5984, path:`/${db}`
},
res => {
buffer = []
res.on('data', data => buffer.push(data))
res.on('end',
_ => {
console.log(`created with ${buffer.join('')}`);
let sets = http.request(
{
method:"PUT",host,port:5984,path:`/${db}/${document}`
},
res => {
buffer =[];
res.on('data', data => buffer.push(data))
res.on('end',
_ => {
console.log(`finished writing ${db} with ${buffer.join('')}`)
})
})
sets.write(JSON.stringify(data))
sets.end()
})
})
create.write('');
create.end();
})
})
sets.write('')
sets.end('')
}
recreate('cardsets','sets', { sets:info.map( ({id,label}) => {
return {id,label}
}) })
recreate('cardmapping', 'mapping', {
mapping:info.map( ({prefix,id:db}) => {
let p = prefix;
if(typeof p === 'string') {
return {
prefix:prefix.replace('/','_').replace('-','_').toLowerCase(),
db
}
}
else {
return prefix.map(p => {
return {
prefix:p.replace('/','_').replace('-','_').toLowerCase(),
db
}
})
}
}).reduce( (acc, val) => {
if(val.length)
return acc.concat(val)
else {
acc.push(val)
return acc;
}
}, [])
})