-
Notifications
You must be signed in to change notification settings - Fork 0
/
link.js
56 lines (48 loc) · 1.08 KB
/
link.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
54
55
56
const fs = require("fs");
const path = require("path");
const rawPath = process.argv[2];
if(!rawPath) {
console.log("Usage: npm run link <path_to_project>");
return;
}
const appPath = path.resolve(rawPath);
const nodeModules = path.join(appPath, "node_modules");
const reactClarity = path.join(nodeModules, "react-clarity");
try {
fs.mkdirSync(nodeModules);
} catch (e) {
if(e.code === "ENOENT") {
console.log(`Couldn't find directory: ${nodeModules}!`);
return -1;
}
if(e.code !== "EEXIST") {
console.log(e);
return -1;
}
}
try {
fs.mkdirSync(nodeModules);
} catch (e) {
if(e.code === "ENOENT") {
console.log(`Couldn't find directory: ${nodeModules}!`);
return -1;
}
if(e.code !== "EEXIST") {
console.log(e);
return -1;
}
}
try {
fs.unlinkSync(reactClarity);
} catch (e) {
if(e.code !== "ENOENT") {
console.log(e);
return -1;
}
}
try {
fs.symlinkSync(path.resolve(""), reactClarity);
} catch (e) {
if(e.code !== "EEXIST")
console.log(e);
}