|
1 | 1 | import type { SpawnOptions } from "node:child_process"; |
2 | 2 | import process from "node:process"; |
3 | 3 |
|
4 | | -import { getCurrentGitRepositoryRoot } from "@code-chronicles/util/getCurrentGitRepositoryRoot"; |
| 4 | +import nullthrows from "nullthrows"; |
| 5 | +import { z } from "zod"; |
| 6 | + |
5 | 7 | import { maybeThrow } from "@code-chronicles/util/maybeThrow"; |
6 | 8 | import { promiseAllLimitingConcurrency } from "@code-chronicles/util/promiseAllLimitingConcurrency"; |
| 9 | +import { readPackageJson } from "@code-chronicles/util/readPackageJson"; |
7 | 10 | import { readWorkspaces } from "@code-chronicles/util/readWorkspaces"; |
8 | 11 | import { runWithLogGroupAsync } from "@code-chronicles/util/runWithLogGroupAsync"; |
9 | 12 | import { spawnWithSafeStdio } from "@code-chronicles/util/spawnWithSafeStdio"; |
10 | 13 | import { stripPrefixOrThrow } from "@code-chronicles/util/stripPrefixOrThrow"; |
11 | 14 |
|
12 | | -import { |
13 | | - SCRIPTS, |
14 | | - SCRIPTS_TO_SKIP_BY_WORKSPACE, |
15 | | - type Script, |
16 | | -} from "./scripts.ts"; |
| 15 | +import { SCRIPTS, type Script } from "./scripts.ts"; |
17 | 16 |
|
18 | 17 | type FailedCommand = { |
19 | 18 | command: string; |
@@ -44,41 +43,41 @@ export async function runCommands( |
44 | 43 | } |
45 | 44 | }; |
46 | 45 |
|
47 | | - const commands = [ |
48 | | - async () => { |
| 46 | + const commands = (await readWorkspaces()).map((workspace) => async () => { |
| 47 | + if (workspace.location === ".") { |
49 | 48 | const rootCommand = SCRIPTS[script]?.repositoryRootCommand; |
50 | | - if (rootCommand != null) { |
51 | | - const currentGitRepositoryRoot = await getCurrentGitRepositoryRoot(); |
52 | | - |
53 | | - await runWithLogGroupAsync( |
54 | | - `Running script ${script} for repository root!`, |
55 | | - async () => |
56 | | - await run.apply(null, [ |
57 | | - ...rootCommand, |
58 | | - { cwd: currentGitRepositoryRoot }, |
59 | | - ]), |
60 | | - ); |
61 | | - } |
62 | | - }, |
63 | | - |
64 | | - ...(await readWorkspaces()).map((workspace) => async () => { |
65 | | - const workspaceShortName = stripPrefixOrThrow( |
66 | | - workspace, |
67 | | - "@code-chronicles/", |
68 | | - ); |
69 | | - if (SCRIPTS_TO_SKIP_BY_WORKSPACE[workspaceShortName]?.has(script)) { |
70 | | - console.error( |
71 | | - `Skipping script ${script} for workspace: ${workspaceShortName}`, |
72 | | - ); |
| 49 | + if (rootCommand == null) { |
| 50 | + console.error(`Skipping script ${script} for repository root!`); |
73 | 51 | return; |
74 | 52 | } |
75 | 53 |
|
76 | 54 | await runWithLogGroupAsync( |
77 | | - `Running script ${script} for workspace: ${workspaceShortName}`, |
78 | | - async () => await run("yarn", ["workspace", workspace, script]), |
| 55 | + `Running script ${script} for repository root!`, |
| 56 | + async () => await run(...rootCommand), |
| 57 | + ); |
| 58 | + return; |
| 59 | + } |
| 60 | + |
| 61 | + const workspaceName = nullthrows(workspace.name); |
| 62 | + const workspaceShortName = stripPrefixOrThrow( |
| 63 | + workspaceName, |
| 64 | + "@code-chronicles/", |
| 65 | + ); |
| 66 | + |
| 67 | + const { scripts } = await readPackageJson(workspace.location); |
| 68 | + |
| 69 | + if (scripts?.[script] == null) { |
| 70 | + console.error( |
| 71 | + `Skipping script ${script} for workspace: ${workspaceShortName}`, |
79 | 72 | ); |
80 | | - }), |
81 | | - ]; |
| 73 | + return; |
| 74 | + } |
| 75 | + |
| 76 | + await runWithLogGroupAsync( |
| 77 | + `Running script ${script} for workspace: ${workspaceShortName}`, |
| 78 | + async () => await run("yarn", ["workspace", workspaceName, script]), |
| 79 | + ); |
| 80 | + }); |
82 | 81 |
|
83 | 82 | await promiseAllLimitingConcurrency( |
84 | 83 | commands, |
|
0 commit comments