| 64 | }; |
| 65 | |
| 66 | export const getSourceFiles = async (cwd: string) => { |
| 67 | const buildDir = path.join(cwd, 'build'); |
| 68 | const files = await fs.readdir(buildDir, { recursive: true }); |
| 69 | const [httpRoutes, webSocketRoutes] = files.reduce( |
| 70 | ([httpRoutes, webSocketRoutes], file) => { |
| 71 | const parsed = path.parse(file); |
| 72 | const pathSegments = file.split(path.sep); |
| 73 | |
| 74 | if (pathSegments.some((segment) => ignore.includes(segment))) { |
| 75 | return [httpRoutes, webSocketRoutes]; |
| 76 | } |
| 77 | |
| 78 | if (parsed.name.endsWith('http')) { |
| 79 | httpRoutes.push(path.join(buildDir, file)); |
| 80 | } |
| 81 | |
| 82 | if (parsed.name.endsWith('ws')) { |
| 83 | webSocketRoutes.push(path.join(buildDir, file)); |
| 84 | } |
| 85 | |
| 86 | return [httpRoutes, webSocketRoutes]; |
| 87 | }, |
| 88 | [[] as string[], [] as string[]], |
| 89 | ); |
| 90 | |
| 91 | return { |
| 92 | files, |
| 93 | httpRoutes, |
| 94 | webSocketRoutes, |
| 95 | }; |
| 96 | }; |
| 97 | |
| 98 | export const camelCase = (str: string) => |
| 99 | str.replace(/-([a-z])/g, (_, w) => w.toUpperCase()); |