bun-workspaces 1.0.0-alpha.3 → 1.0.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +131 -77
- package/bin/cli.js +1 -2
- package/package.json +24 -30
- package/src/cli/commands/commandHandlerUtils.d.ts +41 -0
- package/src/cli/commands/commandHandlerUtils.mjs +59 -0
- package/src/cli/commands/commands.d.ts +10 -0
- package/src/cli/commands/commands.mjs +23 -0
- package/src/cli/commands/commandsConfig.d.ts +312 -0
- package/src/cli/commands/commandsConfig.mjs +155 -0
- package/src/cli/commands/handleRunScript.d.ts +3 -0
- package/src/cli/commands/handleRunScript.mjs +217 -0
- package/src/cli/commands/handleSimpleCommands.d.ts +15 -0
- package/src/cli/commands/handleSimpleCommands.mjs +170 -0
- package/src/cli/commands/index.d.ts +2 -0
- package/src/cli/commands/index.mjs +2 -0
- package/src/cli/createCli.d.ts +19 -0
- package/src/cli/createCli.mjs +113 -0
- package/src/cli/fatalErrorLogger.d.ts +1 -0
- package/src/cli/fatalErrorLogger.mjs +7 -0
- package/src/cli/globalOptions/globalOptions.d.ts +38 -0
- package/src/cli/globalOptions/globalOptions.mjs +120 -0
- package/src/cli/globalOptions/globalOptionsConfig.d.ts +43 -0
- package/src/cli/globalOptions/globalOptionsConfig.mjs +34 -0
- package/src/cli/globalOptions/index.d.ts +2 -0
- package/src/cli/globalOptions/index.mjs +2 -0
- package/src/cli/index.d.ts +3 -0
- package/src/cli/index.mjs +3 -0
- package/src/config/bunWorkspacesConfig.d.ts +17 -0
- package/src/config/bunWorkspacesConfig.mjs +50 -0
- package/src/config/configFile.d.ts +8 -0
- package/src/config/configFile.mjs +43 -0
- package/src/config/errors.d.ts +3 -0
- package/src/config/errors.mjs +10 -0
- package/src/config/{index.ts → index.d.ts} +1 -0
- package/src/config/index.mjs +11 -0
- package/src/config/userEnvVars.d.ts +9 -0
- package/src/config/userEnvVars.mjs +9 -0
- package/src/config/workspaceConfig/errors.d.ts +3 -0
- package/src/config/workspaceConfig/errors.mjs +9 -0
- package/src/config/workspaceConfig/index.d.ts +4 -0
- package/src/config/workspaceConfig/index.mjs +4 -0
- package/src/config/workspaceConfig/loadWorkspaceConfig.d.ts +5 -0
- package/src/config/workspaceConfig/loadWorkspaceConfig.mjs +82 -0
- package/src/config/workspaceConfig/workspaceConfig.d.ts +25 -0
- package/src/config/workspaceConfig/workspaceConfig.mjs +80 -0
- package/src/config/workspaceConfig/workspaceConfigLocation.d.ts +2 -0
- package/src/config/workspaceConfig/workspaceConfigLocation.mjs +5 -0
- package/src/doctor/doctor.d.ts +35 -0
- package/src/doctor/doctor.mjs +52 -0
- package/src/doctor/index.d.ts +1 -0
- package/src/doctor/index.mjs +1 -0
- package/src/index.d.ts +31 -0
- package/src/index.mjs +9 -0
- package/src/internal/bun/bunLock.d.ts +20 -0
- package/src/internal/bun/bunLock.mjs +72 -0
- package/src/internal/bun/bunVersion.d.ts +21 -0
- package/src/internal/bun/bunVersion.mjs +43 -0
- package/src/internal/bun/index.d.ts +2 -0
- package/src/internal/bun/index.mjs +2 -0
- package/src/internal/core/asyncIterable/asyncIterableQueue.d.ts +15 -0
- package/src/internal/core/asyncIterable/asyncIterableQueue.mjs +73 -0
- package/src/internal/core/asyncIterable/mergeAsyncIterables.d.ts +5 -0
- package/src/internal/core/asyncIterable/mergeAsyncIterables.mjs +27 -0
- package/src/internal/core/error.d.ts +9 -0
- package/src/internal/{error.ts → core/error.mjs} +7 -16
- package/src/internal/core/index.d.ts +7 -0
- package/src/internal/core/index.mjs +6 -0
- package/src/internal/core/json/index.d.ts +2 -0
- package/src/internal/core/json/index.mjs +2 -0
- package/src/internal/core/json/json.d.ts +9 -0
- package/src/internal/core/json/json.mjs +6 -0
- package/src/internal/core/json/jsonc.d.ts +9 -0
- package/src/internal/core/json/jsonc.mjs +117 -0
- package/src/internal/core/optionalArray.d.ts +15 -0
- package/src/internal/core/optionalArray.mjs +8 -0
- package/src/internal/core/regex.d.ts +3 -0
- package/src/internal/core/regex.mjs +10 -0
- package/src/internal/core/types.d.ts +6 -0
- package/src/internal/core/types.mjs +3 -0
- package/src/internal/logger/index.d.ts +1 -0
- package/src/internal/logger/index.mjs +1 -0
- package/src/internal/logger/logger.d.ts +44 -0
- package/src/internal/logger/logger.mjs +110 -0
- package/src/internal/runtime/env.d.ts +5 -0
- package/src/internal/runtime/env.mjs +29 -0
- package/src/internal/runtime/index.d.ts +2 -0
- package/src/internal/runtime/index.mjs +2 -0
- package/src/internal/runtime/onExit.d.ts +6 -0
- package/src/internal/runtime/onExit.mjs +24 -0
- package/src/internal/runtime/os.d.ts +4 -0
- package/src/internal/runtime/os.mjs +7 -0
- package/src/internal/runtime/tempFile.d.ts +16 -0
- package/src/internal/runtime/tempFile.mjs +50 -0
- package/src/project/errors.d.ts +3 -0
- package/src/project/errors.mjs +9 -0
- package/src/project/implementations/fileSystemProject.d.ts +106 -0
- package/src/project/implementations/fileSystemProject.mjs +227 -0
- package/src/project/implementations/memoryProject.d.ts +32 -0
- package/src/project/implementations/memoryProject.mjs +46 -0
- package/src/project/implementations/projectBase.d.ts +28 -0
- package/src/project/implementations/projectBase.mjs +117 -0
- package/src/project/index.d.ts +5 -0
- package/src/project/index.mjs +4 -0
- package/src/project/project.d.ts +64 -0
- package/src/project/project.mjs +6 -0
- package/src/runScript/index.d.ts +7 -0
- package/src/runScript/index.mjs +7 -0
- package/src/runScript/outputChunk.d.ts +22 -0
- package/src/runScript/outputChunk.mjs +30 -0
- package/src/runScript/parallel.d.ts +12 -0
- package/src/runScript/parallel.mjs +52 -0
- package/src/runScript/runScript.d.ts +37 -0
- package/src/runScript/runScript.mjs +60 -0
- package/src/runScript/runScripts.d.ts +48 -0
- package/src/runScript/runScripts.mjs +124 -0
- package/src/runScript/scriptCommand.d.ts +33 -0
- package/src/runScript/scriptCommand.mjs +19 -0
- package/src/runScript/scriptExecution.d.ts +9 -0
- package/src/runScript/scriptExecution.mjs +51 -0
- package/src/runScript/scriptRuntimeMetadata.d.ts +75 -0
- package/src/runScript/scriptRuntimeMetadata.mjs +62 -0
- package/src/runScript/scriptShellOption.d.ts +7 -0
- package/src/runScript/scriptShellOption.mjs +36 -0
- package/src/workspaces/errors.d.ts +12 -0
- package/src/workspaces/{errors.ts → errors.mjs} +5 -2
- package/src/workspaces/findWorkspaces.d.ts +22 -0
- package/src/workspaces/findWorkspaces.mjs +168 -0
- package/src/workspaces/index.d.ts +4 -0
- package/src/workspaces/index.mjs +3 -0
- package/src/workspaces/packageJson.d.ts +15 -0
- package/src/workspaces/packageJson.mjs +135 -0
- package/src/workspaces/{workspace.ts → workspace.d.ts} +5 -6
- package/src/workspaces/workspace.mjs +2 -0
- package/bun.lock +0 -576
- package/src/cli/cli.ts +0 -87
- package/src/cli/globalOptions.ts +0 -122
- package/src/cli/index.ts +0 -1
- package/src/cli/projectCommands.ts +0 -390
- package/src/config/bunWorkspacesConfig.ts +0 -62
- package/src/config/configFile.ts +0 -33
- package/src/index.ts +0 -3
- package/src/internal/bunVersion.ts +0 -26
- package/src/internal/env.ts +0 -25
- package/src/internal/logger.ts +0 -180
- package/src/internal/regex.ts +0 -5
- package/src/project/errors.ts +0 -6
- package/src/project/index.ts +0 -6
- package/src/project/project.ts +0 -155
- package/src/project/scriptCommand.ts +0 -40
- package/src/workspaces/findWorkspaces.ts +0 -137
- package/src/workspaces/index.ts +0 -7
- package/src/workspaces/packageJson.ts +0 -166
- package/tsconfig.json +0 -28
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,113 +1,167 @@
|
|
|
1
|
-
|
|
1
|
+
<img src="./packages/doc-website/src/docs/public/images/png/bwunster_64x70.png" alt="bun-workspaces" width="45" />
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
### [**See Full Documentation Here**: _https://bunworkspaces.com_](https://bunworkspaces.com)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# bun-workspaces
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
A CLI and API to enhance your monorepo development with Bun's [native workspaces](https://bun.sh/docs/install/workspaces) feature for nested JavaScript/TypeScript packages.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
- Works right away, with no boilerplate required 🍔🍴
|
|
10
|
+
- Get metadata about your monorepo 🤖
|
|
11
|
+
- Run package.json scripts across workspaces 📋
|
|
12
|
+
- Run inline [Bun Shell](https://bun.com/docs/runtime/shell) scripts in workspaces ⌨️
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
This tool lets you decide the complexity of how you use it.
|
|
15
|
+
To get started, all you need is a normal project using [Bun's native workspaces](https://bun.sh/docs/install/workspaces) feature for nested JavaScript/TypeScript packages.
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
Think of this as a power suit you can snap onto native workspaces, rather than another monorepo framework.
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
Start running some [CLI commands](https://bunworkspaces.com/cli) right away in your repo, or take full advantage of the [scripting API](https://bunworkspaces.com/api) and its features.
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
## Quick Start
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
Installation:
|
|
23
24
|
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
"cli": {
|
|
31
|
-
"logLevel": "warn"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
25
|
+
```bash
|
|
26
|
+
$ # Install to use the API and/or lock your CLI version for your project
|
|
27
|
+
$ bun add --dev bun-workspaces
|
|
28
|
+
$ # Start using the CLI with or without the installation step
|
|
29
|
+
$ bunx bun-workspaces --help
|
|
34
30
|
```
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### Examples
|
|
32
|
+
### CLI
|
|
39
33
|
|
|
40
|
-
|
|
34
|
+
[Full CLI documentation here](https://bunworkspaces.com/cli)
|
|
41
35
|
|
|
42
36
|
```bash
|
|
43
|
-
alias bw="bunx bun-workspaces"
|
|
37
|
+
alias bw="bunx bun-workspaces" # can place in .zshrc, .bashrc, or similar
|
|
44
38
|
|
|
45
|
-
# List all workspaces
|
|
39
|
+
# List all workspaces in your project
|
|
46
40
|
bw list-workspaces
|
|
47
|
-
bw ls
|
|
48
|
-
|
|
49
|
-
# List workspace names only
|
|
50
|
-
bw list-workspaces --name-only
|
|
51
41
|
|
|
52
|
-
#
|
|
53
|
-
bw
|
|
42
|
+
# ls is an alias for list-workspaces
|
|
43
|
+
bw ls --json --pretty # Output as formatted JSON
|
|
54
44
|
|
|
55
|
-
#
|
|
56
|
-
|
|
45
|
+
# Run the lint script for all workspaces
|
|
46
|
+
# that have it in their package.json "scripts" field
|
|
47
|
+
bw run-script lint
|
|
57
48
|
|
|
58
|
-
#
|
|
59
|
-
bw
|
|
49
|
+
# run is an alias for run-script
|
|
50
|
+
bw run lint my-workspace # Run for a single workspace
|
|
51
|
+
bw run lint my-workspace-a my-workspace-b # Run for multiple workspaces
|
|
52
|
+
bw run lint "my-workspace-*" # Run for matching workspace names
|
|
53
|
+
bw run lint --parallel # Run at the same time
|
|
54
|
+
bw run lint --args="--my-appended-args" # Add args to each script call
|
|
55
|
+
bw run lint --args="--my-arg=<workspaceName>" # Use the workspace name in args
|
|
56
|
+
bw run "bun build" --inline --inline-name=build # Run an inline command
|
|
60
57
|
|
|
61
|
-
#
|
|
62
|
-
bw
|
|
63
|
-
bw
|
|
58
|
+
# Show usage (you can pass --help to any command)
|
|
59
|
+
bw help
|
|
60
|
+
bw --help
|
|
64
61
|
|
|
65
|
-
#
|
|
66
|
-
bw
|
|
62
|
+
# Show version
|
|
63
|
+
bw --version
|
|
67
64
|
|
|
68
|
-
#
|
|
69
|
-
bw
|
|
65
|
+
# Pass --cwd to any command
|
|
66
|
+
bw --cwd=/path/to/your/project ls
|
|
67
|
+
bw --cwd=/path/to/your/project run my-script
|
|
70
68
|
|
|
71
|
-
#
|
|
72
|
-
bw
|
|
73
|
-
|
|
74
|
-
bw workspace-info my-workspace --json
|
|
75
|
-
bw script-info my-script --json
|
|
69
|
+
# Pass --log-level to any command (debug, info, warn, error, or silent)
|
|
70
|
+
bw --log-level=silent run my-script
|
|
71
|
+
```
|
|
76
72
|
|
|
77
|
-
|
|
78
|
-
# workspaces that have it
|
|
79
|
-
# in their `scripts` field
|
|
80
|
-
bw run my-script
|
|
73
|
+
### API
|
|
81
74
|
|
|
82
|
-
|
|
83
|
-
bw run my-script my-workspace
|
|
75
|
+
[Full API documentation here](https://bunworkspaces.com/api)
|
|
84
76
|
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
```typescript
|
|
78
|
+
import { createFileSystemProject } from "bun-workspaces";
|
|
87
79
|
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
// A Project contains the core functionality of bun-workspaces.
|
|
81
|
+
const project = createFileSystemProject({
|
|
82
|
+
rootDirectory: "path/to/your/project",
|
|
83
|
+
});
|
|
90
84
|
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
// A Workspace that matches the name or alias "my-workspace"
|
|
86
|
+
const myWorkspace = project.findWorkspaceByNameOrAlias("my-workspace");
|
|
93
87
|
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
// Array of workspaces whose names match the wildcard pattern
|
|
89
|
+
const wildcardWorkspaces = project.findWorkspacesByPattern("my-workspace-*");
|
|
96
90
|
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
// Array of workspaces that have "my-script" in their package.json "scripts"
|
|
92
|
+
const workspacesWithScript = project.listWorkspacesWithScript("my-script");
|
|
99
93
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
94
|
+
// Run a script in a workspace
|
|
95
|
+
const runSingleScript = async () => {
|
|
96
|
+
const { output, exit } = project.runWorkspaceScript({
|
|
97
|
+
workspaceNameOrAlias: "my-workspace",
|
|
98
|
+
script: "my-script",
|
|
99
|
+
args: "--my --appended --args", // optional, arguments to add to the command
|
|
100
|
+
});
|
|
103
101
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
// Get a stream of the script subprocess's output
|
|
103
|
+
for await (const chunk of output) {
|
|
104
|
+
console.log(chunk.raw); // The raw output content (Uint8Array)
|
|
105
|
+
console.log(chunk.decode()); // The output chunk's content (string)
|
|
106
|
+
console.log(chunk.decode({ stripAnsi: true })); // Text with ANSI codes sanitized
|
|
107
|
+
console.log(chunk.streamName); // The output stream, "stdout" or "stderr"
|
|
108
|
+
}
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
// Get data about the script execution after it exits
|
|
111
|
+
const exitResult = await exit;
|
|
112
|
+
|
|
113
|
+
console.log(exitResult.exitCode); // The exit code (number)
|
|
114
|
+
console.log(exitResult.signal); // The exit signal (string), or null
|
|
115
|
+
console.log(exitResult.success); // true if exit code was 0
|
|
116
|
+
console.log(exitResult.startTimeISO); // Start time (string)
|
|
117
|
+
console.log(exitResult.endTimeISO); // End time (string)
|
|
118
|
+
console.log(exitResult.durationMs); // Duration in milliseconds (number)
|
|
119
|
+
console.log(exitResult.metadata.workspace); // The target workspace (Workspace)
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Run a script in all workspaces that have it in their package.json "scripts" field
|
|
123
|
+
const runManyScripts = async () => {
|
|
124
|
+
const { output, summary } = project.runScriptAcrossWorkspaces({
|
|
125
|
+
workspacePatterns: ["*"], // this will run in all workspaces that have my-script
|
|
126
|
+
script: "my-script", // the package.json "scripts" field name to run
|
|
127
|
+
args: "--my --appended --args", // optional, arguments to add to the command
|
|
128
|
+
parallel: true, // optional, run the scripts in parallel
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Get a stream of script output
|
|
132
|
+
for await (const { outputChunk, scriptMetadata } of output) {
|
|
133
|
+
console.log(outputChunk.raw); // The raw output content (Uint8Array)
|
|
134
|
+
console.log(outputChunk.decode()); // the output chunk's content (string)
|
|
135
|
+
console.log(outputChunk.decode({ stripAnsi: true })); // text with ANSI codes sanitized (string)
|
|
136
|
+
console.log(outputChunk.streamName); // "stdout" or "stderr"
|
|
137
|
+
|
|
138
|
+
// The metadata can distinguish which workspace script
|
|
139
|
+
// the current output chunk came from
|
|
140
|
+
console.log(scriptMetadata.workspace); // Workspace object
|
|
141
|
+
}
|
|
110
142
|
|
|
111
|
-
|
|
112
|
-
|
|
143
|
+
// Get final summary data and script exit details after all scripts have completed
|
|
144
|
+
const summaryResult = await summary;
|
|
145
|
+
|
|
146
|
+
console.log(summaryResult.totalCount); // Total number of scripts
|
|
147
|
+
console.log(summaryResult.allSuccess); // true if all scripts succeeded
|
|
148
|
+
console.log(summaryResult.successCount); // Number of scripts that succeeded
|
|
149
|
+
console.log(summaryResult.failureCount); // Number of scripts that failed
|
|
150
|
+
console.log(summaryResult.startTimeISO); // Start time (string)
|
|
151
|
+
console.log(summaryResult.endTimeISO); // End time (string)
|
|
152
|
+
console.log(summaryResult.durationMs); // Total duration in milliseconds (number)
|
|
153
|
+
|
|
154
|
+
// The exit details of each workspace script
|
|
155
|
+
for (const exitResult of summaryResult.scriptResults) {
|
|
156
|
+
console.log(exitResult.exitCode); // The exit code (number)
|
|
157
|
+
console.log(exitResult.signal); // The exit signal (string), or null
|
|
158
|
+
console.log(exitResult.success); // true if exit code was 0
|
|
159
|
+
console.log(exitResult.startTimeISO); // Start time (ISO string)
|
|
160
|
+
console.log(exitResult.endTimeISO); // End time (ISO string)
|
|
161
|
+
console.log(exitResult.durationMs); // Duration in milliseconds (number)
|
|
162
|
+
console.log(exitResult.metadata.workspace); // The target workspace (Workspace)
|
|
163
|
+
}
|
|
164
|
+
};
|
|
113
165
|
```
|
|
166
|
+
|
|
167
|
+
_`bun-workspaces` is independent from the [Bun](https://bun.sh) project and is not affiliated with or endorsed by Anthropic. This project aims to enhance enhance the experience of Bun for its users._
|
package/bin/cli.js
CHANGED
package/package.json
CHANGED
|
@@ -1,40 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-workspaces",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0-alpha.30",
|
|
4
|
+
"description": "A monorepo management tool for Bun, with a CLI and API to enhance Bun's native workspaces.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "src/index.mjs",
|
|
7
|
+
"types": "src/index.d.ts",
|
|
8
|
+
"homepage": "https://bunworkspaces.com",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/bun-workspaces/bun-workspaces.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"bun",
|
|
15
|
+
"workspace",
|
|
16
|
+
"workspaces",
|
|
17
|
+
"monorepo",
|
|
18
|
+
"cli",
|
|
19
|
+
"api"
|
|
20
|
+
],
|
|
6
21
|
"bin": {
|
|
7
|
-
"bun-workspaces": "bin/cli.js"
|
|
22
|
+
"bun-workspaces": "bin/cli.js",
|
|
23
|
+
"bw": "bin/cli.js"
|
|
8
24
|
},
|
|
9
|
-
"
|
|
25
|
+
"_bwInternal": {
|
|
10
26
|
"bunVersion": {
|
|
11
|
-
"build": "1.
|
|
12
|
-
"libraryConsumer": "^1.
|
|
27
|
+
"build": "1.3.4",
|
|
28
|
+
"libraryConsumer": "^1.2.x"
|
|
13
29
|
}
|
|
14
30
|
},
|
|
15
|
-
"scripts": {
|
|
16
|
-
"cli": "bun run bin/cli.js",
|
|
17
|
-
"cli:dev": "_BW_RUNTIME_MODE=development bun run bin/cli.js",
|
|
18
|
-
"type-check": "tsc --noEmit",
|
|
19
|
-
"lint": "eslint .",
|
|
20
|
-
"format": "prettier --write .",
|
|
21
|
-
"format-check": "prettier --check ."
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"@types/bun": "^1.2.22",
|
|
25
|
-
"@typescript-eslint/eslint-plugin": "^8.44.1",
|
|
26
|
-
"@typescript-eslint/parser": "^8.44.1",
|
|
27
|
-
"bun-workspaces": "file:.",
|
|
28
|
-
"eslint": "^9.36.0",
|
|
29
|
-
"eslint-plugin-import": "^2.32.0",
|
|
30
|
-
"prettier": "^3.6.2",
|
|
31
|
-
"typescript-eslint": "^8.44.1"
|
|
32
|
-
},
|
|
33
31
|
"dependencies": {
|
|
34
|
-
"commander": "^12.1.0"
|
|
35
|
-
"glob": "^11.0.3"
|
|
36
|
-
},
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"typescript": "^5.9.2"
|
|
32
|
+
"commander": "^12.1.0"
|
|
39
33
|
}
|
|
40
34
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Command } from "commander";
|
|
2
|
+
import type { FileSystemProject } from "../../project/implementations/fileSystemProject";
|
|
3
|
+
import type { Workspace } from "../../workspaces";
|
|
4
|
+
import {
|
|
5
|
+
type CliGlobalCommandName,
|
|
6
|
+
type CliProjectCommandName,
|
|
7
|
+
} from "./commandsConfig";
|
|
8
|
+
/** @todo DRY use of output text in cases such as having no workspaces/scripts */
|
|
9
|
+
export interface GlobalCommandContext {
|
|
10
|
+
program: Command;
|
|
11
|
+
postTerminatorArgs: string[];
|
|
12
|
+
}
|
|
13
|
+
export type ProjectCommandContext = GlobalCommandContext & {
|
|
14
|
+
project: FileSystemProject;
|
|
15
|
+
projectError: Error | null;
|
|
16
|
+
};
|
|
17
|
+
export declare const createWorkspaceInfoLines: (
|
|
18
|
+
workspace: Workspace,
|
|
19
|
+
) => string[];
|
|
20
|
+
export declare const createScriptInfoLines: (
|
|
21
|
+
script: string,
|
|
22
|
+
workspaces: Workspace[],
|
|
23
|
+
) => string[];
|
|
24
|
+
export declare const createJsonLines: (
|
|
25
|
+
data: unknown,
|
|
26
|
+
options: {
|
|
27
|
+
pretty: boolean;
|
|
28
|
+
},
|
|
29
|
+
) => string[];
|
|
30
|
+
export declare const commandOutputLogger: import("../../internal/logger").Logger;
|
|
31
|
+
export declare const handleGlobalCommand: <ActionArgs extends unknown[]>(
|
|
32
|
+
commandName: CliGlobalCommandName,
|
|
33
|
+
handler: (context: GlobalCommandContext, ...actionArgs: ActionArgs) => void,
|
|
34
|
+
) => (context: GlobalCommandContext) => Command;
|
|
35
|
+
export declare const handleProjectCommand: <ActionArgs extends unknown[]>(
|
|
36
|
+
commandName: CliProjectCommandName,
|
|
37
|
+
handler: (
|
|
38
|
+
context: Omit<ProjectCommandContext, "projectError">,
|
|
39
|
+
...actionArgs: ActionArgs
|
|
40
|
+
) => void,
|
|
41
|
+
) => (context: ProjectCommandContext) => Command;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
import { createLogger, logger } from "../../internal/logger/index.mjs";
|
|
3
|
+
import { getCliCommandConfig } from "./commandsConfig.mjs"; // CONCATENATED MODULE: external "commander"
|
|
4
|
+
// CONCATENATED MODULE: external "../../internal/logger/index.mjs"
|
|
5
|
+
// CONCATENATED MODULE: external "./commandsConfig.mjs"
|
|
6
|
+
// CONCATENATED MODULE: ./src/cli/commands/commandHandlerUtils.ts
|
|
7
|
+
|
|
8
|
+
const createWorkspaceInfoLines = (workspace) => [
|
|
9
|
+
`Workspace: ${workspace.name}`,
|
|
10
|
+
` - Aliases: ${workspace.aliases.join(", ")}`,
|
|
11
|
+
` - Path: ${workspace.path}`,
|
|
12
|
+
` - Glob Match: ${workspace.matchPattern}`,
|
|
13
|
+
` - Scripts: ${workspace.scripts.join(", ")}`,
|
|
14
|
+
];
|
|
15
|
+
const createScriptInfoLines = (script, workspaces) => [
|
|
16
|
+
`Script: ${script}`,
|
|
17
|
+
...workspaces.map((workspace) => ` - ${workspace.name}`),
|
|
18
|
+
];
|
|
19
|
+
const createJsonLines = (data, options) =>
|
|
20
|
+
JSON.stringify(data, null, options.pretty ? 2 : undefined).split("\n");
|
|
21
|
+
const commandOutputLogger = createLogger("");
|
|
22
|
+
commandOutputLogger.printLevel = "info";
|
|
23
|
+
const handleCommand = (commandName, handler) => (context) => {
|
|
24
|
+
const config = getCliCommandConfig(commandName);
|
|
25
|
+
let { program } = context;
|
|
26
|
+
program = program
|
|
27
|
+
.command(config.command)
|
|
28
|
+
.aliases(config.aliases)
|
|
29
|
+
.description(config.description);
|
|
30
|
+
for (const { flags, description, values } of Object.values(config.options)) {
|
|
31
|
+
const option = new Option(flags.join(", "), description);
|
|
32
|
+
if (values?.length) {
|
|
33
|
+
option.choices(values);
|
|
34
|
+
}
|
|
35
|
+
program.addOption(option);
|
|
36
|
+
}
|
|
37
|
+
program = program.action((...actionArgs) => handler(context, ...actionArgs));
|
|
38
|
+
return program;
|
|
39
|
+
};
|
|
40
|
+
const handleGlobalCommand = (commandName, handler) => (context) =>
|
|
41
|
+
handleCommand(commandName, handler)(context);
|
|
42
|
+
const handleProjectCommand = (commandName, handler) => (context) =>
|
|
43
|
+
handleCommand(commandName, (context, ...actionArgs) => {
|
|
44
|
+
const { projectError } = context;
|
|
45
|
+
if (projectError) {
|
|
46
|
+
logger.error(projectError.message);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
handler(context, ...actionArgs);
|
|
50
|
+
})(context);
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
commandOutputLogger,
|
|
54
|
+
createJsonLines,
|
|
55
|
+
createScriptInfoLines,
|
|
56
|
+
createWorkspaceInfoLines,
|
|
57
|
+
handleGlobalCommand,
|
|
58
|
+
handleProjectCommand,
|
|
59
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
GlobalCommandContext,
|
|
3
|
+
ProjectCommandContext,
|
|
4
|
+
} from "./commandHandlerUtils";
|
|
5
|
+
export declare const defineGlobalCommands: (
|
|
6
|
+
context: GlobalCommandContext,
|
|
7
|
+
) => void;
|
|
8
|
+
export declare const defineProjectCommands: (
|
|
9
|
+
context: ProjectCommandContext,
|
|
10
|
+
) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { runScript } from "./handleRunScript.mjs";
|
|
2
|
+
import {
|
|
3
|
+
doctor,
|
|
4
|
+
listScripts,
|
|
5
|
+
listWorkspaces,
|
|
6
|
+
scriptInfo,
|
|
7
|
+
workspaceInfo,
|
|
8
|
+
} from "./handleSimpleCommands.mjs"; // CONCATENATED MODULE: external "./handleRunScript.mjs"
|
|
9
|
+
// CONCATENATED MODULE: external "./handleSimpleCommands.mjs"
|
|
10
|
+
// CONCATENATED MODULE: ./src/cli/commands/commands.ts
|
|
11
|
+
|
|
12
|
+
const defineGlobalCommands = (context) => {
|
|
13
|
+
doctor(context);
|
|
14
|
+
};
|
|
15
|
+
const defineProjectCommands = (context) => {
|
|
16
|
+
listWorkspaces(context);
|
|
17
|
+
listScripts(context);
|
|
18
|
+
workspaceInfo(context);
|
|
19
|
+
scriptInfo(context);
|
|
20
|
+
runScript(context);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { defineGlobalCommands, defineProjectCommands };
|