forked from GeopJr/SveltePress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateSymlinks.js
47 lines (41 loc) · 1.46 KB
/
generateSymlinks.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
import { symlinkSync, existsSync } from 'fs';
import { resolve, join, dirname, sep } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const paths = {
'sveltePress.config.js': './src/lib/SveltePress/sveltePress.config.js',
'gui/Flutter/assets': '../../static/',
'gui/QT/assets': '../../static/',
'gui/GTK/assets': '../../static/'
};
export function createSymLinks(win = process.platform === 'win32') {
Object.keys(paths).forEach((key) => {
paths[resolve(join(__dirname, key))] = paths[key];
delete paths[key];
});
for (const dest of Object.keys(paths)) {
const target = paths[dest];
const isFolder = target.endsWith('/');
if (isFolder && !existsSync(dest.split(sep).slice(0, -1).join(sep))) continue;
try {
symlinkSync(target, dest, isFolder ? 'dir' : 'file');
} catch (e) {
if (e.code === 'EPERM' && win) {
console.log('\x1b[31m%s\x1b[0m', `Windows requires Admin to make symlinks`);
console.log(
'\x1b[31m%s\x1b[0m',
`Please run 'node generateSymlinks.js' on a terminal with Admin Privileges from your SveltePress project root`
);
// Removed because admin requires a password (blank doesnt work)
// execSync(
// 'runas /user:Administrator "node generateSymlinks.js"',
// { stdio: 'inherit' }
// );
process.exit(1);
} else if (e.code === 'EEXIST') {
console.log(`Symlink '${dest}' already exists, skipped.`);
}
}
}
}
createSymLinks();