-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (38 loc) · 1.45 KB
/
index.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
/* eslint-disable no-nested-ternary */
const fs = require('fs');
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const { unpack } = require('./src/scShader');
const { argv } = yargs(hideBin(process.argv));
const main = async () => {
const startTime = new Date().getTime();
const promises = [];
const filesToExtract = !argv.file ? [] : (Array.isArray(argv.file) ? argv.file : [argv.file]);
const folders = !argv.folder ? [] : (Array.isArray(argv.folder) ? argv.folder : [argv.folder]);
folders.forEach((folder) => {
const scFiles = fs.readdirSync(folder);
scFiles.forEach((scFile) => {
filesToExtract.push(`${folder}/${scFile}`);
});
});
if (fs.existsSync('out')) {
fs.rmSync('out', { recursive: true });
}
if (fs.existsSync('temp')) {
fs.rmSync('temp', { recursive: true });
}
filesToExtract.forEach((scFile) => {
const lastSlash = scFile.lastIndexOf('/');
fs.mkdirSync(`out/${scFile.substring(0, lastSlash)}/${scFile.substring(lastSlash + 1)}`, { recursive: true });
fs.mkdirSync(`temp/${scFile.substring(0, lastSlash)}/${scFile.substring(lastSlash + 1)}`, { recursive: true });
promises.push(unpack(scFile));
});
const results = await Promise.allSettled(promises);
results.forEach((result) => {
if (result.status === 'rejected') {
console.error(result.reason);
}
});
console.log(`Unpack time - ${new Date().getTime() - startTime}ms`);
};
main();