-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
53 lines (42 loc) · 1.57 KB
/
build.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
// Take all files in "cases/" and its subdirectories
// and create "dist/cases.json" with { "relative/path/to/file.scad": content }
const fs = require("fs");
const path = require("path");
const models = {};
const dir = path.join(__dirname, "cases");
function readDirRecursively(directory, relativePath = "") {
const entries = fs.readdirSync(directory, { withFileTypes: true });
for (const entry of entries) {
if (entry.name.startsWith(".")) {
// Skip hidden files and directories
continue;
}
const fullPath = path.join(directory, entry.name);
const relativeFilePath = path.join(relativePath, entry.name);
if (entry.isDirectory()) {
// Recursively read subdirectories
readDirRecursively(fullPath, relativeFilePath);
} else if (entry.isFile()) {
// Read and store file content
models[relativeFilePath] = fs.readFileSync(fullPath, "utf-8");
}
}
}
readDirRecursively(dir);
// Ensure the "dist" directory exists
fs.mkdirSync(path.join(__dirname, "dist"), { recursive: true });
// Write models object to "models.json"
fs.writeFileSync(
path.join(__dirname, "dist", "cases.json"),
JSON.stringify(models, null, 2) // Pretty print JSON for easier readability
);
// openscad playground
const playgroundDir = path.join(__dirname, "..", "openscad-playground", "src");
// copy dist/cases.json to ../openscad-playground/src/cases.json
if (fs.existsSync(playgroundDir)) {
fs.copyFileSync(
path.join(__dirname, "dist", "cases.json"),
path.join(playgroundDir, "cases.json")
);
}
console.log("Cases have been built successfully!");