@bagelink/workspace 1.7.4 → 1.7.8
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/README.md +224 -1
- package/bin/bgl.ts +102 -4
- package/dist/bin/bgl.cjs +80 -5
- package/dist/bin/bgl.mjs +80 -5
- package/dist/index.cjs +18 -10
- package/dist/index.d.cts +41 -1
- package/dist/index.d.mts +41 -1
- package/dist/index.d.ts +41 -1
- package/dist/index.mjs +2 -2
- package/dist/shared/workspace.BMTTo3s8.cjs +993 -0
- package/dist/shared/workspace.COhZ__uF.mjs +973 -0
- package/package.json +15 -4
- package/src/detect.ts +90 -0
- package/src/index.ts +5 -0
- package/src/lint.ts +235 -0
- package/src/sdk.ts +175 -0
- package/src/workspace.ts +505 -0
- package/templates/dev-runner.ts +61 -0
- package/dist/shared/workspace.R3ocIOTb.mjs +0 -234
- package/dist/shared/workspace.hk0HFYa9.cjs +0 -246
package/README.md
CHANGED
|
@@ -161,7 +161,9 @@ export default defineWorkspace({
|
|
|
161
161
|
|
|
162
162
|
## CLI
|
|
163
163
|
|
|
164
|
-
###
|
|
164
|
+
### Single Project Setup
|
|
165
|
+
|
|
166
|
+
#### `npx bgl init`
|
|
165
167
|
|
|
166
168
|
Interactively generate project configuration files:
|
|
167
169
|
- `bgl.config.ts` - Workspace configuration
|
|
@@ -180,6 +182,227 @@ npx bgl init
|
|
|
180
182
|
- Generates netlify.toml with production proxy configuration
|
|
181
183
|
- Safe: prompts before each step
|
|
182
184
|
|
|
185
|
+
### Workspace (Multi-Project) Setup
|
|
186
|
+
|
|
187
|
+
#### `npx bgl init --workspace`
|
|
188
|
+
|
|
189
|
+
Create a workspace with flat structure for multiple projects:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
npx bgl init --workspace
|
|
193
|
+
|
|
194
|
+
? Workspace name: › my-workspace
|
|
195
|
+
? Bagel project ID: › my-project
|
|
196
|
+
? Create first project? › Yes
|
|
197
|
+
? First project name: › web
|
|
198
|
+
|
|
199
|
+
✅ Workspace created successfully!
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Creates structure:**
|
|
203
|
+
```
|
|
204
|
+
my-workspace/
|
|
205
|
+
├── package.json # Workspace root
|
|
206
|
+
├── bgl.config.ts # Shared config
|
|
207
|
+
├── tsconfig.json
|
|
208
|
+
├── shared/ # Shared code
|
|
209
|
+
│ ├── package.json
|
|
210
|
+
│ ├── utils/
|
|
211
|
+
│ └── types/
|
|
212
|
+
└── web/ # First project
|
|
213
|
+
├── bgl.config.ts
|
|
214
|
+
├── package.json
|
|
215
|
+
├── vite.config.ts
|
|
216
|
+
└── src/
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
#### `bgl add <project-name>`
|
|
220
|
+
|
|
221
|
+
Add a new project to workspace:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
bgl add admin
|
|
225
|
+
bgl add customer
|
|
226
|
+
bgl add mobile
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Each project:
|
|
230
|
+
- Gets its own directory at root level
|
|
231
|
+
- Inherits shared config from workspace root
|
|
232
|
+
- Can import from `shared/utils`, `shared/types`, etc.
|
|
233
|
+
- Auto-configures with Vite proxy
|
|
234
|
+
|
|
235
|
+
#### `bgl list`
|
|
236
|
+
|
|
237
|
+
List all projects in workspace:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
bgl list
|
|
241
|
+
|
|
242
|
+
Projects:
|
|
243
|
+
- web
|
|
244
|
+
- admin
|
|
245
|
+
- customer
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Running Workspace Projects
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
# Run all projects concurrently
|
|
252
|
+
bun run dev
|
|
253
|
+
|
|
254
|
+
# Run specific project
|
|
255
|
+
bun run dev:admin
|
|
256
|
+
bun run dev:customer
|
|
257
|
+
|
|
258
|
+
# Build specific project
|
|
259
|
+
bun run build:admin
|
|
260
|
+
|
|
261
|
+
# Build all projects
|
|
262
|
+
bun run build
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Vite automatically assigns ports:**
|
|
266
|
+
- First project: `http://localhost:5173`
|
|
267
|
+
- Second project: `http://localhost:5174`
|
|
268
|
+
- Third project: `http://localhost:5175`
|
|
269
|
+
- etc.
|
|
270
|
+
|
|
271
|
+
### Linting Setup
|
|
272
|
+
|
|
273
|
+
#### `bgl lint init`
|
|
274
|
+
|
|
275
|
+
Set up linting and formatting in your project:
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
bgl lint init
|
|
279
|
+
|
|
280
|
+
? Select configurations to set up:
|
|
281
|
+
✔ ESLint
|
|
282
|
+
✔ Prettier
|
|
283
|
+
✔ EditorConfig
|
|
284
|
+
○ Git Hooks
|
|
285
|
+
? Install dependencies? › Yes
|
|
286
|
+
|
|
287
|
+
✅ Created eslint.config.js
|
|
288
|
+
✅ Created .prettierrc
|
|
289
|
+
✅ Created .prettierignore
|
|
290
|
+
✅ Created .editorconfig
|
|
291
|
+
✅ Updated package.json with lint scripts
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
**Creates:**
|
|
295
|
+
- `eslint.config.js` - ESLint configuration (Vue 3 + TypeScript)
|
|
296
|
+
- `.prettierrc` - Prettier configuration
|
|
297
|
+
- `.prettierignore` - Prettier ignore patterns
|
|
298
|
+
- `.editorconfig` - Editor configuration
|
|
299
|
+
- `.lintstagedrc` - Lint-staged configuration (if git hooks selected)
|
|
300
|
+
|
|
301
|
+
**Adds scripts:**
|
|
302
|
+
- `bun run lint` - Run linter
|
|
303
|
+
- `bun run lint:fix` - Fix linting issues
|
|
304
|
+
- `bun run format` - Format code
|
|
305
|
+
- `bun run format:check` - Check formatting
|
|
306
|
+
|
|
307
|
+
**Auto-detects workspace:**
|
|
308
|
+
```bash
|
|
309
|
+
# In workspace root (auto-detected)
|
|
310
|
+
bgl lint init
|
|
311
|
+
✓ Detected workspace mode
|
|
312
|
+
# Sets up at workspace root
|
|
313
|
+
|
|
314
|
+
# In single project (auto-detected)
|
|
315
|
+
bgl lint init
|
|
316
|
+
# Sets up in current project
|
|
317
|
+
|
|
318
|
+
# Force modes:
|
|
319
|
+
bgl lint init --workspace # Force workspace mode
|
|
320
|
+
bgl lint init --project # Force single project mode
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
**Workspace detection:**
|
|
324
|
+
- Checks for `workspaces` field in package.json
|
|
325
|
+
- Checks for multiple project directories
|
|
326
|
+
- Auto-applies best mode
|
|
327
|
+
|
|
328
|
+
### SDK Generation
|
|
329
|
+
|
|
330
|
+
#### `bgl sdk generate`
|
|
331
|
+
|
|
332
|
+
Generate TypeScript SDK from OpenAPI specification:
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
bgl sdk generate
|
|
336
|
+
|
|
337
|
+
? OpenAPI spec URL: › http://localhost:8000/openapi.json
|
|
338
|
+
? Output directory: › ./src/api
|
|
339
|
+
? Split into organized files? › Yes
|
|
340
|
+
|
|
341
|
+
📡 Fetching OpenAPI spec from: http://localhost:8000/openapi.json
|
|
342
|
+
📁 Output directory: ./src/api
|
|
343
|
+
|
|
344
|
+
✅ Generated types.d.ts
|
|
345
|
+
✅ Generated api.ts
|
|
346
|
+
✅ Generated index.ts
|
|
347
|
+
🔀 Splitting into organized files...
|
|
348
|
+
✅ Files organized into directories
|
|
349
|
+
|
|
350
|
+
✅ SDK generated successfully!
|
|
351
|
+
|
|
352
|
+
Import it in your code:
|
|
353
|
+
import { api } from './api'
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
**Features:**
|
|
357
|
+
- Auto-reads `openapi_url` from `bgl.config.ts`
|
|
358
|
+
- Generates TypeScript types from OpenAPI schema
|
|
359
|
+
- Creates type-safe API client
|
|
360
|
+
- Optional file organization (split by endpoints)
|
|
361
|
+
- Works with both local and remote OpenAPI specs
|
|
362
|
+
|
|
363
|
+
**Auto-detects workspace:**
|
|
364
|
+
```bash
|
|
365
|
+
# In workspace root (auto-detected)
|
|
366
|
+
bgl sdk generate
|
|
367
|
+
✓ Detected workspace mode - will generate for multiple projects
|
|
368
|
+
|
|
369
|
+
? Select projects to generate SDK for:
|
|
370
|
+
✔ admin
|
|
371
|
+
✔ customer
|
|
372
|
+
✔ mobile
|
|
373
|
+
|
|
374
|
+
# In single project (auto-detected)
|
|
375
|
+
bgl sdk generate
|
|
376
|
+
# Generates SDK for current project only
|
|
377
|
+
|
|
378
|
+
# Force modes:
|
|
379
|
+
bgl sdk generate --workspace # Force workspace mode
|
|
380
|
+
bgl sdk generate --project # Force single project mode
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
**Smart behavior:**
|
|
384
|
+
- Auto-detects workspace structure
|
|
385
|
+
- Prompts for project selection in workspace mode
|
|
386
|
+
- Reads `openapi_url` from each project's `bgl.config.ts`
|
|
387
|
+
|
|
388
|
+
**Generated structure:**
|
|
389
|
+
```
|
|
390
|
+
src/api/
|
|
391
|
+
├── index.ts # Main export
|
|
392
|
+
├── types.d.ts # TypeScript types
|
|
393
|
+
└── api.ts # API client
|
|
394
|
+
|
|
395
|
+
# Or with --split:
|
|
396
|
+
src/api/
|
|
397
|
+
├── endpoints/
|
|
398
|
+
│ ├── users.ts
|
|
399
|
+
│ ├── auth.ts
|
|
400
|
+
│ └── data.ts
|
|
401
|
+
├── types/
|
|
402
|
+
│ └── index.ts
|
|
403
|
+
└── index.ts
|
|
404
|
+
```
|
|
405
|
+
|
|
183
406
|
### `npx bgl --help`
|
|
184
407
|
|
|
185
408
|
Show CLI help.
|
package/bin/bgl.ts
CHANGED
|
@@ -1,22 +1,120 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import process from 'node:process'
|
|
3
|
+
import { isWorkspace } from '../src/detect.js'
|
|
3
4
|
import { generateWorkspaceConfig } from '../src/init.js'
|
|
5
|
+
import { setupLint } from '../src/lint.js'
|
|
6
|
+
import { generateSDK, generateSDKForWorkspace } from '../src/sdk.js'
|
|
7
|
+
import { addProject, initWorkspace, listProjects } from '../src/workspace.js'
|
|
4
8
|
|
|
5
|
-
const [,, command] = process.argv
|
|
9
|
+
const [,, command, subcommand, ...args] = process.argv
|
|
6
10
|
|
|
7
11
|
async function main() {
|
|
8
12
|
if (command === 'init') {
|
|
9
|
-
|
|
13
|
+
// Check both subcommand and args for --workspace flag
|
|
14
|
+
const createWorkspace
|
|
15
|
+
= subcommand === '--workspace'
|
|
16
|
+
|| subcommand === '-w'
|
|
17
|
+
|| args.includes('--workspace')
|
|
18
|
+
|| args.includes('-w')
|
|
19
|
+
if (createWorkspace) {
|
|
20
|
+
await initWorkspace()
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
await generateWorkspaceConfig()
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (command === 'add') {
|
|
27
|
+
const projectName = subcommand // 'bgl add admin' -> subcommand is 'admin'
|
|
28
|
+
if (!projectName) {
|
|
29
|
+
console.error('Error: Project name is required')
|
|
30
|
+
console.log('Usage: bgl add <project-name>')
|
|
31
|
+
process.exit(1)
|
|
32
|
+
}
|
|
33
|
+
await addProject(projectName)
|
|
34
|
+
}
|
|
35
|
+
else if (command === 'list') {
|
|
36
|
+
const projects = listProjects()
|
|
37
|
+
if (projects.length === 0) {
|
|
38
|
+
console.log('No projects found')
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
console.log('\nProjects:')
|
|
42
|
+
projects.forEach((p) => { console.log(` - ${p}`) })
|
|
43
|
+
console.log('')
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (command === 'lint') {
|
|
47
|
+
if (subcommand === 'init') {
|
|
48
|
+
// Auto-detect workspace or allow override
|
|
49
|
+
const forceWorkspace = args.includes('--workspace') || args.includes('-w')
|
|
50
|
+
const forceProject = args.includes('--project') || args.includes('-p')
|
|
51
|
+
|
|
52
|
+
let workspaceMode = isWorkspace(process.cwd())
|
|
53
|
+
if (forceWorkspace) workspaceMode = true
|
|
54
|
+
if (forceProject) workspaceMode = false
|
|
55
|
+
|
|
56
|
+
if (workspaceMode) {
|
|
57
|
+
console.log('✓ Detected workspace mode')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
await setupLint(process.cwd(), workspaceMode)
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.log(`
|
|
64
|
+
Lint Commands:
|
|
65
|
+
bgl lint init Set up linting (auto-detects workspace)
|
|
66
|
+
bgl lint init --workspace Force workspace mode
|
|
67
|
+
bgl lint init --project Force single project mode
|
|
68
|
+
`)
|
|
69
|
+
process.exit(1)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (command === 'sdk') {
|
|
73
|
+
if (subcommand === 'generate') {
|
|
74
|
+
// Auto-detect workspace or allow override
|
|
75
|
+
const forceWorkspace = args.includes('--workspace') || args.includes('-w')
|
|
76
|
+
const forceProject = args.includes('--project') || args.includes('-p')
|
|
77
|
+
|
|
78
|
+
let workspaceMode = isWorkspace(process.cwd())
|
|
79
|
+
if (forceWorkspace) workspaceMode = true
|
|
80
|
+
if (forceProject) workspaceMode = false
|
|
81
|
+
|
|
82
|
+
if (workspaceMode) {
|
|
83
|
+
console.log('✓ Detected workspace mode - will generate for multiple projects')
|
|
84
|
+
await generateSDKForWorkspace()
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
await generateSDK(process.cwd())
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log(`
|
|
92
|
+
SDK Commands:
|
|
93
|
+
bgl sdk generate Generate SDK (auto-detects workspace)
|
|
94
|
+
bgl sdk generate --workspace Force workspace mode
|
|
95
|
+
bgl sdk generate --project Force single project mode
|
|
96
|
+
`)
|
|
97
|
+
process.exit(1)
|
|
98
|
+
}
|
|
10
99
|
}
|
|
11
100
|
else {
|
|
12
101
|
console.log(`
|
|
13
102
|
Bagel Workspace CLI
|
|
14
103
|
|
|
15
104
|
Usage:
|
|
16
|
-
bgl init
|
|
105
|
+
bgl init Generate bgl.config.ts for single project
|
|
106
|
+
bgl init --workspace Create a new workspace with multiple projects
|
|
107
|
+
bgl add <name> Add a new project to workspace
|
|
108
|
+
bgl list List all projects in workspace
|
|
109
|
+
bgl lint init Set up linting (auto-detects workspace)
|
|
110
|
+
bgl sdk generate Generate SDK (auto-detects workspace)
|
|
17
111
|
|
|
18
112
|
Options:
|
|
19
|
-
--
|
|
113
|
+
--workspace, -w Force workspace mode
|
|
114
|
+
--project, -p Force single project mode
|
|
115
|
+
--help, -h Show this help message
|
|
116
|
+
|
|
117
|
+
Note: Commands auto-detect workspace mode based on directory structure
|
|
20
118
|
`)
|
|
21
119
|
process.exit(command === '--help' || command === '-h' ? 0 : 1)
|
|
22
120
|
}
|
package/dist/bin/bgl.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const process = require('node:process');
|
|
5
|
-
const
|
|
5
|
+
const detect = require('../shared/workspace.BMTTo3s8.cjs');
|
|
6
6
|
require('node:fs');
|
|
7
7
|
require('node:path');
|
|
8
8
|
require('prompts');
|
|
@@ -11,19 +11,94 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
11
11
|
|
|
12
12
|
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
13
13
|
|
|
14
|
-
const [, , command] = process__default.argv;
|
|
14
|
+
const [, , command, subcommand, ...args] = process__default.argv;
|
|
15
15
|
async function main() {
|
|
16
16
|
if (command === "init") {
|
|
17
|
-
|
|
17
|
+
const createWorkspace = subcommand === "--workspace" || subcommand === "-w" || args.includes("--workspace") || args.includes("-w");
|
|
18
|
+
if (createWorkspace) {
|
|
19
|
+
await detect.initWorkspace();
|
|
20
|
+
} else {
|
|
21
|
+
await detect.generateWorkspaceConfig();
|
|
22
|
+
}
|
|
23
|
+
} else if (command === "add") {
|
|
24
|
+
const projectName = subcommand;
|
|
25
|
+
if (!projectName) {
|
|
26
|
+
console.error("Error: Project name is required");
|
|
27
|
+
console.log("Usage: bgl add <project-name>");
|
|
28
|
+
process__default.exit(1);
|
|
29
|
+
}
|
|
30
|
+
await detect.addProject(projectName);
|
|
31
|
+
} else if (command === "list") {
|
|
32
|
+
const projects = detect.listProjects();
|
|
33
|
+
if (projects.length === 0) {
|
|
34
|
+
console.log("No projects found");
|
|
35
|
+
} else {
|
|
36
|
+
console.log("\nProjects:");
|
|
37
|
+
projects.forEach((p) => {
|
|
38
|
+
console.log(` - ${p}`);
|
|
39
|
+
});
|
|
40
|
+
console.log("");
|
|
41
|
+
}
|
|
42
|
+
} else if (command === "lint") {
|
|
43
|
+
if (subcommand === "init") {
|
|
44
|
+
const forceWorkspace = args.includes("--workspace") || args.includes("-w");
|
|
45
|
+
const forceProject = args.includes("--project") || args.includes("-p");
|
|
46
|
+
let workspaceMode = detect.isWorkspace(process__default.cwd());
|
|
47
|
+
if (forceWorkspace) workspaceMode = true;
|
|
48
|
+
if (forceProject) workspaceMode = false;
|
|
49
|
+
if (workspaceMode) {
|
|
50
|
+
console.log("\u2713 Detected workspace mode");
|
|
51
|
+
}
|
|
52
|
+
await detect.setupLint(process__default.cwd(), workspaceMode);
|
|
53
|
+
} else {
|
|
54
|
+
console.log(`
|
|
55
|
+
Lint Commands:
|
|
56
|
+
bgl lint init Set up linting (auto-detects workspace)
|
|
57
|
+
bgl lint init --workspace Force workspace mode
|
|
58
|
+
bgl lint init --project Force single project mode
|
|
59
|
+
`);
|
|
60
|
+
process__default.exit(1);
|
|
61
|
+
}
|
|
62
|
+
} else if (command === "sdk") {
|
|
63
|
+
if (subcommand === "generate") {
|
|
64
|
+
const forceWorkspace = args.includes("--workspace") || args.includes("-w");
|
|
65
|
+
const forceProject = args.includes("--project") || args.includes("-p");
|
|
66
|
+
let workspaceMode = detect.isWorkspace(process__default.cwd());
|
|
67
|
+
if (forceWorkspace) workspaceMode = true;
|
|
68
|
+
if (forceProject) workspaceMode = false;
|
|
69
|
+
if (workspaceMode) {
|
|
70
|
+
console.log("\u2713 Detected workspace mode - will generate for multiple projects");
|
|
71
|
+
await detect.generateSDKForWorkspace();
|
|
72
|
+
} else {
|
|
73
|
+
await detect.generateSDK(process__default.cwd());
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
console.log(`
|
|
77
|
+
SDK Commands:
|
|
78
|
+
bgl sdk generate Generate SDK (auto-detects workspace)
|
|
79
|
+
bgl sdk generate --workspace Force workspace mode
|
|
80
|
+
bgl sdk generate --project Force single project mode
|
|
81
|
+
`);
|
|
82
|
+
process__default.exit(1);
|
|
83
|
+
}
|
|
18
84
|
} else {
|
|
19
85
|
console.log(`
|
|
20
86
|
Bagel Workspace CLI
|
|
21
87
|
|
|
22
88
|
Usage:
|
|
23
|
-
bgl init
|
|
89
|
+
bgl init Generate bgl.config.ts for single project
|
|
90
|
+
bgl init --workspace Create a new workspace with multiple projects
|
|
91
|
+
bgl add <name> Add a new project to workspace
|
|
92
|
+
bgl list List all projects in workspace
|
|
93
|
+
bgl lint init Set up linting (auto-detects workspace)
|
|
94
|
+
bgl sdk generate Generate SDK (auto-detects workspace)
|
|
24
95
|
|
|
25
96
|
Options:
|
|
26
|
-
--
|
|
97
|
+
--workspace, -w Force workspace mode
|
|
98
|
+
--project, -p Force single project mode
|
|
99
|
+
--help, -h Show this help message
|
|
100
|
+
|
|
101
|
+
Note: Commands auto-detect workspace mode based on directory structure
|
|
27
102
|
`);
|
|
28
103
|
process__default.exit(command === "--help" || command === "-h" ? 0 : 1);
|
|
29
104
|
}
|
package/dist/bin/bgl.mjs
CHANGED
|
@@ -1,23 +1,98 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import process from 'node:process';
|
|
3
|
-
import { g as generateWorkspaceConfig } from '../shared/workspace.
|
|
3
|
+
import { i as initWorkspace, g as generateWorkspaceConfig, h as addProject, l as listProjects, k as isWorkspace, d as setupLint, f as generateSDKForWorkspace, e as generateSDK } from '../shared/workspace.COhZ__uF.mjs';
|
|
4
4
|
import 'node:fs';
|
|
5
5
|
import 'node:path';
|
|
6
6
|
import 'prompts';
|
|
7
7
|
|
|
8
|
-
const [, , command] = process.argv;
|
|
8
|
+
const [, , command, subcommand, ...args] = process.argv;
|
|
9
9
|
async function main() {
|
|
10
10
|
if (command === "init") {
|
|
11
|
-
|
|
11
|
+
const createWorkspace = subcommand === "--workspace" || subcommand === "-w" || args.includes("--workspace") || args.includes("-w");
|
|
12
|
+
if (createWorkspace) {
|
|
13
|
+
await initWorkspace();
|
|
14
|
+
} else {
|
|
15
|
+
await generateWorkspaceConfig();
|
|
16
|
+
}
|
|
17
|
+
} else if (command === "add") {
|
|
18
|
+
const projectName = subcommand;
|
|
19
|
+
if (!projectName) {
|
|
20
|
+
console.error("Error: Project name is required");
|
|
21
|
+
console.log("Usage: bgl add <project-name>");
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
await addProject(projectName);
|
|
25
|
+
} else if (command === "list") {
|
|
26
|
+
const projects = listProjects();
|
|
27
|
+
if (projects.length === 0) {
|
|
28
|
+
console.log("No projects found");
|
|
29
|
+
} else {
|
|
30
|
+
console.log("\nProjects:");
|
|
31
|
+
projects.forEach((p) => {
|
|
32
|
+
console.log(` - ${p}`);
|
|
33
|
+
});
|
|
34
|
+
console.log("");
|
|
35
|
+
}
|
|
36
|
+
} else if (command === "lint") {
|
|
37
|
+
if (subcommand === "init") {
|
|
38
|
+
const forceWorkspace = args.includes("--workspace") || args.includes("-w");
|
|
39
|
+
const forceProject = args.includes("--project") || args.includes("-p");
|
|
40
|
+
let workspaceMode = isWorkspace(process.cwd());
|
|
41
|
+
if (forceWorkspace) workspaceMode = true;
|
|
42
|
+
if (forceProject) workspaceMode = false;
|
|
43
|
+
if (workspaceMode) {
|
|
44
|
+
console.log("\u2713 Detected workspace mode");
|
|
45
|
+
}
|
|
46
|
+
await setupLint(process.cwd(), workspaceMode);
|
|
47
|
+
} else {
|
|
48
|
+
console.log(`
|
|
49
|
+
Lint Commands:
|
|
50
|
+
bgl lint init Set up linting (auto-detects workspace)
|
|
51
|
+
bgl lint init --workspace Force workspace mode
|
|
52
|
+
bgl lint init --project Force single project mode
|
|
53
|
+
`);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
} else if (command === "sdk") {
|
|
57
|
+
if (subcommand === "generate") {
|
|
58
|
+
const forceWorkspace = args.includes("--workspace") || args.includes("-w");
|
|
59
|
+
const forceProject = args.includes("--project") || args.includes("-p");
|
|
60
|
+
let workspaceMode = isWorkspace(process.cwd());
|
|
61
|
+
if (forceWorkspace) workspaceMode = true;
|
|
62
|
+
if (forceProject) workspaceMode = false;
|
|
63
|
+
if (workspaceMode) {
|
|
64
|
+
console.log("\u2713 Detected workspace mode - will generate for multiple projects");
|
|
65
|
+
await generateSDKForWorkspace();
|
|
66
|
+
} else {
|
|
67
|
+
await generateSDK(process.cwd());
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
console.log(`
|
|
71
|
+
SDK Commands:
|
|
72
|
+
bgl sdk generate Generate SDK (auto-detects workspace)
|
|
73
|
+
bgl sdk generate --workspace Force workspace mode
|
|
74
|
+
bgl sdk generate --project Force single project mode
|
|
75
|
+
`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
12
78
|
} else {
|
|
13
79
|
console.log(`
|
|
14
80
|
Bagel Workspace CLI
|
|
15
81
|
|
|
16
82
|
Usage:
|
|
17
|
-
bgl init
|
|
83
|
+
bgl init Generate bgl.config.ts for single project
|
|
84
|
+
bgl init --workspace Create a new workspace with multiple projects
|
|
85
|
+
bgl add <name> Add a new project to workspace
|
|
86
|
+
bgl list List all projects in workspace
|
|
87
|
+
bgl lint init Set up linting (auto-detects workspace)
|
|
88
|
+
bgl sdk generate Generate SDK (auto-detects workspace)
|
|
18
89
|
|
|
19
90
|
Options:
|
|
20
|
-
--
|
|
91
|
+
--workspace, -w Force workspace mode
|
|
92
|
+
--project, -p Force single project mode
|
|
93
|
+
--help, -h Show this help message
|
|
94
|
+
|
|
95
|
+
Note: Commands auto-detect workspace mode based on directory structure
|
|
21
96
|
`);
|
|
22
97
|
process.exit(command === "--help" || command === "-h" ? 0 : 1);
|
|
23
98
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const node_fs = require('node:fs');
|
|
4
4
|
const node_path = require('node:path');
|
|
5
5
|
const process = require('node:process');
|
|
6
|
-
const
|
|
6
|
+
const detect = require('./shared/workspace.BMTTo3s8.cjs');
|
|
7
7
|
require('prompts');
|
|
8
8
|
|
|
9
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -32,7 +32,7 @@ async function resolveConfig(mode = "development", options = {}) {
|
|
|
32
32
|
currentDir = parentDir;
|
|
33
33
|
}
|
|
34
34
|
if (options.interactive !== false) {
|
|
35
|
-
await
|
|
35
|
+
await detect.generateWorkspaceConfig(root, configFile);
|
|
36
36
|
const newConfig = await loadConfig(localConfigPath, mode);
|
|
37
37
|
if (newConfig) {
|
|
38
38
|
return newConfig;
|
|
@@ -131,13 +131,13 @@ function createWorkspace(options = {}) {
|
|
|
131
131
|
* Generate Netlify configuration file
|
|
132
132
|
*/
|
|
133
133
|
generateNetlify(config, outPath = "./netlify.toml", additionalConfig) {
|
|
134
|
-
|
|
134
|
+
detect.writeNetlifyConfig(config, outPath, additionalConfig);
|
|
135
135
|
},
|
|
136
136
|
/**
|
|
137
137
|
* Set build environment variables
|
|
138
138
|
*/
|
|
139
139
|
setBuildEnv(config) {
|
|
140
|
-
|
|
140
|
+
detect.setBuildEnvVars(config);
|
|
141
141
|
},
|
|
142
142
|
/**
|
|
143
143
|
* Clear cached configuration
|
|
@@ -148,12 +148,20 @@ function createWorkspace(options = {}) {
|
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
exports.
|
|
152
|
-
exports.
|
|
153
|
-
exports.
|
|
154
|
-
exports.
|
|
155
|
-
exports.
|
|
156
|
-
exports.
|
|
151
|
+
exports.addProject = detect.addProject;
|
|
152
|
+
exports.generateNetlifyConfig = detect.generateNetlifyConfig;
|
|
153
|
+
exports.generateNetlifyRedirect = detect.generateNetlifyRedirect;
|
|
154
|
+
exports.generateSDK = detect.generateSDK;
|
|
155
|
+
exports.generateSDKForWorkspace = detect.generateSDKForWorkspace;
|
|
156
|
+
exports.generateWorkspaceConfig = detect.generateWorkspaceConfig;
|
|
157
|
+
exports.generateWorkspaceConfigSync = detect.generateWorkspaceConfigSync;
|
|
158
|
+
exports.getWorkspaceInfo = detect.getWorkspaceInfo;
|
|
159
|
+
exports.initWorkspace = detect.initWorkspace;
|
|
160
|
+
exports.isWorkspace = detect.isWorkspace;
|
|
161
|
+
exports.listProjects = detect.listProjects;
|
|
162
|
+
exports.setBuildEnvVars = detect.setBuildEnvVars;
|
|
163
|
+
exports.setupLint = detect.setupLint;
|
|
164
|
+
exports.writeNetlifyConfig = detect.writeNetlifyConfig;
|
|
157
165
|
exports.createCustomProxy = createCustomProxy;
|
|
158
166
|
exports.createViteProxy = createViteProxy;
|
|
159
167
|
exports.createWorkspace = createWorkspace;
|
package/dist/index.d.cts
CHANGED
|
@@ -91,6 +91,46 @@ declare function createCustomProxy(paths: string[], target: string, options?: {
|
|
|
91
91
|
secure?: boolean;
|
|
92
92
|
}): ProxyConfig;
|
|
93
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Set up linting in a project
|
|
96
|
+
*/
|
|
97
|
+
declare function setupLint(root?: string, isWorkspace?: boolean): Promise<void>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Generate SDK from OpenAPI spec
|
|
101
|
+
*/
|
|
102
|
+
declare function generateSDK(root?: string): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Generate SDK for all projects in workspace
|
|
105
|
+
*/
|
|
106
|
+
declare function generateSDKForWorkspace(root?: string): Promise<void>;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Initialize a new workspace with flat structure
|
|
110
|
+
*/
|
|
111
|
+
declare function initWorkspace(root?: string): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Add a new project to the workspace
|
|
114
|
+
*/
|
|
115
|
+
declare function addProject(name: string, root?: string): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* List all projects in workspace
|
|
118
|
+
*/
|
|
119
|
+
declare function listProjects(root?: string): string[];
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Detect if current directory is a workspace root
|
|
123
|
+
*/
|
|
124
|
+
declare function isWorkspace(root?: string): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Get workspace info
|
|
127
|
+
*/
|
|
128
|
+
declare function getWorkspaceInfo(root?: string): {
|
|
129
|
+
isWorkspace: boolean;
|
|
130
|
+
projects: string[];
|
|
131
|
+
hasShared: boolean;
|
|
132
|
+
};
|
|
133
|
+
|
|
94
134
|
/**
|
|
95
135
|
* Define workspace configuration
|
|
96
136
|
* Simple helper to get config from a config map
|
|
@@ -123,5 +163,5 @@ declare function createWorkspace(options?: WorkspaceOptions): {
|
|
|
123
163
|
clearCache(): void;
|
|
124
164
|
};
|
|
125
165
|
|
|
126
|
-
export { createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateWorkspaceConfig, generateWorkspaceConfigSync, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
|
|
166
|
+
export { addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, getWorkspaceInfo, initWorkspace, isWorkspace, listProjects, mergeConfigs, resolveConfig, setBuildEnvVars, setupLint, writeNetlifyConfig };
|
|
127
167
|
export type { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
|