-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildToc.mjs
104 lines (92 loc) · 2.25 KB
/
buildToc.mjs
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
94
95
96
97
98
99
100
101
102
103
104
import { join } from "path";
import { readdir, stat, writeFile } from "fs/promises";
const __dirname = join(new URL(".", import.meta.url).pathname, "docs");
const files = await getJSON(__dirname);
await writeFile(
join(__dirname, "full.json"),
JSON.stringify(files, undefined, 2)
);
await writeFile(
join(__dirname, "jdx.json"),
JSON.stringify(
files.filter((file) => file.relativePath.includes("/format/jdx/")),
undefined,
2
)
);
await writeFile(
join(__dirname, "biologic.json"),
JSON.stringify(
files.filter((file) => file.relativePath.includes("/format/biologic/")),
undefined,
2
)
);
await writeFile(
join(__dirname, "bigmap.json"),
JSON.stringify(
files.filter((file) => file.relativePath.includes("/format/biologic/jdb")),
undefined,
2
)
);
await writeFile(
join(__dirname, "uvvis.json"),
JSON.stringify(
files.filter((file) => file.relativePath.includes("/cary500")),
undefined,
2
)
);
await writeFile(
join(__dirname, "hplc.json"),
JSON.stringify(
files.filter((file) => file.relativePath.includes("/agilent-hplc")),
undefined,
2
)
);
await writeFile(
join(__dirname, "gcms.json"),
JSON.stringify(
files.filter((file) => file.relativePath.includes("/agilent-gcms")),
undefined,
2
)
);
await writeFile(
join(__dirname, "mass.json"),
JSON.stringify(
files.filter((file) => file.relativePath.includes("/measurement/mass")),
undefined,
2
)
);
async function getJSON(basedir) {
let files = [];
await appendFiles(files, basedir, "data");
files.forEach((file) => {
file.relativePath = file.relativePath.replace(/.*__tests__\//, "");
});
return files;
}
async function appendFiles(files, basedir, currentDir) {
const entries = (await readdir(join(basedir, currentDir))).filter(
(entry) => !entry.startsWith(".")
);
for (let entry of entries) {
const current = join(currentDir, entry);
const currentPath = join(basedir, current);
const info = await stat(currentPath);
if (info.isDirectory()) {
await appendFiles(files, basedir, current);
} else {
files.push({
name: entry,
size: info.size,
relativePath: current,
lastModified: Math.round(info.mtimeMs),
});
}
}
}