-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean-types.js
More file actions
executable file
·47 lines (37 loc) · 1.13 KB
/
clean-types.js
File metadata and controls
executable file
·47 lines (37 loc) · 1.13 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
import { rm, readdir, lstat } from 'node:fs/promises';
import { resolve as resolvePath } from 'node:path';
const ignoredPath = ['lib/types'].map((path) =>
resolvePath(process.cwd(), path),
);
const BASE_DIR = resolvePath(process.cwd(), 'lib');
const directories = [BASE_DIR];
/**
* @param {string[]} directories
* @param {string[]} ignored
* @param {(file: string) => void | Promise<void>} fn
*/
async function processFiles(directories, ignored, fn) {
while (directories.length) {
const directory = directories.shift();
for (const fileName of await readdir(directory)) {
const filePath = resolvePath(directory, fileName);
if (ignoredPath.includes(filePath)) continue;
if (await lstat(filePath).then((result) => result.isDirectory())) {
directories.push(filePath);
continue;
}
await fn(filePath);
}
}
}
/**
* @param {string} filePath
*/
async function removeTypeDefFiles(filePath) {
if (filePath.endsWith('.d.ts')) {
await rm(filePath, { force: true });
}
return Promise.resolve();
}
await processFiles(directories, ignoredPath, removeTypeDefFiles);