-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstar.js
51 lines (39 loc) · 1.36 KB
/
star.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
/* eslint-disable import/no-commonjs */
const path = require("path");
const util = require("util");
const fs = require("fs");
const copyFile = util.promisify(require("fs").copyFile);
const moveFile = util.promisify(require("fs").rename);
async function starExec(filename, folder) {
const exec = util.promisify(require("child_process").exec);
let starBinary = "star";
if (process.platform === "linux") {
starBinary = path.join(folder, "star");
} else if (process.platform === "win32") {
starBinary = path.join(folder, "star.exe");
}
starBinary = "\"" + starBinary + "\"";
const { stdout, stderr } = await exec(
starBinary + " -f " + folder + "/" + filename + " extract"
);
if (stderr) {
console.error(`stderr: ${stderr}`);
return;
}
return stdout;
}
async function copyStarBinary(destination) {
let starBinary = "star";
if (process.platform === "linux") {
starBinary = path.resolve("linux", "star");
destination = destination + "/" + starBinary.split("/").pop();
} else if (process.platform === "win32") {
starBinary = path.resolve("windows", "star.exe");
destination = destination + "\\" + starBinary.split("\\").pop();
}
await copyFile(starBinary, destination);
}
async function moveStarFiles(oldPath, newPath) {
await moveFile(oldPath, newPath);
}
module.exports = { starExec, copyStarBinary, moveStarFiles };