forked from Nexus-Mods/Vortex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallAssets.mjs
More file actions
57 lines (44 loc) · 1.44 KB
/
InstallAssets.mjs
File metadata and controls
57 lines (44 loc) · 1.44 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
import { glob } from "glob";
import { mkdir, cp } from "node:fs/promises";
import { join, dirname, basename } from "node:path";
import data from "./InstallAssets.json" with { type: "json" };
/** @type (import("glob").GlobOptionsWithFileTypesUnset) */
const globOptions = { matchBase: true, globstar: true };
if (process.argv.length < 3) {
process.exit(1);
}
const tgt = process.argv[2];
let copies = -1;
try {
const promises = data.copy.map(async (file) => {
if (file.target.indexOf(basename(tgt)) === -1) {
return;
}
const files = await glob(file.srcPath, globOptions);
copies = copies === -1 ? files.length : (copies += files.length);
const filePromises = files.map(async (globResult) => {
let globTarget = join(
...globResult.split(/[\/\\]/).slice(file.skipPaths),
);
if (file.rename) {
globTarget = join(dirname(globTarget), file.rename);
}
const targetFile = join(tgt, file.outPath, globTarget);
try {
await mkdir(dirname(targetFile), { recursive: true });
await cp(globResult, targetFile, { recursive: true });
console.log("copied", globResult, targetFile);
} catch (err) {
console.log("failed to copy", globResult, targetFile, err);
} finally {
--copies;
}
});
await Promise.all(filePromises);
});
await Promise.all(promises);
} catch (err) {
console.error(err);
} finally {
console.log("done");
}