-
Notifications
You must be signed in to change notification settings - Fork 1
/
ldes_v2.js
54 lines (46 loc) · 1.64 KB
/
ldes_v2.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
const fs = require('fs');
exports.generateLDES = function (dir,baseUrl) {
console.log(`generating ldes for ${dir}...`);
fs.readdir(dir, (err,files) => {
if (err)
throw err;
files.forEach( (file) => {
const stats = fs.statSync(`${dir}/${file}`);
if (stats.isDirectory() && file.match(/^[A-Za-z0-9]/)) {
_generateLDES(`${dir}/${file}`,baseUrl);
}
});
});
}
function _generateLDES(dir,baseUrl) {
const subdir = dir.replace(/.*\//g,'');
const ldes = {
"@context" : {
"ldes" : "https://w3id.org/ldes#",
"tree" : "https://w3id.org/tree#",
"ldp" : "http://www.w3.org/ns/ldp#",
"dc" : "http://purl.org/dc/elements/1.1/",
"ov" : "http://open.vocab.org/terms/",
"tree:member": { "@container": "@list"}
} ,
"@id": `${baseUrl}/${subdir}/ldes.jsonld#EventStream`,
"@type": [ "ldes:EventStream" , "evt:EventLog" ],
"tree:member": []
};
fs.readdir(dir, (err,files) => {
if (err)
throw err
files.forEach( file => {
if (!file.match(/jsonld$/) || file == 'ldes.jsonld')
return;
const stats = fs.statSync(`${dir}/${file}`);
const modified = (new Date(stats.mtime)).toISOString();
ldes['tree:member'].push({
"@id": file,
"@type": [ "ldp:Resource" , "evt:Notification" ],
"dc:modified": modified
});
});
fs.writeFileSync(`${dir}/ldes.jsonld`,JSON.stringify(ldes,null,2));
});
}