forked from SocketDotTech/socket-plugs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ts
52 lines (45 loc) · 1.36 KB
/
setup.ts
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
import { execSync } from "child_process";
import { existsSync, readFileSync, writeFileSync } from "fs";
import { join } from "path";
// Path to the script.ts file
const scriptPath = join(__dirname, "script", "script.ts");
const symlinkPath = "/usr/local/bin/socket";
function addShebang() {
console.log("setting up socket....");
const shebang = "#!/usr/bin/env ts-node\n";
const content = readFileSync(scriptPath, "utf8");
if (!content.startsWith(shebang)) {
writeFileSync(scriptPath, shebang + content);
console.log("Shebang added to script.ts");
} else {
console.log("Shebang already present in script.ts");
}
}
function makeExecutable() {
execSync(`chmod +x ${scriptPath}`);
console.log("script.ts made executable");
}
function createSymlink() {
if (existsSync(symlinkPath)) {
execSync(`rm ${symlinkPath}`);
}
execSync(`ln -s ${scriptPath} ${symlinkPath}`);
console.log(`Symbolic link created at ${symlinkPath}`);
}
function ensureTsNode() {
try {
execSync("ts-node -v", { stdio: "ignore" });
console.log("ts-node is already installed globally");
console.log("socket setup complete, socket command is now available");
} catch {
execSync("npm install -g ts-node");
console.log("ts-node installed globally");
}
}
function setup() {
addShebang();
makeExecutable();
createSymlink();
ensureTsNode();
}
setup();