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.
Files changed (154) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +131 -77
  3. package/bin/cli.js +1 -2
  4. package/package.json +24 -30
  5. package/src/cli/commands/commandHandlerUtils.d.ts +41 -0
  6. package/src/cli/commands/commandHandlerUtils.mjs +59 -0
  7. package/src/cli/commands/commands.d.ts +10 -0
  8. package/src/cli/commands/commands.mjs +23 -0
  9. package/src/cli/commands/commandsConfig.d.ts +312 -0
  10. package/src/cli/commands/commandsConfig.mjs +155 -0
  11. package/src/cli/commands/handleRunScript.d.ts +3 -0
  12. package/src/cli/commands/handleRunScript.mjs +217 -0
  13. package/src/cli/commands/handleSimpleCommands.d.ts +15 -0
  14. package/src/cli/commands/handleSimpleCommands.mjs +170 -0
  15. package/src/cli/commands/index.d.ts +2 -0
  16. package/src/cli/commands/index.mjs +2 -0
  17. package/src/cli/createCli.d.ts +19 -0
  18. package/src/cli/createCli.mjs +113 -0
  19. package/src/cli/fatalErrorLogger.d.ts +1 -0
  20. package/src/cli/fatalErrorLogger.mjs +7 -0
  21. package/src/cli/globalOptions/globalOptions.d.ts +38 -0
  22. package/src/cli/globalOptions/globalOptions.mjs +120 -0
  23. package/src/cli/globalOptions/globalOptionsConfig.d.ts +43 -0
  24. package/src/cli/globalOptions/globalOptionsConfig.mjs +34 -0
  25. package/src/cli/globalOptions/index.d.ts +2 -0
  26. package/src/cli/globalOptions/index.mjs +2 -0
  27. package/src/cli/index.d.ts +3 -0
  28. package/src/cli/index.mjs +3 -0
  29. package/src/config/bunWorkspacesConfig.d.ts +17 -0
  30. package/src/config/bunWorkspacesConfig.mjs +50 -0
  31. package/src/config/configFile.d.ts +8 -0
  32. package/src/config/configFile.mjs +43 -0
  33. package/src/config/errors.d.ts +3 -0
  34. package/src/config/errors.mjs +10 -0
  35. package/src/config/{index.ts → index.d.ts} +1 -0
  36. package/src/config/index.mjs +11 -0
  37. package/src/config/userEnvVars.d.ts +9 -0
  38. package/src/config/userEnvVars.mjs +9 -0
  39. package/src/config/workspaceConfig/errors.d.ts +3 -0
  40. package/src/config/workspaceConfig/errors.mjs +9 -0
  41. package/src/config/workspaceConfig/index.d.ts +4 -0
  42. package/src/config/workspaceConfig/index.mjs +4 -0
  43. package/src/config/workspaceConfig/loadWorkspaceConfig.d.ts +5 -0
  44. package/src/config/workspaceConfig/loadWorkspaceConfig.mjs +82 -0
  45. package/src/config/workspaceConfig/workspaceConfig.d.ts +25 -0
  46. package/src/config/workspaceConfig/workspaceConfig.mjs +80 -0
  47. package/src/config/workspaceConfig/workspaceConfigLocation.d.ts +2 -0
  48. package/src/config/workspaceConfig/workspaceConfigLocation.mjs +5 -0
  49. package/src/doctor/doctor.d.ts +35 -0
  50. package/src/doctor/doctor.mjs +52 -0
  51. package/src/doctor/index.d.ts +1 -0
  52. package/src/doctor/index.mjs +1 -0
  53. package/src/index.d.ts +31 -0
  54. package/src/index.mjs +9 -0
  55. package/src/internal/bun/bunLock.d.ts +20 -0
  56. package/src/internal/bun/bunLock.mjs +72 -0
  57. package/src/internal/bun/bunVersion.d.ts +21 -0
  58. package/src/internal/bun/bunVersion.mjs +43 -0
  59. package/src/internal/bun/index.d.ts +2 -0
  60. package/src/internal/bun/index.mjs +2 -0
  61. package/src/internal/core/asyncIterable/asyncIterableQueue.d.ts +15 -0
  62. package/src/internal/core/asyncIterable/asyncIterableQueue.mjs +73 -0
  63. package/src/internal/core/asyncIterable/mergeAsyncIterables.d.ts +5 -0
  64. package/src/internal/core/asyncIterable/mergeAsyncIterables.mjs +27 -0
  65. package/src/internal/core/error.d.ts +9 -0
  66. package/src/internal/{error.ts → core/error.mjs} +7 -16
  67. package/src/internal/core/index.d.ts +7 -0
  68. package/src/internal/core/index.mjs +6 -0
  69. package/src/internal/core/json/index.d.ts +2 -0
  70. package/src/internal/core/json/index.mjs +2 -0
  71. package/src/internal/core/json/json.d.ts +9 -0
  72. package/src/internal/core/json/json.mjs +6 -0
  73. package/src/internal/core/json/jsonc.d.ts +9 -0
  74. package/src/internal/core/json/jsonc.mjs +117 -0
  75. package/src/internal/core/optionalArray.d.ts +15 -0
  76. package/src/internal/core/optionalArray.mjs +8 -0
  77. package/src/internal/core/regex.d.ts +3 -0
  78. package/src/internal/core/regex.mjs +10 -0
  79. package/src/internal/core/types.d.ts +6 -0
  80. package/src/internal/core/types.mjs +3 -0
  81. package/src/internal/logger/index.d.ts +1 -0
  82. package/src/internal/logger/index.mjs +1 -0
  83. package/src/internal/logger/logger.d.ts +44 -0
  84. package/src/internal/logger/logger.mjs +110 -0
  85. package/src/internal/runtime/env.d.ts +5 -0
  86. package/src/internal/runtime/env.mjs +29 -0
  87. package/src/internal/runtime/index.d.ts +2 -0
  88. package/src/internal/runtime/index.mjs +2 -0
  89. package/src/internal/runtime/onExit.d.ts +6 -0
  90. package/src/internal/runtime/onExit.mjs +24 -0
  91. package/src/internal/runtime/os.d.ts +4 -0
  92. package/src/internal/runtime/os.mjs +7 -0
  93. package/src/internal/runtime/tempFile.d.ts +16 -0
  94. package/src/internal/runtime/tempFile.mjs +50 -0
  95. package/src/project/errors.d.ts +3 -0
  96. package/src/project/errors.mjs +9 -0
  97. package/src/project/implementations/fileSystemProject.d.ts +106 -0
  98. package/src/project/implementations/fileSystemProject.mjs +227 -0
  99. package/src/project/implementations/memoryProject.d.ts +32 -0
  100. package/src/project/implementations/memoryProject.mjs +46 -0
  101. package/src/project/implementations/projectBase.d.ts +28 -0
  102. package/src/project/implementations/projectBase.mjs +117 -0
  103. package/src/project/index.d.ts +5 -0
  104. package/src/project/index.mjs +4 -0
  105. package/src/project/project.d.ts +64 -0
  106. package/src/project/project.mjs +6 -0
  107. package/src/runScript/index.d.ts +7 -0
  108. package/src/runScript/index.mjs +7 -0
  109. package/src/runScript/outputChunk.d.ts +22 -0
  110. package/src/runScript/outputChunk.mjs +30 -0
  111. package/src/runScript/parallel.d.ts +12 -0
  112. package/src/runScript/parallel.mjs +52 -0
  113. package/src/runScript/runScript.d.ts +37 -0
  114. package/src/runScript/runScript.mjs +60 -0
  115. package/src/runScript/runScripts.d.ts +48 -0
  116. package/src/runScript/runScripts.mjs +124 -0
  117. package/src/runScript/scriptCommand.d.ts +33 -0
  118. package/src/runScript/scriptCommand.mjs +19 -0
  119. package/src/runScript/scriptExecution.d.ts +9 -0
  120. package/src/runScript/scriptExecution.mjs +51 -0
  121. package/src/runScript/scriptRuntimeMetadata.d.ts +75 -0
  122. package/src/runScript/scriptRuntimeMetadata.mjs +62 -0
  123. package/src/runScript/scriptShellOption.d.ts +7 -0
  124. package/src/runScript/scriptShellOption.mjs +36 -0
  125. package/src/workspaces/errors.d.ts +12 -0
  126. package/src/workspaces/{errors.ts → errors.mjs} +5 -2
  127. package/src/workspaces/findWorkspaces.d.ts +22 -0
  128. package/src/workspaces/findWorkspaces.mjs +168 -0
  129. package/src/workspaces/index.d.ts +4 -0
  130. package/src/workspaces/index.mjs +3 -0
  131. package/src/workspaces/packageJson.d.ts +15 -0
  132. package/src/workspaces/packageJson.mjs +135 -0
  133. package/src/workspaces/{workspace.ts → workspace.d.ts} +5 -6
  134. package/src/workspaces/workspace.mjs +2 -0
  135. package/bun.lock +0 -576
  136. package/src/cli/cli.ts +0 -87
  137. package/src/cli/globalOptions.ts +0 -122
  138. package/src/cli/index.ts +0 -1
  139. package/src/cli/projectCommands.ts +0 -390
  140. package/src/config/bunWorkspacesConfig.ts +0 -62
  141. package/src/config/configFile.ts +0 -33
  142. package/src/index.ts +0 -3
  143. package/src/internal/bunVersion.ts +0 -26
  144. package/src/internal/env.ts +0 -25
  145. package/src/internal/logger.ts +0 -180
  146. package/src/internal/regex.ts +0 -5
  147. package/src/project/errors.ts +0 -6
  148. package/src/project/index.ts +0 -6
  149. package/src/project/project.ts +0 -155
  150. package/src/project/scriptCommand.ts +0 -40
  151. package/src/workspaces/findWorkspaces.ts +0 -137
  152. package/src/workspaces/index.ts +0 -7
  153. package/src/workspaces/packageJson.ts +0 -166
  154. package/tsconfig.json +0 -28
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Scott Morse
3
+ Copyright (c) 2026 Smorsic Labs, LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,113 +1,167 @@
1
- # bun-workspaces
1
+ <img src="./packages/doc-website/src/docs/public/images/png/bwunster_64x70.png" alt="bun-workspaces" width="45" />
2
2
 
3
- This is a CLI meant to help manage [Bun workspaces](https://bun.sh/docs/install/workspaces).
3
+ ### [**See Full Documentation Here**: _https://bunworkspaces.com_](https://bunworkspaces.com)
4
4
 
5
- ## Installation
5
+ # bun-workspaces
6
6
 
7
- You can install the CLI in your project or simply use `bunx bun-workspaces`.
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
- ```bash
10
- $ bun add --dev bun-workspaces
11
- $ bunx bun-workspaces --help
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
- ### Config file
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
- You can create a config file at `bw.json` in your project root, or you can pass a config file to the CLI with the `--configFile` (or `-c`) option.
17
+ Think of this as a power suit you can snap onto native workspaces, rather than another monorepo framework.
17
18
 
18
- #### Example config
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
- In this config, "app-a" is an alias for package "@my-org/application-a" and "app-b" is an alias for package "@my-org/application-b".
21
+ ## Quick Start
21
22
 
22
- CLI log levels are `debug`, `info`, `warn`, and `error` or `silent`. The default log level is `info`. Commands that are intended to print specific output will still print at `silent`, such as `list-workspaces`, `list-scripts`, `workspace-info`, `script-info`, etc., but other logs will be suppressed.
23
+ Installation:
23
24
 
24
- ```json
25
- {
26
- "workspaceAliases": {
27
- "app-a": "@my-org/application-a",
28
- "app-b": "@my-org/application-b"
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
- You can also pass a config file to the CLI with the `-c` or `--configFile` option.
37
-
38
- ### Examples
32
+ ### CLI
39
33
 
40
- You might consider making a shorter alias in your `.bashrc`, `.zshrc`, or similar shell configuration file, such as `alias bw="bunx bun-workspaces"`, for convenience.
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
- # Filter list of workspaces with wildcard
53
- bw list-workspaces "my-*"
42
+ # ls is an alias for list-workspaces
43
+ bw ls --json --pretty # Output as formatted JSON
54
44
 
55
- # List all workspace scripts
56
- bw list-scripts
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
- # List script names only
59
- bw list-scripts --name-only
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
- # Get info about a workspace
62
- bw workspace-info my-workspace
63
- bw info my-workspace
58
+ # Show usage (you can pass --help to any command)
59
+ bw help
60
+ bw --help
64
61
 
65
- # Get info about a script
66
- bw script-info my-script
62
+ # Show version
63
+ bw --version
67
64
 
68
- # Only print list of workspace names that have the script
69
- bw script-info my-script --workspaces-only
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
- # Get JSON output
72
- bw list-workspaces --json --pretty # optionally pretty print JSON
73
- bw list-scripts --json
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
- # Run a script for all
78
- # workspaces that have it
79
- # in their `scripts` field
80
- bw run my-script
73
+ ### API
81
74
 
82
- # Run a script for a specific workspace by its package.json name or alias from the config
83
- bw run my-script my-workspace
75
+ [Full API documentation here](https://bunworkspaces.com/api)
84
76
 
85
- # Run a script for multiple workspaces
86
- bw run my-script workspace-a workspace-b
77
+ ```typescript
78
+ import { createFileSystemProject } from "bun-workspaces";
87
79
 
88
- # Run a script for workspaces using wildcard (does not take into account workspace aliases)
89
- bw run my-script "my-workspace-*"
80
+ // A Project contains the core functionality of bun-workspaces.
81
+ const project = createFileSystemProject({
82
+ rootDirectory: "path/to/your/project",
83
+ });
90
84
 
91
- # Run script in parallel for all workspaces
92
- bw run my-script --parallel
85
+ // A Workspace that matches the name or alias "my-workspace"
86
+ const myWorkspace = project.findWorkspaceByNameOrAlias("my-workspace");
93
87
 
94
- # Append args to each script call
95
- bw run my-script --args "--my --args"
88
+ // Array of workspaces whose names match the wildcard pattern
89
+ const wildcardWorkspaces = project.findWorkspacesByPattern("my-workspace-*");
96
90
 
97
- # Use the workspace name in args
98
- bw run my-script --args "--my --args=<workspace>"
91
+ // Array of workspaces that have "my-script" in their package.json "scripts"
92
+ const workspacesWithScript = project.listWorkspacesWithScript("my-script");
99
93
 
100
- # Help (--help can also be passed to any command)
101
- bw help
102
- bw --help
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
- # Pass --cwd to any command
105
- bw --cwd /path/to/your/project ls
106
- bw --cwd /path/to/your/project run-script my-script
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
- # Pass --configFile to any command
109
- bw --configFile /path/to/your/config.json ls
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
- # Pass --logLevel to any command (debug, info, warn, error, or silent)
112
- bw --logLevel silent run my-script
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
@@ -1,4 +1,3 @@
1
1
  #!/usr/bin/env bun
2
- import { createCli } from "bun-workspaces";
3
-
2
+ import { createCli } from "bun-workspaces/src/cli";
4
3
  createCli().run();
package/package.json CHANGED
@@ -1,40 +1,34 @@
1
1
  {
2
2
  "name": "bun-workspaces",
3
- "version": "1.0.0-alpha.3",
4
- "main": "src/index.ts",
5
- "homepage": "https://github.com/ScottMorse/bun-workspaces#readme",
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
- "custom": {
25
+ "_bwInternal": {
10
26
  "bunVersion": {
11
- "build": "1.2.22",
12
- "libraryConsumer": "^1.1.x"
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 };