-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_render.js
More file actions
50 lines (40 loc) · 1.29 KB
/
batch_render.js
File metadata and controls
50 lines (40 loc) · 1.29 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
// batch_render.js
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
// --- 1. Get directory from CLI (default: ./graphs) ---
const dir = process.argv[2] || path.join(__dirname, 'graphs');
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
console.error('Not a directory:', dir);
process.exit(1);
}
const files = fs.readdirSync(dir)
.filter(f => f.toLowerCase().endsWith('.json'))
.map(f => path.join(dir, f));
if (files.length === 0) {
console.log('No .json files found in', dir);
process.exit(0);
}
console.log(`Found ${files.length} JSON graph file(s) in ${dir}`);
console.log('Rendering...\n');
// --- 2. Render each file by calling render_contact_network.js ---
function renderFile(idx) {
if (idx >= files.length) {
console.log('\nAll renders done.');
return;
}
const file = files[idx];
console.log(`(${idx + 1}/${files.length}) Rendering: ${file}`);
const child = spawn('node', [path.join(__dirname, 'render_contact_network.js'), file], {
stdio: 'inherit'
});
child.on('exit', (code) => {
if (code !== 0) {
console.error(`render_contact_network.js exited with code ${code} for file ${file}`);
}
// move on to next file
renderFile(idx + 1);
});
}
// start the chain
renderFile(0);