-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-symlinks.js
executable file
·106 lines (93 loc) · 2.5 KB
/
setup-symlinks.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import fs from 'node:fs';
import path, { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import process from 'node:process';
import { glob } from 'glob';
import task from 'tasuku';
const __dirname = dirname(fileURLToPath(import.meta.url));
const HANDLED_INDIVIDUALLY = ['starship.toml'];
const ignore = [
'node_modules/**',
'scripts/**',
'zsh/**',
'LICENSE',
'package.json',
'pnpm-lock.yaml',
'prettier.config.js',
'setup-symlinks.js',
'README.md',
...HANDLED_INDIVIDUALLY,
];
const createSymlink = (entry, target, type) => {
if (fs.existsSync(target)) {
fs.unlinkSync(target);
}
fs.symlinkSync(entry, target, type);
};
const { result: dotfiles } = await task(
'Grouping dotfiles',
async ({ setStatus }) => {
const dotfiles = {
home: {
entries: await glob('*', {
ignore,
absolute: true,
nodir: true,
}),
target: path.resolve(process.env.HOME, '.'),
},
binaries: {
entries: await glob('bin/*', {
ignore,
absolute: true,
nodir: true,
}),
target: path.resolve('/usr/local/bin'),
},
aws: {
entry: path.resolve(__dirname, 'aws/'),
target: path.resolve(process.env.HOME, '.aws/'),
},
starship: {
entry: path.resolve(__dirname, 'starship.toml'),
target: path.resolve(process.env.HOME, '.config/'),
},
};
setStatus('Done');
return dotfiles;
},
);
await task('Creating symlinks', async ({ setStatus, task }) => {
await task.group((task) => [
task('$HOME', () => {
const { entries, target } = dotfiles.home;
entries.forEach((entry) => {
const symlinkTarget = path.resolve(
target,
`.${path.basename(entry)}`,
);
createSymlink(entry, symlinkTarget, 'file');
});
}),
task('Binaries', () => {
const { entries, target } = dotfiles.binaries;
entries.forEach((entry) => {
const symlinkTarget = path.resolve(
target,
path.basename(entry),
);
createSymlink(entry, symlinkTarget, 'file');
});
}),
task('AWS', () => {
const { entry, target } = dotfiles.aws;
createSymlink(entry, target, 'dir');
}),
task('Starship', () => {
const { entry, target } = dotfiles.starship;
const symlinkTarget = path.resolve(target, path.basename(entry));
createSymlink(entry, symlinkTarget, 'file');
}),
]);
setStatus('Done');
});