-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-symlink.js
More file actions
28 lines (26 loc) · 1 KB
/
setup-symlink.js
File metadata and controls
28 lines (26 loc) · 1 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
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const sourceEnvPath = path.resolve(__dirname, './.env'); // Root-level .env file
const targetEnvPath = path.resolve(__dirname, './apps/backend/.env'); // Backend .env file
// Check if symlink already exists
if (fs.existsSync(targetEnvPath)) {
if (fs.lstatSync(targetEnvPath).isSymbolicLink()) {
console.log(`Symlink already exists: ${targetEnvPath}`);
} else {
console.log(`A file or folder exists at ${targetEnvPath}, cannot create symlink.`);
}
} else {
// Create symlink
try {
if (process.platform === 'win32') {
execSync(`mklink "${targetEnvPath}" "${sourceEnvPath}"`, { stdio: 'inherit' });
console.log('Symlink created on Windows');
} else {
execSync(`ln -s "${sourceEnvPath}" "${targetEnvPath}"`, { stdio: 'inherit' });
console.log('Symlink created on Unix-like system');
}
} catch (err) {
console.error('Error creating symlink:', err.message);
}
}