-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoints.ts
38 lines (34 loc) · 1013 Bytes
/
entrypoints.ts
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
import { readdir } from 'fs/promises';
import { extname, join } from 'path';
const sourceDir = './src/scripts';
/**
* Recursively get all .ts and .js entrypoints from the directory
*
* @param dir Directory path to scan
* @returns {Promise<string[]>} The entrypoints
*/
async function getFiles(dir: string): Promise<string[]> {
const dirents = await readdir(dir, { withFileTypes: true });
const files = await Promise.all(
dirents.map((dirent) => {
const res = join(dir, dirent.name);
if (dirent.isDirectory()) {
return getFiles(res);
} else {
return Promise.resolve(res);
}
})
);
// Flatten the array and filter only .ts and .js files
return Array.prototype
.concat(...files)
.filter((file) => ['.ts', '.js'].includes(extname(file)));
}
/**
* Get all entrypoints from the src directory
*
* @returns {Promise<string[]>} The entrypoints
*/
export default async function entryPoints(): Promise<string[]> {
return getFiles(sourceDir);
}