-
Notifications
You must be signed in to change notification settings - Fork 1
/
prep.js
55 lines (45 loc) · 1.1 KB
/
prep.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
const fs = require("fs");
const mkdirp = require("mkdirp");
const bundleDir = "bundles/Bundle";
const saveDir = "bundles/submit";
const saveBundle = (bundle, id) => {
mkdirp(saveDir, err => {
const filename = `Bundle.${id}.submit.json`;
fs.writeFile(
`${saveDir}/${filename}`,
JSON.stringify(bundle, null, 2),
err => {
if (err) throw err;
console.log(`Wrote: ${saveDir}/${filename}`);
}
);
});
};
const prepBundle = bundle => {
const submitBundle = {
resourceType: "Bundle",
type: "batch"
};
submitBundle.entry = bundle.entry.map(entry => {
return {
request: {
method: "PUT",
url: `${entry.resource.resourceType}/${entry.resource.id}`
},
resource: entry.resource
};
});
saveBundle(submitBundle, bundle.id);
};
const prep = () => {
fs.readdir(bundleDir, function(err, items) {
items.forEach(item => {
fs.readFile(`${bundleDir}/${item}`, (err, data) => {
if (err) throw err;
const bundle = JSON.parse(data);
prepBundle(bundle);
});
});
});
};
prep();