Skip to content

Commit dce81f2

Browse files
committed
feat: Implement symlink creation command with error handling and path validation
1 parent e8747e8 commit dce81f2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/commands/symlink-crm.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
module.exports = async function (repos, args) {
5+
try {
6+
if (args.length < 2) {
7+
console.error("Please provide both source and destination paths.");
8+
return;
9+
}
10+
11+
const srcPath = path.resolve(process.cwd(), args[0]);
12+
const destPath = path.resolve(process.cwd(), args[1]);
13+
14+
if (!fs.existsSync(srcPath)) {
15+
console.error(`Source path does not exist: ${srcPath}`);
16+
return;
17+
}
18+
19+
try {
20+
// Always remove the destination entry if it exists
21+
if (fs.existsSync(destPath)) {
22+
await fs.promises.rm(destPath, { recursive: true, force: true });
23+
}
24+
25+
// Create a symlink for the directory
26+
await fs.promises.symlink(srcPath, destPath, "dir");
27+
console.log(`Directory symlink created: ${srcPath} -> ${destPath}`);
28+
} catch (err) {
29+
console.error(`Failed to create symlink for ${srcPath}:`, err);
30+
}
31+
32+
console.log("Symlinking complete.");
33+
} catch (err) {
34+
console.error("Error during symlinking process:", err);
35+
}
36+
};

0 commit comments

Comments
 (0)