-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgen.cjs
39 lines (35 loc) · 1.05 KB
/
gen.cjs
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
const fs = require("fs");
const { join } = require("path");
const constants = {
WEBCOMPONENTS_DIR: join(".", "webcomponents"),
};
const webcomponents = {};
fs.readdirSync(constants.WEBCOMPONENTS_DIR, { withFileTypes: true })
.filter((dir) => dir.isDirectory())
.forEach((folder) => {
console.log("folder", folder);
const fileNames = fs.readdirSync(
join(constants.WEBCOMPONENTS_DIR, folder.name)
);
fileNames.forEach((fileName) => {
const dashspilt = fileName.split("-");
const prefix = dashspilt[0];
const dotSplit = dashspilt[1].split(".");
const componentName = dotSplit[0];
if (!webcomponents[prefix]) {
webcomponents[prefix] = [];
}
webcomponents[prefix].push({
componentName,
filePath: join(
constants.WEBCOMPONENTS_DIR,
folder.name,
prefix + "-" + componentName + ".html"
),
});
});
});
fs.writeFileSync(
join(constants.WEBCOMPONENTS_DIR, "index.js"),
`export const webcomponents=${JSON.stringify(webcomponents)};`
);