-
-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathrun-cpd.js
More file actions
executable file
·61 lines (55 loc) · 1.48 KB
/
Copy pathrun-cpd.js
File metadata and controls
executable file
·61 lines (55 loc) · 1.48 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
58
59
60
61
#!/usr/bin/env node
"use strict";
const path = require("path");
const { spawnSync } = require("child_process");
const { getPlatformKey, PLATFORM_MAP } = require("./platform-map");
const key = getPlatformKey();
if (!key) {
console.error(
`cpd: Unsupported platform ${process.platform}/${process.arch}`
);
process.exit(1);
}
const entry = PLATFORM_MAP[key];
const binaryName = process.platform === "win32" ? "cpd.exe" : "cpd";
let binaryPath;
try {
const pkgJson = require.resolve(`${entry.packageName}/package.json`, {
paths: [path.resolve(__dirname, ".."), __dirname],
});
binaryPath = path.join(path.dirname(pkgJson), "cpd-bin", binaryName);
} catch {
const localBuild = path.join(
__dirname,
"target",
"release",
binaryName
);
const fs = require("fs");
if (fs.existsSync(localBuild)) {
binaryPath = localBuild;
} else {
console.error(
`cpd: Platform package "${entry.packageName}" not installed.` +
` Install it with: npm install ${entry.packageName}`
);
console.error(
"Alternatively, build from source: cargo build --release -p jscpd"
);
process.exit(1);
}
}
const result = spawnSync(binaryPath, process.argv.slice(2), {
stdio: "inherit",
});
if (result.error) {
if (result.error.code === "ENOENT") {
console.error(`cpd: binary not found: ${binaryPath}`);
process.exit(1);
}
throw result.error;
}
if (result.signal) {
process.kill(process.pid, result.signal);
}
process.exit(result.status ?? 0);