@bagelink/workspace 1.10.0 → 1.10.2
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 +33 -6
- package/bin/bgl.ts +42 -19
- package/dist/bin/bgl.cjs +42 -27
- package/dist/bin/bgl.mjs +36 -21
- package/dist/index.cjs +18 -16
- package/dist/index.d.cts +15 -2
- package/dist/index.d.mts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.mjs +2 -2
- package/dist/shared/{workspace.CTMBmbXa.mjs → workspace.B9BC0YWd.mjs} +64 -25
- package/dist/shared/{workspace.dQE-K3dI.cjs → workspace.BT61Ods7.cjs} +65 -24
- package/package.json +1 -1
- package/src/detect.ts +90 -0
- package/src/index.ts +1 -0
- package/src/sdk.ts +15 -26
package/README.md
CHANGED
|
@@ -304,12 +304,26 @@ bgl lint init
|
|
|
304
304
|
- `bun run format` - Format code
|
|
305
305
|
- `bun run format:check` - Check formatting
|
|
306
306
|
|
|
307
|
-
**
|
|
307
|
+
**Auto-detects workspace:**
|
|
308
308
|
```bash
|
|
309
|
-
|
|
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
|
|
310
321
|
```
|
|
311
322
|
|
|
312
|
-
|
|
323
|
+
**Workspace detection:**
|
|
324
|
+
- Checks for `workspaces` field in package.json
|
|
325
|
+
- Checks for multiple project directories
|
|
326
|
+
- Auto-applies best mode
|
|
313
327
|
|
|
314
328
|
### SDK Generation
|
|
315
329
|
|
|
@@ -346,17 +360,30 @@ Import it in your code:
|
|
|
346
360
|
- Optional file organization (split by endpoints)
|
|
347
361
|
- Works with both local and remote OpenAPI specs
|
|
348
362
|
|
|
349
|
-
**
|
|
363
|
+
**Auto-detects workspace:**
|
|
350
364
|
```bash
|
|
351
|
-
|
|
365
|
+
# In workspace root (auto-detected)
|
|
366
|
+
bgl sdk generate
|
|
367
|
+
✓ Detected workspace mode - will generate for multiple projects
|
|
352
368
|
|
|
353
369
|
? Select projects to generate SDK for:
|
|
354
370
|
✔ admin
|
|
355
371
|
✔ customer
|
|
356
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
|
|
357
381
|
```
|
|
358
382
|
|
|
359
|
-
|
|
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`
|
|
360
387
|
|
|
361
388
|
**Generated structure:**
|
|
362
389
|
```
|
package/bin/bgl.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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'
|
|
4
5
|
import { setupLint } from '../src/lint.js'
|
|
5
6
|
import { generateSDK, generateSDKForWorkspace } from '../src/sdk.js'
|
|
@@ -39,34 +40,54 @@ async function main() {
|
|
|
39
40
|
}
|
|
40
41
|
else if (command === 'lint') {
|
|
41
42
|
if (subcommand === 'init') {
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
// Auto-detect workspace or allow override
|
|
44
|
+
const forceWorkspace = args.includes('--workspace') || args.includes('-w')
|
|
45
|
+
const forceProject = args.includes('--project') || args.includes('-p')
|
|
46
|
+
|
|
47
|
+
let workspaceMode = isWorkspace(process.cwd())
|
|
48
|
+
if (forceWorkspace) workspaceMode = true
|
|
49
|
+
if (forceProject) workspaceMode = false
|
|
50
|
+
|
|
51
|
+
if (workspaceMode) {
|
|
52
|
+
console.log('✓ Detected workspace mode')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await setupLint(process.cwd(), workspaceMode)
|
|
44
56
|
}
|
|
45
57
|
else {
|
|
46
58
|
console.log(`
|
|
47
59
|
Lint Commands:
|
|
48
|
-
bgl lint init Set up linting
|
|
49
|
-
bgl lint init --workspace
|
|
60
|
+
bgl lint init Set up linting (auto-detects workspace)
|
|
61
|
+
bgl lint init --workspace Force workspace mode
|
|
62
|
+
bgl lint init --project Force single project mode
|
|
50
63
|
`)
|
|
51
64
|
process.exit(1)
|
|
52
65
|
}
|
|
53
66
|
}
|
|
54
67
|
else if (command === 'sdk') {
|
|
55
68
|
if (subcommand === 'generate') {
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
// Auto-detect workspace or allow override
|
|
70
|
+
const forceWorkspace = args.includes('--workspace') || args.includes('-w')
|
|
71
|
+
const forceProject = args.includes('--project') || args.includes('-p')
|
|
72
|
+
|
|
73
|
+
let workspaceMode = isWorkspace(process.cwd())
|
|
74
|
+
if (forceWorkspace) workspaceMode = true
|
|
75
|
+
if (forceProject) workspaceMode = false
|
|
76
|
+
|
|
77
|
+
if (workspaceMode) {
|
|
78
|
+
console.log('✓ Detected workspace mode - will generate for multiple projects')
|
|
58
79
|
await generateSDKForWorkspace()
|
|
59
80
|
}
|
|
60
81
|
else {
|
|
61
|
-
|
|
62
|
-
await generateSDK(process.cwd(), projectName)
|
|
82
|
+
await generateSDK(process.cwd())
|
|
63
83
|
}
|
|
64
84
|
}
|
|
65
85
|
else {
|
|
66
86
|
console.log(`
|
|
67
87
|
SDK Commands:
|
|
68
|
-
bgl sdk generate
|
|
69
|
-
bgl sdk generate --workspace
|
|
88
|
+
bgl sdk generate Generate SDK (auto-detects workspace)
|
|
89
|
+
bgl sdk generate --workspace Force workspace mode
|
|
90
|
+
bgl sdk generate --project Force single project mode
|
|
70
91
|
`)
|
|
71
92
|
process.exit(1)
|
|
72
93
|
}
|
|
@@ -76,17 +97,19 @@ SDK Commands:
|
|
|
76
97
|
Bagel Workspace CLI
|
|
77
98
|
|
|
78
99
|
Usage:
|
|
79
|
-
bgl init
|
|
80
|
-
bgl init --workspace
|
|
81
|
-
bgl add <name>
|
|
82
|
-
bgl list
|
|
83
|
-
bgl lint init
|
|
84
|
-
bgl
|
|
85
|
-
bgl sdk generate Generate SDK from OpenAPI spec
|
|
86
|
-
bgl sdk generate --workspace Generate SDK for all workspace projects
|
|
100
|
+
bgl init Generate bgl.config.ts for single project
|
|
101
|
+
bgl init --workspace Create a new workspace with multiple projects
|
|
102
|
+
bgl add <name> Add a new project to workspace
|
|
103
|
+
bgl list List all projects in workspace
|
|
104
|
+
bgl lint init Set up linting (auto-detects workspace)
|
|
105
|
+
bgl sdk generate Generate SDK (auto-detects workspace)
|
|
87
106
|
|
|
88
107
|
Options:
|
|
89
|
-
--
|
|
108
|
+
--workspace, -w Force workspace mode
|
|
109
|
+
--project, -p Force single project mode
|
|
110
|
+
--help, -h Show this help message
|
|
111
|
+
|
|
112
|
+
Note: Commands auto-detect workspace mode based on directory structure
|
|
90
113
|
`)
|
|
91
114
|
process.exit(command === '--help' || command === '-h' ? 0 : 1)
|
|
92
115
|
}
|
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.BT61Ods7.cjs');
|
|
6
6
|
require('node:fs');
|
|
7
7
|
require('node:path');
|
|
8
8
|
require('prompts');
|
|
@@ -14,11 +14,11 @@ const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
|
14
14
|
const [, , command, subcommand, ...args] = process__default.argv;
|
|
15
15
|
async function main() {
|
|
16
16
|
if (command === "init") {
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
await
|
|
17
|
+
const isWorkspace2 = args.includes("--workspace") || args.includes("-w");
|
|
18
|
+
if (isWorkspace2) {
|
|
19
|
+
await detect.initWorkspace();
|
|
20
20
|
} else {
|
|
21
|
-
await
|
|
21
|
+
await detect.generateWorkspaceConfig();
|
|
22
22
|
}
|
|
23
23
|
} else if (command === "add") {
|
|
24
24
|
const projectName = args[0];
|
|
@@ -27,9 +27,9 @@ async function main() {
|
|
|
27
27
|
console.log("Usage: bgl add <project-name>");
|
|
28
28
|
process__default.exit(1);
|
|
29
29
|
}
|
|
30
|
-
await
|
|
30
|
+
await detect.addProject(projectName);
|
|
31
31
|
} else if (command === "list") {
|
|
32
|
-
const projects =
|
|
32
|
+
const projects = detect.listProjects();
|
|
33
33
|
if (projects.length === 0) {
|
|
34
34
|
console.log("No projects found");
|
|
35
35
|
} else {
|
|
@@ -41,30 +41,43 @@ async function main() {
|
|
|
41
41
|
}
|
|
42
42
|
} else if (command === "lint") {
|
|
43
43
|
if (subcommand === "init") {
|
|
44
|
-
const
|
|
45
|
-
|
|
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);
|
|
46
53
|
} else {
|
|
47
54
|
console.log(`
|
|
48
55
|
Lint Commands:
|
|
49
|
-
bgl lint init Set up linting
|
|
50
|
-
bgl lint init --workspace
|
|
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
|
|
51
59
|
`);
|
|
52
60
|
process__default.exit(1);
|
|
53
61
|
}
|
|
54
62
|
} else if (command === "sdk") {
|
|
55
63
|
if (subcommand === "generate") {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
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();
|
|
59
72
|
} else {
|
|
60
|
-
|
|
61
|
-
await workspace.generateSDK(process__default.cwd());
|
|
73
|
+
await detect.generateSDK(process__default.cwd());
|
|
62
74
|
}
|
|
63
75
|
} else {
|
|
64
76
|
console.log(`
|
|
65
77
|
SDK Commands:
|
|
66
|
-
bgl sdk generate
|
|
67
|
-
bgl sdk generate --workspace
|
|
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
|
|
68
81
|
`);
|
|
69
82
|
process__default.exit(1);
|
|
70
83
|
}
|
|
@@ -73,17 +86,19 @@ SDK Commands:
|
|
|
73
86
|
Bagel Workspace CLI
|
|
74
87
|
|
|
75
88
|
Usage:
|
|
76
|
-
bgl init
|
|
77
|
-
bgl init --workspace
|
|
78
|
-
bgl add <name>
|
|
79
|
-
bgl list
|
|
80
|
-
bgl lint init
|
|
81
|
-
bgl
|
|
82
|
-
bgl sdk generate Generate SDK from OpenAPI spec
|
|
83
|
-
bgl sdk generate --workspace Generate SDK for all workspace projects
|
|
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)
|
|
84
95
|
|
|
85
96
|
Options:
|
|
86
|
-
--
|
|
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
|
|
87
102
|
`);
|
|
88
103
|
process__default.exit(command === "--help" || command === "-h" ? 0 : 1);
|
|
89
104
|
}
|
package/dist/bin/bgl.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import process from 'node:process';
|
|
3
|
-
import { i as initWorkspace, g as generateWorkspaceConfig, h as addProject, l as listProjects, d as setupLint, f as generateSDKForWorkspace, e as generateSDK } 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.B9BC0YWd.mjs';
|
|
4
4
|
import 'node:fs';
|
|
5
5
|
import 'node:path';
|
|
6
6
|
import 'prompts';
|
|
@@ -8,8 +8,8 @@ import 'prompts';
|
|
|
8
8
|
const [, , command, subcommand, ...args] = process.argv;
|
|
9
9
|
async function main() {
|
|
10
10
|
if (command === "init") {
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
11
|
+
const isWorkspace2 = args.includes("--workspace") || args.includes("-w");
|
|
12
|
+
if (isWorkspace2) {
|
|
13
13
|
await initWorkspace();
|
|
14
14
|
} else {
|
|
15
15
|
await generateWorkspaceConfig();
|
|
@@ -35,30 +35,43 @@ async function main() {
|
|
|
35
35
|
}
|
|
36
36
|
} else if (command === "lint") {
|
|
37
37
|
if (subcommand === "init") {
|
|
38
|
-
const
|
|
39
|
-
|
|
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);
|
|
40
47
|
} else {
|
|
41
48
|
console.log(`
|
|
42
49
|
Lint Commands:
|
|
43
|
-
bgl lint init Set up linting
|
|
44
|
-
bgl lint init --workspace
|
|
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
|
|
45
53
|
`);
|
|
46
54
|
process.exit(1);
|
|
47
55
|
}
|
|
48
56
|
} else if (command === "sdk") {
|
|
49
57
|
if (subcommand === "generate") {
|
|
50
|
-
const
|
|
51
|
-
|
|
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");
|
|
52
65
|
await generateSDKForWorkspace();
|
|
53
66
|
} else {
|
|
54
|
-
args.find((arg) => !arg.startsWith("-"));
|
|
55
67
|
await generateSDK(process.cwd());
|
|
56
68
|
}
|
|
57
69
|
} else {
|
|
58
70
|
console.log(`
|
|
59
71
|
SDK Commands:
|
|
60
|
-
bgl sdk generate
|
|
61
|
-
bgl sdk generate --workspace
|
|
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
|
|
62
75
|
`);
|
|
63
76
|
process.exit(1);
|
|
64
77
|
}
|
|
@@ -67,17 +80,19 @@ SDK Commands:
|
|
|
67
80
|
Bagel Workspace CLI
|
|
68
81
|
|
|
69
82
|
Usage:
|
|
70
|
-
bgl init
|
|
71
|
-
bgl init --workspace
|
|
72
|
-
bgl add <name>
|
|
73
|
-
bgl list
|
|
74
|
-
bgl lint init
|
|
75
|
-
bgl
|
|
76
|
-
bgl sdk generate Generate SDK from OpenAPI spec
|
|
77
|
-
bgl sdk generate --workspace Generate SDK for all workspace projects
|
|
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)
|
|
78
89
|
|
|
79
90
|
Options:
|
|
80
|
-
--
|
|
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
|
|
81
96
|
`);
|
|
82
97
|
process.exit(command === "--help" || command === "-h" ? 0 : 1);
|
|
83
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.BT61Ods7.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,18 +148,20 @@ function createWorkspace(options = {}) {
|
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
exports.addProject =
|
|
152
|
-
exports.generateNetlifyConfig =
|
|
153
|
-
exports.generateNetlifyRedirect =
|
|
154
|
-
exports.generateSDK =
|
|
155
|
-
exports.generateSDKForWorkspace =
|
|
156
|
-
exports.generateWorkspaceConfig =
|
|
157
|
-
exports.generateWorkspaceConfigSync =
|
|
158
|
-
exports.
|
|
159
|
-
exports.
|
|
160
|
-
exports.
|
|
161
|
-
exports.
|
|
162
|
-
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;
|
|
163
165
|
exports.createCustomProxy = createCustomProxy;
|
|
164
166
|
exports.createViteProxy = createViteProxy;
|
|
165
167
|
exports.createWorkspace = createWorkspace;
|
package/dist/index.d.cts
CHANGED
|
@@ -99,7 +99,7 @@ declare function setupLint(root?: string, isWorkspace?: boolean): Promise<void>;
|
|
|
99
99
|
/**
|
|
100
100
|
* Generate SDK from OpenAPI spec
|
|
101
101
|
*/
|
|
102
|
-
declare function generateSDK(root?: string
|
|
102
|
+
declare function generateSDK(root?: string): Promise<void>;
|
|
103
103
|
/**
|
|
104
104
|
* Generate SDK for all projects in workspace
|
|
105
105
|
*/
|
|
@@ -118,6 +118,19 @@ declare function addProject(name: string, root?: string): Promise<void>;
|
|
|
118
118
|
*/
|
|
119
119
|
declare function listProjects(root?: string): string[];
|
|
120
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
|
+
|
|
121
134
|
/**
|
|
122
135
|
* Define workspace configuration
|
|
123
136
|
* Simple helper to get config from a config map
|
|
@@ -150,5 +163,5 @@ declare function createWorkspace(options?: WorkspaceOptions): {
|
|
|
150
163
|
clearCache(): void;
|
|
151
164
|
};
|
|
152
165
|
|
|
153
|
-
export { addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, initWorkspace, listProjects, mergeConfigs, resolveConfig, setBuildEnvVars, setupLint, writeNetlifyConfig };
|
|
166
|
+
export { addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, getWorkspaceInfo, initWorkspace, isWorkspace, listProjects, mergeConfigs, resolveConfig, setBuildEnvVars, setupLint, writeNetlifyConfig };
|
|
154
167
|
export type { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
|
package/dist/index.d.mts
CHANGED
|
@@ -99,7 +99,7 @@ declare function setupLint(root?: string, isWorkspace?: boolean): Promise<void>;
|
|
|
99
99
|
/**
|
|
100
100
|
* Generate SDK from OpenAPI spec
|
|
101
101
|
*/
|
|
102
|
-
declare function generateSDK(root?: string
|
|
102
|
+
declare function generateSDK(root?: string): Promise<void>;
|
|
103
103
|
/**
|
|
104
104
|
* Generate SDK for all projects in workspace
|
|
105
105
|
*/
|
|
@@ -118,6 +118,19 @@ declare function addProject(name: string, root?: string): Promise<void>;
|
|
|
118
118
|
*/
|
|
119
119
|
declare function listProjects(root?: string): string[];
|
|
120
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
|
+
|
|
121
134
|
/**
|
|
122
135
|
* Define workspace configuration
|
|
123
136
|
* Simple helper to get config from a config map
|
|
@@ -150,5 +163,5 @@ declare function createWorkspace(options?: WorkspaceOptions): {
|
|
|
150
163
|
clearCache(): void;
|
|
151
164
|
};
|
|
152
165
|
|
|
153
|
-
export { addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, initWorkspace, listProjects, mergeConfigs, resolveConfig, setBuildEnvVars, setupLint, writeNetlifyConfig };
|
|
166
|
+
export { addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, getWorkspaceInfo, initWorkspace, isWorkspace, listProjects, mergeConfigs, resolveConfig, setBuildEnvVars, setupLint, writeNetlifyConfig };
|
|
154
167
|
export type { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -99,7 +99,7 @@ declare function setupLint(root?: string, isWorkspace?: boolean): Promise<void>;
|
|
|
99
99
|
/**
|
|
100
100
|
* Generate SDK from OpenAPI spec
|
|
101
101
|
*/
|
|
102
|
-
declare function generateSDK(root?: string
|
|
102
|
+
declare function generateSDK(root?: string): Promise<void>;
|
|
103
103
|
/**
|
|
104
104
|
* Generate SDK for all projects in workspace
|
|
105
105
|
*/
|
|
@@ -118,6 +118,19 @@ declare function addProject(name: string, root?: string): Promise<void>;
|
|
|
118
118
|
*/
|
|
119
119
|
declare function listProjects(root?: string): string[];
|
|
120
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
|
+
|
|
121
134
|
/**
|
|
122
135
|
* Define workspace configuration
|
|
123
136
|
* Simple helper to get config from a config map
|
|
@@ -150,5 +163,5 @@ declare function createWorkspace(options?: WorkspaceOptions): {
|
|
|
150
163
|
clearCache(): void;
|
|
151
164
|
};
|
|
152
165
|
|
|
153
|
-
export { addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, initWorkspace, listProjects, mergeConfigs, resolveConfig, setBuildEnvVars, setupLint, writeNetlifyConfig };
|
|
166
|
+
export { addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, getWorkspaceInfo, initWorkspace, isWorkspace, listProjects, mergeConfigs, resolveConfig, setBuildEnvVars, setupLint, writeNetlifyConfig };
|
|
154
167
|
export type { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { resolve, join } from 'node:path';
|
|
3
3
|
import process from 'node:process';
|
|
4
|
-
import { g as generateWorkspaceConfig, s as setBuildEnvVars, w as writeNetlifyConfig } from './shared/workspace.
|
|
5
|
-
export { h as addProject, a as generateNetlifyConfig, b as generateNetlifyRedirect, e as generateSDK, f as generateSDKForWorkspace, c as generateWorkspaceConfigSync, i as initWorkspace, l as listProjects, d as setupLint } from './shared/workspace.
|
|
4
|
+
import { g as generateWorkspaceConfig, s as setBuildEnvVars, w as writeNetlifyConfig } from './shared/workspace.B9BC0YWd.mjs';
|
|
5
|
+
export { h as addProject, a as generateNetlifyConfig, b as generateNetlifyRedirect, e as generateSDK, f as generateSDKForWorkspace, c as generateWorkspaceConfigSync, j as getWorkspaceInfo, i as initWorkspace, k as isWorkspace, l as listProjects, d as setupLint } from './shared/workspace.B9BC0YWd.mjs';
|
|
6
6
|
import 'prompts';
|
|
7
7
|
|
|
8
8
|
async function resolveConfig(mode = "development", options = {}) {
|
|
@@ -401,7 +401,7 @@ function updatePackageJsonLint(root, configs) {
|
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
-
async function generateSDK(root = process.cwd()
|
|
404
|
+
async function generateSDK(root = process.cwd()) {
|
|
405
405
|
console.log("\n\u{1F527} Generating SDK from OpenAPI...\n");
|
|
406
406
|
let config = null;
|
|
407
407
|
let openApiUrl;
|
|
@@ -412,18 +412,19 @@ async function generateSDK(root = process.cwd(), projectName) {
|
|
|
412
412
|
const workspace = module.default;
|
|
413
413
|
if (typeof workspace === "function") {
|
|
414
414
|
config = workspace("development");
|
|
415
|
-
|
|
415
|
+
if (config?.openapi_url) {
|
|
416
|
+
openApiUrl = config.openapi_url;
|
|
417
|
+
}
|
|
416
418
|
}
|
|
417
419
|
}
|
|
418
|
-
} catch
|
|
419
|
-
console.warn("\u26A0\uFE0F Could not load bgl.config.ts");
|
|
420
|
+
} catch {
|
|
420
421
|
}
|
|
421
422
|
const response = await prompts([
|
|
422
423
|
{
|
|
423
|
-
type: openApiUrl ? null : "text",
|
|
424
|
+
type: openApiUrl !== void 0 ? null : "text",
|
|
424
425
|
name: "openApiUrl",
|
|
425
426
|
message: "OpenAPI spec URL:",
|
|
426
|
-
initial: openApiUrl
|
|
427
|
+
initial: openApiUrl ?? "http://localhost:8000/openapi.json"
|
|
427
428
|
},
|
|
428
429
|
{
|
|
429
430
|
type: "text",
|
|
@@ -442,14 +443,14 @@ async function generateSDK(root = process.cwd(), projectName) {
|
|
|
442
443
|
console.log("\n\u274C SDK generation cancelled.\n");
|
|
443
444
|
process.exit(1);
|
|
444
445
|
}
|
|
445
|
-
const finalUrl = openApiUrl
|
|
446
|
+
const finalUrl = openApiUrl ?? response.openApiUrl;
|
|
446
447
|
const { outputDir, splitFiles } = response;
|
|
447
448
|
console.log(`
|
|
448
449
|
\u{1F4E1} Fetching OpenAPI spec from: ${finalUrl}`);
|
|
449
450
|
console.log(`\u{1F4C1} Output directory: ${outputDir}
|
|
450
451
|
`);
|
|
451
452
|
try {
|
|
452
|
-
const {
|
|
453
|
+
const { openAPI } = await import('@bagelink/sdk');
|
|
453
454
|
const { types, code } = await openAPI(finalUrl, "/api");
|
|
454
455
|
const outputPath = resolve(root, outputDir);
|
|
455
456
|
if (!existsSync(outputPath)) {
|
|
@@ -469,20 +470,8 @@ async function generateSDK(root = process.cwd(), projectName) {
|
|
|
469
470
|
console.log("\u2705 Generated index.ts");
|
|
470
471
|
if (splitFiles) {
|
|
471
472
|
console.log("\n\u{1F500} Splitting into organized files...");
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
await splitClientCode({
|
|
475
|
-
bagelinkDir: outputPath,
|
|
476
|
-
useDirectories: true
|
|
477
|
-
});
|
|
478
|
-
const fs = await import('node:fs');
|
|
479
|
-
fs.rmSync(apiPath, { force: true });
|
|
480
|
-
fs.rmSync(typesPath, { force: true });
|
|
481
|
-
fs.rmSync(indexPath, { force: true });
|
|
482
|
-
console.log("\u2705 Files organized into directories");
|
|
483
|
-
} catch (error) {
|
|
484
|
-
console.warn("\u26A0\uFE0F Could not split files, keeping monolithic structure");
|
|
485
|
-
}
|
|
473
|
+
console.log("\u2139\uFE0F File splitting requires @bagelink/sdk bin scripts");
|
|
474
|
+
console.log(" Keeping monolithic structure for now");
|
|
486
475
|
}
|
|
487
476
|
console.log("\n\u2705 SDK generated successfully!");
|
|
488
477
|
console.log(`
|
|
@@ -530,8 +519,8 @@ async function generateSDKForWorkspace(root = process.cwd()) {
|
|
|
530
519
|
const projectPath = resolve(root, project);
|
|
531
520
|
try {
|
|
532
521
|
await generateSDK(projectPath);
|
|
533
|
-
} catch
|
|
534
|
-
console.error(`Failed to generate SDK for ${project}
|
|
522
|
+
} catch {
|
|
523
|
+
console.error(`Failed to generate SDK for ${project}`);
|
|
535
524
|
}
|
|
536
525
|
}
|
|
537
526
|
console.log("\n\u2705 All SDKs generated!");
|
|
@@ -863,4 +852,54 @@ function listProjects(root = process.cwd()) {
|
|
|
863
852
|
}
|
|
864
853
|
}
|
|
865
854
|
|
|
866
|
-
|
|
855
|
+
function isWorkspace(root = process.cwd()) {
|
|
856
|
+
const packageJsonPath = resolve(root, "package.json");
|
|
857
|
+
if (existsSync(packageJsonPath)) {
|
|
858
|
+
try {
|
|
859
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
860
|
+
if (packageJson.workspaces !== void 0) {
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
} catch {
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
try {
|
|
867
|
+
const items = readdirSync(root, { withFileTypes: true });
|
|
868
|
+
const projectDirs = items.filter(
|
|
869
|
+
(item) => item.isDirectory() && item.name !== "node_modules" && item.name !== "shared" && item.name !== ".git" && !item.name.startsWith(".") && existsSync(resolve(root, item.name, "package.json"))
|
|
870
|
+
);
|
|
871
|
+
return projectDirs.length >= 2;
|
|
872
|
+
} catch {
|
|
873
|
+
return false;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
function getWorkspaceInfo(root = process.cwd()) {
|
|
877
|
+
const workspace = isWorkspace(root);
|
|
878
|
+
if (!workspace) {
|
|
879
|
+
return {
|
|
880
|
+
isWorkspace: false,
|
|
881
|
+
projects: [],
|
|
882
|
+
hasShared: false
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
try {
|
|
886
|
+
const items = readdirSync(root, { withFileTypes: true });
|
|
887
|
+
const projects = items.filter(
|
|
888
|
+
(item) => item.isDirectory() && item.name !== "node_modules" && item.name !== "shared" && item.name !== ".git" && !item.name.startsWith(".") && existsSync(resolve(root, item.name, "package.json"))
|
|
889
|
+
).map((item) => item.name);
|
|
890
|
+
const hasShared = existsSync(resolve(root, "shared"));
|
|
891
|
+
return {
|
|
892
|
+
isWorkspace: true,
|
|
893
|
+
projects,
|
|
894
|
+
hasShared
|
|
895
|
+
};
|
|
896
|
+
} catch {
|
|
897
|
+
return {
|
|
898
|
+
isWorkspace: false,
|
|
899
|
+
projects: [],
|
|
900
|
+
hasShared: false
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
export { generateNetlifyConfig as a, generateNetlifyRedirect as b, generateWorkspaceConfigSync as c, setupLint as d, generateSDK as e, generateSDKForWorkspace as f, generateWorkspaceConfig as g, addProject as h, initWorkspace as i, getWorkspaceInfo as j, isWorkspace as k, listProjects as l, setBuildEnvVars as s, writeNetlifyConfig as w };
|
|
@@ -408,7 +408,7 @@ function updatePackageJsonLint(root, configs) {
|
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
-
async function generateSDK(root = process__default.cwd()
|
|
411
|
+
async function generateSDK(root = process__default.cwd()) {
|
|
412
412
|
console.log("\n\u{1F527} Generating SDK from OpenAPI...\n");
|
|
413
413
|
let config = null;
|
|
414
414
|
let openApiUrl;
|
|
@@ -419,18 +419,19 @@ async function generateSDK(root = process__default.cwd(), projectName) {
|
|
|
419
419
|
const workspace = module.default;
|
|
420
420
|
if (typeof workspace === "function") {
|
|
421
421
|
config = workspace("development");
|
|
422
|
-
|
|
422
|
+
if (config?.openapi_url) {
|
|
423
|
+
openApiUrl = config.openapi_url;
|
|
424
|
+
}
|
|
423
425
|
}
|
|
424
426
|
}
|
|
425
|
-
} catch
|
|
426
|
-
console.warn("\u26A0\uFE0F Could not load bgl.config.ts");
|
|
427
|
+
} catch {
|
|
427
428
|
}
|
|
428
429
|
const response = await prompts__default([
|
|
429
430
|
{
|
|
430
|
-
type: openApiUrl ? null : "text",
|
|
431
|
+
type: openApiUrl !== void 0 ? null : "text",
|
|
431
432
|
name: "openApiUrl",
|
|
432
433
|
message: "OpenAPI spec URL:",
|
|
433
|
-
initial: openApiUrl
|
|
434
|
+
initial: openApiUrl ?? "http://localhost:8000/openapi.json"
|
|
434
435
|
},
|
|
435
436
|
{
|
|
436
437
|
type: "text",
|
|
@@ -449,14 +450,14 @@ async function generateSDK(root = process__default.cwd(), projectName) {
|
|
|
449
450
|
console.log("\n\u274C SDK generation cancelled.\n");
|
|
450
451
|
process__default.exit(1);
|
|
451
452
|
}
|
|
452
|
-
const finalUrl = openApiUrl
|
|
453
|
+
const finalUrl = openApiUrl ?? response.openApiUrl;
|
|
453
454
|
const { outputDir, splitFiles } = response;
|
|
454
455
|
console.log(`
|
|
455
456
|
\u{1F4E1} Fetching OpenAPI spec from: ${finalUrl}`);
|
|
456
457
|
console.log(`\u{1F4C1} Output directory: ${outputDir}
|
|
457
458
|
`);
|
|
458
459
|
try {
|
|
459
|
-
const {
|
|
460
|
+
const { openAPI } = await import('@bagelink/sdk');
|
|
460
461
|
const { types, code } = await openAPI(finalUrl, "/api");
|
|
461
462
|
const outputPath = node_path.resolve(root, outputDir);
|
|
462
463
|
if (!node_fs.existsSync(outputPath)) {
|
|
@@ -476,20 +477,8 @@ async function generateSDK(root = process__default.cwd(), projectName) {
|
|
|
476
477
|
console.log("\u2705 Generated index.ts");
|
|
477
478
|
if (splitFiles) {
|
|
478
479
|
console.log("\n\u{1F500} Splitting into organized files...");
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
await splitClientCode({
|
|
482
|
-
bagelinkDir: outputPath,
|
|
483
|
-
useDirectories: true
|
|
484
|
-
});
|
|
485
|
-
const fs = await import('node:fs');
|
|
486
|
-
fs.rmSync(apiPath, { force: true });
|
|
487
|
-
fs.rmSync(typesPath, { force: true });
|
|
488
|
-
fs.rmSync(indexPath, { force: true });
|
|
489
|
-
console.log("\u2705 Files organized into directories");
|
|
490
|
-
} catch (error) {
|
|
491
|
-
console.warn("\u26A0\uFE0F Could not split files, keeping monolithic structure");
|
|
492
|
-
}
|
|
480
|
+
console.log("\u2139\uFE0F File splitting requires @bagelink/sdk bin scripts");
|
|
481
|
+
console.log(" Keeping monolithic structure for now");
|
|
493
482
|
}
|
|
494
483
|
console.log("\n\u2705 SDK generated successfully!");
|
|
495
484
|
console.log(`
|
|
@@ -537,8 +526,8 @@ async function generateSDKForWorkspace(root = process__default.cwd()) {
|
|
|
537
526
|
const projectPath = node_path.resolve(root, project);
|
|
538
527
|
try {
|
|
539
528
|
await generateSDK(projectPath);
|
|
540
|
-
} catch
|
|
541
|
-
console.error(`Failed to generate SDK for ${project}
|
|
529
|
+
} catch {
|
|
530
|
+
console.error(`Failed to generate SDK for ${project}`);
|
|
542
531
|
}
|
|
543
532
|
}
|
|
544
533
|
console.log("\n\u2705 All SDKs generated!");
|
|
@@ -870,6 +859,56 @@ function listProjects(root = process__default.cwd()) {
|
|
|
870
859
|
}
|
|
871
860
|
}
|
|
872
861
|
|
|
862
|
+
function isWorkspace(root = process__default.cwd()) {
|
|
863
|
+
const packageJsonPath = node_path.resolve(root, "package.json");
|
|
864
|
+
if (node_fs.existsSync(packageJsonPath)) {
|
|
865
|
+
try {
|
|
866
|
+
const packageJson = JSON.parse(node_fs.readFileSync(packageJsonPath, "utf-8"));
|
|
867
|
+
if (packageJson.workspaces !== void 0) {
|
|
868
|
+
return true;
|
|
869
|
+
}
|
|
870
|
+
} catch {
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
try {
|
|
874
|
+
const items = node_fs.readdirSync(root, { withFileTypes: true });
|
|
875
|
+
const projectDirs = items.filter(
|
|
876
|
+
(item) => item.isDirectory() && item.name !== "node_modules" && item.name !== "shared" && item.name !== ".git" && !item.name.startsWith(".") && node_fs.existsSync(node_path.resolve(root, item.name, "package.json"))
|
|
877
|
+
);
|
|
878
|
+
return projectDirs.length >= 2;
|
|
879
|
+
} catch {
|
|
880
|
+
return false;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
function getWorkspaceInfo(root = process__default.cwd()) {
|
|
884
|
+
const workspace = isWorkspace(root);
|
|
885
|
+
if (!workspace) {
|
|
886
|
+
return {
|
|
887
|
+
isWorkspace: false,
|
|
888
|
+
projects: [],
|
|
889
|
+
hasShared: false
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
try {
|
|
893
|
+
const items = node_fs.readdirSync(root, { withFileTypes: true });
|
|
894
|
+
const projects = items.filter(
|
|
895
|
+
(item) => item.isDirectory() && item.name !== "node_modules" && item.name !== "shared" && item.name !== ".git" && !item.name.startsWith(".") && node_fs.existsSync(node_path.resolve(root, item.name, "package.json"))
|
|
896
|
+
).map((item) => item.name);
|
|
897
|
+
const hasShared = node_fs.existsSync(node_path.resolve(root, "shared"));
|
|
898
|
+
return {
|
|
899
|
+
isWorkspace: true,
|
|
900
|
+
projects,
|
|
901
|
+
hasShared
|
|
902
|
+
};
|
|
903
|
+
} catch {
|
|
904
|
+
return {
|
|
905
|
+
isWorkspace: false,
|
|
906
|
+
projects: [],
|
|
907
|
+
hasShared: false
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
873
912
|
exports.addProject = addProject;
|
|
874
913
|
exports.generateNetlifyConfig = generateNetlifyConfig;
|
|
875
914
|
exports.generateNetlifyRedirect = generateNetlifyRedirect;
|
|
@@ -877,7 +916,9 @@ exports.generateSDK = generateSDK;
|
|
|
877
916
|
exports.generateSDKForWorkspace = generateSDKForWorkspace;
|
|
878
917
|
exports.generateWorkspaceConfig = generateWorkspaceConfig;
|
|
879
918
|
exports.generateWorkspaceConfigSync = generateWorkspaceConfigSync;
|
|
919
|
+
exports.getWorkspaceInfo = getWorkspaceInfo;
|
|
880
920
|
exports.initWorkspace = initWorkspace;
|
|
921
|
+
exports.isWorkspace = isWorkspace;
|
|
881
922
|
exports.listProjects = listProjects;
|
|
882
923
|
exports.setBuildEnvVars = setBuildEnvVars;
|
|
883
924
|
exports.setupLint = setupLint;
|
package/package.json
CHANGED
package/src/detect.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import process from 'node:process'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Detect if current directory is a workspace root
|
|
7
|
+
*/
|
|
8
|
+
export function isWorkspace(root: string = process.cwd()): boolean {
|
|
9
|
+
// Check if package.json has workspaces field
|
|
10
|
+
const packageJsonPath = resolve(root, 'package.json')
|
|
11
|
+
if (existsSync(packageJsonPath)) {
|
|
12
|
+
try {
|
|
13
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
|
|
14
|
+
if (packageJson.workspaces !== undefined) {
|
|
15
|
+
return true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Ignore parse errors
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Check if there are multiple project directories
|
|
24
|
+
// (directories with their own package.json, excluding shared, node_modules, etc.)
|
|
25
|
+
try {
|
|
26
|
+
const items = readdirSync(root, { withFileTypes: true })
|
|
27
|
+
const projectDirs = items.filter(
|
|
28
|
+
item => item.isDirectory()
|
|
29
|
+
&& item.name !== 'node_modules'
|
|
30
|
+
&& item.name !== 'shared'
|
|
31
|
+
&& item.name !== '.git'
|
|
32
|
+
&& !item.name.startsWith('.')
|
|
33
|
+
&& existsSync(resolve(root, item.name, 'package.json')),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
// If we have 2+ project directories, it's likely a workspace
|
|
37
|
+
return projectDirs.length >= 2
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get workspace info
|
|
46
|
+
*/
|
|
47
|
+
export function getWorkspaceInfo(root: string = process.cwd()): {
|
|
48
|
+
isWorkspace: boolean
|
|
49
|
+
projects: string[]
|
|
50
|
+
hasShared: boolean
|
|
51
|
+
} {
|
|
52
|
+
const workspace = isWorkspace(root)
|
|
53
|
+
|
|
54
|
+
if (!workspace) {
|
|
55
|
+
return {
|
|
56
|
+
isWorkspace: false,
|
|
57
|
+
projects: [],
|
|
58
|
+
hasShared: false,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const items = readdirSync(root, { withFileTypes: true })
|
|
64
|
+
const projects = items
|
|
65
|
+
.filter(
|
|
66
|
+
item => item.isDirectory()
|
|
67
|
+
&& item.name !== 'node_modules'
|
|
68
|
+
&& item.name !== 'shared'
|
|
69
|
+
&& item.name !== '.git'
|
|
70
|
+
&& !item.name.startsWith('.')
|
|
71
|
+
&& existsSync(resolve(root, item.name, 'package.json')),
|
|
72
|
+
)
|
|
73
|
+
.map(item => item.name)
|
|
74
|
+
|
|
75
|
+
const hasShared = existsSync(resolve(root, 'shared'))
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
isWorkspace: true,
|
|
79
|
+
projects,
|
|
80
|
+
hasShared,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return {
|
|
85
|
+
isWorkspace: false,
|
|
86
|
+
projects: [],
|
|
87
|
+
hasShared: false,
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -37,6 +37,7 @@ export {
|
|
|
37
37
|
export { setupLint } from './lint'
|
|
38
38
|
export { generateSDK, generateSDKForWorkspace } from './sdk'
|
|
39
39
|
export { addProject, initWorkspace, listProjects } from './workspace'
|
|
40
|
+
export { getWorkspaceInfo, isWorkspace } from './detect'
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* Define workspace configuration
|
package/src/sdk.ts
CHANGED
|
@@ -9,7 +9,6 @@ import prompts from 'prompts'
|
|
|
9
9
|
*/
|
|
10
10
|
export async function generateSDK(
|
|
11
11
|
root: string = process.cwd(),
|
|
12
|
-
projectName?: string,
|
|
13
12
|
): Promise<void> {
|
|
14
13
|
console.log('\n🔧 Generating SDK from OpenAPI...\n')
|
|
15
14
|
|
|
@@ -24,21 +23,23 @@ export async function generateSDK(
|
|
|
24
23
|
const workspace = module.default
|
|
25
24
|
if (typeof workspace === 'function') {
|
|
26
25
|
config = workspace('development')
|
|
27
|
-
|
|
26
|
+
if (config?.openapi_url) {
|
|
27
|
+
openApiUrl = config.openapi_url
|
|
28
|
+
}
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
catch
|
|
32
|
-
|
|
32
|
+
catch {
|
|
33
|
+
// Ignore config load errors
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
// Prompt for missing info
|
|
36
37
|
const response = await prompts([
|
|
37
38
|
{
|
|
38
|
-
type: openApiUrl ? null : 'text',
|
|
39
|
+
type: openApiUrl !== undefined ? null : 'text',
|
|
39
40
|
name: 'openApiUrl',
|
|
40
41
|
message: 'OpenAPI spec URL:',
|
|
41
|
-
initial: openApiUrl
|
|
42
|
+
initial: openApiUrl ?? 'http://localhost:8000/openapi.json',
|
|
42
43
|
},
|
|
43
44
|
{
|
|
44
45
|
type: 'text',
|
|
@@ -59,7 +60,7 @@ export async function generateSDK(
|
|
|
59
60
|
process.exit(1)
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
const finalUrl = openApiUrl
|
|
63
|
+
const finalUrl = openApiUrl ?? response.openApiUrl
|
|
63
64
|
const { outputDir, splitFiles } = response
|
|
64
65
|
|
|
65
66
|
console.log(`\n📡 Fetching OpenAPI spec from: ${finalUrl}`)
|
|
@@ -67,7 +68,7 @@ export async function generateSDK(
|
|
|
67
68
|
|
|
68
69
|
try {
|
|
69
70
|
// Dynamic import of @bagelink/sdk
|
|
70
|
-
const {
|
|
71
|
+
const { openAPI } = await import('@bagelink/sdk')
|
|
71
72
|
|
|
72
73
|
const { types, code } = await openAPI(finalUrl, '/api')
|
|
73
74
|
|
|
@@ -96,22 +97,10 @@ export async function generateSDK(
|
|
|
96
97
|
|
|
97
98
|
if (splitFiles) {
|
|
98
99
|
console.log('\n🔀 Splitting into organized files...')
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
useDirectories: true,
|
|
104
|
-
})
|
|
105
|
-
// Clean up monolithic files
|
|
106
|
-
const fs = await import('node:fs')
|
|
107
|
-
fs.rmSync(apiPath, { force: true })
|
|
108
|
-
fs.rmSync(typesPath, { force: true })
|
|
109
|
-
fs.rmSync(indexPath, { force: true })
|
|
110
|
-
console.log('✅ Files organized into directories')
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
console.warn('⚠️ Could not split files, keeping monolithic structure')
|
|
114
|
-
}
|
|
100
|
+
console.log('ℹ️ File splitting requires @bagelink/sdk bin scripts')
|
|
101
|
+
console.log(' Keeping monolithic structure for now')
|
|
102
|
+
// Note: File splitting requires unpublished bin scripts
|
|
103
|
+
// Users can manually run: bunx bagelink generate
|
|
115
104
|
}
|
|
116
105
|
|
|
117
106
|
console.log('\n✅ SDK generated successfully!')
|
|
@@ -177,8 +166,8 @@ export async function generateSDKForWorkspace(root: string = process.cwd()): Pro
|
|
|
177
166
|
try {
|
|
178
167
|
await generateSDK(projectPath)
|
|
179
168
|
}
|
|
180
|
-
catch
|
|
181
|
-
console.error(`Failed to generate SDK for ${project}
|
|
169
|
+
catch {
|
|
170
|
+
console.error(`Failed to generate SDK for ${project}`)
|
|
182
171
|
}
|
|
183
172
|
}
|
|
184
173
|
|