-
Notifications
You must be signed in to change notification settings - Fork 14
/
entrypoints.ts
39 lines (35 loc) · 1.05 KB
/
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
39
import { readdir } from 'fs/promises';
import { extname, join } from 'path';
const sourceDir = './src/';
/**
* 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 dirEntries = await readdir(dir, { withFileTypes: true });
const files = await Promise.all(
dirEntries.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
const filteredFiles: string[] = (
Array.prototype.concat(...files) as string[]
).filter((file) => ['.ts', '.js'].includes(extname(file)));
return filteredFiles;
}
/**
* Get all entrypoints from the src directory
*
* @returns {Promise<string[]>} The entrypoints
*/
export default async function entryPoints(): Promise<string[]> {
return getFiles(sourceDir);
}