-
Notifications
You must be signed in to change notification settings - Fork 21
/
generate-manifest.js
55 lines (48 loc) · 1.51 KB
/
generate-manifest.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 path = require("path");
const languages = ["r", "python", "node.js", "dotnet/csharp", "dotnet/fsharp", "dotnet/powershell", "julia"];
async function getExamples() {
// Look within each directory our manifest needs
const manifest = await Promise.all(
// Loop vera ll keys (languages) within manifesst
languages.map(
language =>
// Create a promise we can await
new Promise((resolve, reject) => {
// Read the directory for that language
fs.readdir(language, (err, files) => {
if (err) {
// Failed, reject
reject(err);
return;
}
// Pass back all the files
resolve({
language: language,
// For each notebook, read it into memory
files: files.map(filename => {
const notebookPath = path.join(language, filename);
const content = JSON.parse(fs.readFileSync(notebookPath));
return {
path: notebookPath,
metadata: content.metadata
};
})
});
});
})
)
);
return new Promise((resolve, reject) => {
fs.writeFile("manifest.json", JSON.stringify(manifest, null, 2), err => {
if (err) {
reject(err);
return;
}
resolve();
});
});
}
getExamples()
.then(x => console.log("example notebooks manifest written"))
.catch(err => process.exit(1));