-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
26 lines (22 loc) · 898 Bytes
/
main.js
File metadata and controls
26 lines (22 loc) · 898 Bytes
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
#!/usr/bin/env node
import {glob} from 'glob';
import {dirname, join, normalize} from 'path';
import {fileURLToPath} from 'url';
import {availableParallelism, DynamicThreadPool} from 'poolifier';
const workerPath = normalize(join(dirname(fileURLToPath(import.meta.url)), 'worker.js'));
const pool = new DynamicThreadPool(Math.floor(availableParallelism() / 2), availableParallelism(), workerPath, {
errorHandler: error => console.error('worker has error', error),
});
const targetDir = process.argv[2] ?? '.';
const files = await glob(`${targetDir}/**/*.{ts,js}`);
const poolRequests = files.map(path => pool.execute(join(process.cwd(), path)));
Promise.all(poolRequests)
.then(data => JSON.stringify(data, undefined, 2))
.then(data => {
console.log(data);
process.exit(0);
})
.catch(error => {
console.error(error);
process.exit(1);
});