-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopyplugin.js
53 lines (48 loc) · 1.48 KB
/
copyplugin.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
49
50
51
52
53
import { promises as fs } from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const VORTEX_PLUGINS = path.join(process.env.APPDATA, "Vortex", "Plugins");
//console.log("__dirname=" + __dirname);
//console.log("__filename=" + __filename);
async function removeOldPlugins(name) {
const entries = await (
await fs.readdir(VORTEX_PLUGINS)
).filter((entry) => entry.startsWith(name));
for (const entry of entries) {
const contents = await fs.readdir(path.join(VORTEX_PLUGINS, entry));
for (const content of contents) {
await fs.unlink(path.join(VORTEX_PLUGINS, entry, content));
}
await fs.rmdir(path.join(VORTEX_PLUGINS, entry));
}
}
async function start() {
const packageData = await fs.readFile(path.join(__dirname, "package.json"), {
encoding: "utf8"
});
try {
const data = JSON.parse(packageData);
const destination = path.join(
VORTEX_PLUGINS,
`${data.name}-${data.version}`
);
try {
await removeOldPlugins(data.name);
} catch (err) {
console.error(err);
}
const fileEntries = await fs.readdir(path.join(__dirname, "dist"));
await fs.mkdir(destination, { recursive: true });
for (const file of fileEntries) {
await fs.copyFile(
path.join(__dirname, "dist", file),
path.join(destination, file)
);
}
} catch (err) {
console.error(err);
}
}
start();