-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ts
More file actions
114 lines (97 loc) · 3.34 KB
/
setup.ts
File metadata and controls
114 lines (97 loc) · 3.34 KB
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
105
106
107
108
109
110
111
112
113
114
import { execSync, ExecSyncOptionsWithBufferEncoding } from "child_process";
import path from "path";
import fs from "fs";
const ROOT_DIR = path.resolve(__dirname);
const BUILD_DIR = path.join(ROOT_DIR, "build");
const TASK_TAGS_FILE = path.join(BUILD_DIR, ".task-tags.json");
const EMSDK_DIR = path.join(BUILD_DIR, "emsdk");
const EMSDK_VERSION = "4.0.15";
const OCCT_DIR = path.join(BUILD_DIR, "occt");
function execAsync(command: string, options?: ExecSyncOptionsWithBufferEncoding): Promise<void> {
return new Promise((resolve, reject) => {
try {
execSync(command, options);
resolve();
} catch (error) {
reject(error);
}
});
}
interface InstallTask {
key: string;
name: string;
repository: string;
tag: string;
targetDir: string;
commands: string[];
}
const tasks: InstallTask[] = [
{
key: "emsdk",
name: "emsdk",
repository: "https://github.com/emscripten-core/emsdk.git",
tag: EMSDK_VERSION,
targetDir: EMSDK_DIR,
commands: [
`${EMSDK_DIR}/emsdk install ${EMSDK_VERSION}`,
`${EMSDK_DIR}/emsdk activate --embedded ${EMSDK_VERSION}`,
]
},
{
key: "occt",
name: "Open CASCADE Technology",
repository: "https://github.com/Open-Cascade-SAS/OCCT.git",
tag: "V7_9_3",
targetDir: OCCT_DIR,
commands: []
}
];
function readTaskTags(): Record<string, string> {
if (!fs.existsSync(TASK_TAGS_FILE)) {
return {};
}
try {
const raw = fs.readFileSync(TASK_TAGS_FILE, "utf8");
const parsed = JSON.parse(raw) as unknown;
if (parsed !== null && typeof parsed === "object") {
return parsed as Record<string, string>;
}
} catch {
// If the file is malformed, ignore it and regenerate.
}
return {};
}
function writeTaskTags(taskTags: Record<string, string>): void {
fs.writeFileSync(TASK_TAGS_FILE, JSON.stringify(taskTags, null, 2));
}
async function run(): Promise<void> {
fs.mkdirSync(BUILD_DIR, { recursive: true });
const taskTags = readTaskTags();
for (const task of tasks) {
const savedTag = taskTags[task.key];
if (fs.existsSync(task.targetDir)) {
if (savedTag === undefined) {
console.log(`No saved tag for ${task.name}. Deleting existing directory to ensure clean setup.`);
fs.rmSync(task.targetDir, { recursive: true, force: true });
} else if (savedTag !== task.tag) {
console.log(`Tag changed for ${task.name}: ${savedTag} -> ${task.tag}. Reinstalling...`);
fs.rmSync(task.targetDir, { recursive: true, force: true });
}
}
if (!fs.existsSync(task.targetDir)) {
console.log(`Cloning ${task.name}...`);
await execAsync(`git clone --depth 1 --branch ${task.tag} ${task.repository} ${task.targetDir}`);
}
for (const command of task.commands) {
console.log(`Running command for ${task.name}: ${command}`);
await execAsync(command, { stdio: "inherit" });
}
taskTags[task.key] = task.tag;
console.log(`${task.name} setup completed.`);
}
writeTaskTags(taskTags);
}
run().catch(error => {
console.error("Setup failed:", error);
process.exit(1);
});