|
1 | 1 | // @ts-check
|
2 | 2 | import parallelLimit from "async/parallelLimit";
|
3 |
| -import { readdirSync, readFileSync, statSync } from "fs"; |
4 | 3 | import { cpus } from "os";
|
5 |
| -import { join } from "path"; |
6 | 4 | import yargs from "yargs";
|
7 | 5 |
|
8 | 6 | import { downlevelWorkspace } from "./downlevelWorkspace.mjs";
|
| 7 | +import { getWorkspaces } from "./getWorkspaces.mjs"; |
9 | 8 |
|
10 | 9 | // ToDo: Write downlevel-dts as a yargs command, and import yargs in scripts instead.
|
11 | 10 | yargs
|
|
17 | 16 | .help()
|
18 | 17 | .alias("h", "help").argv;
|
19 | 18 |
|
20 |
| -const { packages } = JSON.parse(readFileSync(join(process.cwd(), "package.json")).toString()).workspaces; |
21 |
| - |
22 |
| -const getAllFiles = (dirPath, arrayOfFiles = []) => { |
23 |
| - const files = readdirSync(dirPath); |
24 |
| - |
25 |
| - files.forEach((file) => { |
26 |
| - if (statSync(dirPath + "/" + file).isDirectory()) { |
27 |
| - arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles); |
28 |
| - } else { |
29 |
| - arrayOfFiles.push(join(dirPath, "/", file)); |
30 |
| - } |
31 |
| - }); |
32 |
| - |
33 |
| - return arrayOfFiles; |
34 |
| -}; |
35 |
| - |
36 |
| -const workspaces = packages |
37 |
| - .map((dir) => dir.replace("/*", "")) |
38 |
| - .flatMap((workspacesDir) => |
39 |
| - readdirSync(join(process.cwd(), workspacesDir), { withFileTypes: true }) |
40 |
| - .filter((dirent) => dirent.isDirectory()) |
41 |
| - .map((dirent) => ({ workspacesDir, workspaceName: dirent.name })) |
42 |
| - ); |
43 |
| - |
| 19 | +const workspaces = getWorkspaces(process.cwd()); |
44 | 20 | const tasks = workspaces.map(({ workspacesDir, workspaceName }) => async () => {
|
45 | 21 | await downlevelWorkspace(workspacesDir, workspaceName);
|
46 | 22 | });
|
|
0 commit comments