-
Notifications
You must be signed in to change notification settings - Fork 326
/
Copy pathnuke.mjs
executable file
·64 lines (54 loc) · 1.84 KB
/
nuke.mjs
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
#!/usr/bin/env node
import { access, constants, readdir } from 'node:fs/promises';
import { join, resolve } from 'node:path';
import { $ } from 'zx';
const $$ = $({
env: { NODE_ENV: 'production' },
verbose: !!process.env.VERBOSE,
});
const DIRECTORIES_TO_CLEAN = ['.coverage', '.turbo', 'coverage', 'dist', 'node_modules'];
// Iterate over `packages/*`
try {
const packagesDir = resolve('packages');
await access(packagesDir, constants.R_OK);
try {
const packages = await readdir(packagesDir);
const promises = packages.map(
dir => $$`rm -rf ${DIRECTORIES_TO_CLEAN.map(directory => join(join(packagesDir, dir), directory))}`,
);
await Promise.all(promises).then(() => void console.log(`Cleaned ${promises.length} packages`));
} catch (error) {
console.error(error);
}
} catch {
console.log('Cannot access packages directory');
}
// Iterate over `playground/*`
try {
const playgroundDir = resolve('playground');
await access(playgroundDir);
try {
const playgrounds = await readdir(playgroundDir);
for (const dir of playgrounds) {
try {
await access(join(playgroundDir, dir, '.yalc'), constants.R_OK);
$$({
cwd: join(playgroundDir, dir),
})`rm -rf .yalc`.then(() => console.log('Removed .yalc from', dir));
} catch {
// Ignore
}
}
await Promise.allSettled(
playgrounds.map(
dir => $$`rm -rf ${DIRECTORIES_TO_CLEAN.map(directory => join(join(playgroundDir, dir), directory))}`,
),
).then(() => void console.log(`Cleaned playground directories`));
} catch (error) {
console.error(error);
}
} catch {
console.log('Cannot access playground directory');
}
await $$`rm -rf .turbo`.then(() => console.log('Removed root .turbo directory'));
await $$`rm -rf node_modules`.then(() => console.log('Removed root node_modules'));