-
Notifications
You must be signed in to change notification settings - Fork 1
/
symlink.js
28 lines (26 loc) · 910 Bytes
/
symlink.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
const fs = require("fs");
const {join} = require("path");
const pkg = require("./package.json");
(function createSymlink() {
const v = pkg.version.split(".")[0];
const nodeModulesPath = join(__dirname, "node_modules");
const targetPath = join("_node_modules", "node_modules_" + v);
if (fs.existsSync(nodeModulesPath)) {
fs.unlinkSync(nodeModulesPath);
}
if (!fs.existsSync(targetPath)) {
console.info("Target folder doesn't exist, stop before creating new symlink");
return;
}
fs.symlink(join(__dirname, targetPath), nodeModulesPath, "dir", (err) => {
if (err) {
console.log(err);
}
else {
console.log(`Symlink created: /node_modules => /${targetPath}`);
console.log("Symlink is a directory:",
fs.statSync(nodeModulesPath).isDirectory()
);
}
});
})();