@bagelink/workspace 1.10.0 → 1.10.1

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 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
- **For workspace:**
307
+ **Auto-detects workspace:**
308
308
  ```bash
309
- bgl lint init --workspace
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
- Sets up linting at workspace root level for all projects.
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
- **For workspace:**
363
+ **Auto-detects workspace:**
350
364
  ```bash
351
- bgl sdk generate --workspace
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
- Generates SDK for multiple projects from their respective `openapi_url` configs.
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,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import process from 'node:process'
3
3
  import { generateWorkspaceConfig } from '../src/init.js'
4
+ import { isWorkspace } from '../src/detect.js'
4
5
  import { setupLint } from '../src/lint.js'
5
6
  import { generateSDK, generateSDKForWorkspace } from '../src/sdk.js'
6
7
  import { addProject, initWorkspace, listProjects } from '../src/workspace.js'
@@ -39,22 +40,42 @@ async function main() {
39
40
  }
40
41
  else if (command === 'lint') {
41
42
  if (subcommand === 'init') {
42
- const isWorkspace = args.includes('--workspace') || args.includes('-w')
43
- await setupLint(process.cwd(), isWorkspace)
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()
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 in current project
49
- bgl lint init --workspace Set up linting for workspace root
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
- const isWorkspace = args.includes('--workspace') || args.includes('-w')
57
- if (isWorkspace) {
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()
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 {
@@ -65,8 +86,9 @@ Lint Commands:
65
86
  else {
66
87
  console.log(`
67
88
  SDK Commands:
68
- bgl sdk generate Generate SDK from OpenAPI spec
69
- bgl sdk generate --workspace Generate SDK for all workspace projects
89
+ bgl sdk generate Generate SDK (auto-detects workspace)
90
+ bgl sdk generate --workspace Force workspace mode
91
+ bgl sdk generate --project Force single project mode
70
92
  `)
71
93
  process.exit(1)
72
94
  }
@@ -76,17 +98,19 @@ SDK Commands:
76
98
  Bagel Workspace CLI
77
99
 
78
100
  Usage:
79
- bgl init Generate bgl.config.ts for single project
80
- bgl init --workspace Create a new workspace with multiple projects
81
- bgl add <name> Add a new project to workspace
82
- bgl list List all projects in workspace
83
- bgl lint init Set up linting in current project
84
- bgl lint init --workspace Set up linting for workspace root
85
- bgl sdk generate Generate SDK from OpenAPI spec
86
- bgl sdk generate --workspace Generate SDK for all workspace projects
101
+ bgl init Generate bgl.config.ts for single project
102
+ bgl init --workspace Create a new workspace with multiple projects
103
+ bgl add <name> Add a new project to workspace
104
+ bgl list List all projects in workspace
105
+ bgl lint init Set up linting (auto-detects workspace)
106
+ bgl sdk generate Generate SDK (auto-detects workspace)
87
107
 
88
108
  Options:
89
- --help, -h Show this help message
109
+ --workspace, -w Force workspace mode
110
+ --project, -p Force single project mode
111
+ --help, -h Show this help message
112
+
113
+ Note: Commands auto-detect workspace mode based on directory structure
90
114
  `)
91
115
  process.exit(command === '--help' || command === '-h' ? 0 : 1)
92
116
  }
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 workspace = require('../shared/workspace.dQE-K3dI.cjs');
5
+ const detect = require('../shared/workspace.Ndvn7T1u.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 isWorkspace = args.includes("--workspace") || args.includes("-w");
18
- if (isWorkspace) {
19
- await workspace.initWorkspace();
17
+ const isWorkspace2 = args.includes("--workspace") || args.includes("-w");
18
+ if (isWorkspace2) {
19
+ await detect.initWorkspace();
20
20
  } else {
21
- await workspace.generateWorkspaceConfig();
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 workspace.addProject(projectName);
30
+ await detect.addProject(projectName);
31
31
  } else if (command === "list") {
32
- const projects = workspace.listProjects();
32
+ const projects = detect.listProjects();
33
33
  if (projects.length === 0) {
34
34
  console.log("No projects found");
35
35
  } else {
@@ -41,30 +41,44 @@ async function main() {
41
41
  }
42
42
  } else if (command === "lint") {
43
43
  if (subcommand === "init") {
44
- const isWorkspace = args.includes("--workspace") || args.includes("-w");
45
- await workspace.setupLint(process__default.cwd(), isWorkspace);
44
+ const forceWorkspace = args.includes("--workspace") || args.includes("-w");
45
+ const forceProject = args.includes("--project") || args.includes("-p");
46
+ let workspaceMode = detect.isWorkspace();
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 in current project
50
- bgl lint init --workspace Set up linting for workspace root
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 isWorkspace = args.includes("--workspace") || args.includes("-w");
57
- if (isWorkspace) {
58
- await workspace.generateSDKForWorkspace();
64
+ const forceWorkspace = args.includes("--workspace") || args.includes("-w");
65
+ const forceProject = args.includes("--project") || args.includes("-p");
66
+ let workspaceMode = detect.isWorkspace();
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
73
  args.find((arg) => !arg.startsWith("-"));
61
- await workspace.generateSDK(process__default.cwd());
74
+ await detect.generateSDK(process__default.cwd());
62
75
  }
63
76
  } else {
64
77
  console.log(`
65
78
  SDK Commands:
66
- bgl sdk generate Generate SDK from OpenAPI spec
67
- bgl sdk generate --workspace Generate SDK for all workspace projects
79
+ bgl sdk generate Generate SDK (auto-detects workspace)
80
+ bgl sdk generate --workspace Force workspace mode
81
+ bgl sdk generate --project Force single project mode
68
82
  `);
69
83
  process__default.exit(1);
70
84
  }
@@ -73,17 +87,19 @@ SDK Commands:
73
87
  Bagel Workspace CLI
74
88
 
75
89
  Usage:
76
- bgl init Generate bgl.config.ts for single project
77
- bgl init --workspace Create a new workspace with multiple projects
78
- bgl add <name> Add a new project to workspace
79
- bgl list List all projects in workspace
80
- bgl lint init Set up linting in current project
81
- bgl lint init --workspace Set up linting for workspace root
82
- bgl sdk generate Generate SDK from OpenAPI spec
83
- bgl sdk generate --workspace Generate SDK for all workspace projects
90
+ bgl init Generate bgl.config.ts for single project
91
+ bgl init --workspace Create a new workspace with multiple projects
92
+ bgl add <name> Add a new project to workspace
93
+ bgl list List all projects in workspace
94
+ bgl lint init Set up linting (auto-detects workspace)
95
+ bgl sdk generate Generate SDK (auto-detects workspace)
84
96
 
85
97
  Options:
86
- --help, -h Show this help message
98
+ --workspace, -w Force workspace mode
99
+ --project, -p Force single project mode
100
+ --help, -h Show this help message
101
+
102
+ Note: Commands auto-detect workspace mode based on directory structure
87
103
  `);
88
104
  process__default.exit(command === "--help" || command === "-h" ? 0 : 1);
89
105
  }
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.CTMBmbXa.mjs';
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.B6LGs4Ed.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 isWorkspace = args.includes("--workspace") || args.includes("-w");
12
- if (isWorkspace) {
11
+ const isWorkspace2 = args.includes("--workspace") || args.includes("-w");
12
+ if (isWorkspace2) {
13
13
  await initWorkspace();
14
14
  } else {
15
15
  await generateWorkspaceConfig();
@@ -35,20 +35,33 @@ async function main() {
35
35
  }
36
36
  } else if (command === "lint") {
37
37
  if (subcommand === "init") {
38
- const isWorkspace = args.includes("--workspace") || args.includes("-w");
39
- await setupLint(process.cwd(), isWorkspace);
38
+ const forceWorkspace = args.includes("--workspace") || args.includes("-w");
39
+ const forceProject = args.includes("--project") || args.includes("-p");
40
+ let workspaceMode = isWorkspace();
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 in current project
44
- bgl lint init --workspace Set up linting for workspace root
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 isWorkspace = args.includes("--workspace") || args.includes("-w");
51
- if (isWorkspace) {
58
+ const forceWorkspace = args.includes("--workspace") || args.includes("-w");
59
+ const forceProject = args.includes("--project") || args.includes("-p");
60
+ let workspaceMode = isWorkspace();
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
67
  args.find((arg) => !arg.startsWith("-"));
@@ -57,8 +70,9 @@ Lint Commands:
57
70
  } else {
58
71
  console.log(`
59
72
  SDK Commands:
60
- bgl sdk generate Generate SDK from OpenAPI spec
61
- bgl sdk generate --workspace Generate SDK for all workspace projects
73
+ bgl sdk generate Generate SDK (auto-detects workspace)
74
+ bgl sdk generate --workspace Force workspace mode
75
+ bgl sdk generate --project Force single project mode
62
76
  `);
63
77
  process.exit(1);
64
78
  }
@@ -67,17 +81,19 @@ SDK Commands:
67
81
  Bagel Workspace CLI
68
82
 
69
83
  Usage:
70
- bgl init Generate bgl.config.ts for single project
71
- bgl init --workspace Create a new workspace with multiple projects
72
- bgl add <name> Add a new project to workspace
73
- bgl list List all projects in workspace
74
- bgl lint init Set up linting in current project
75
- bgl lint init --workspace Set up linting for workspace root
76
- bgl sdk generate Generate SDK from OpenAPI spec
77
- bgl sdk generate --workspace Generate SDK for all workspace projects
84
+ bgl init Generate bgl.config.ts for single project
85
+ bgl init --workspace Create a new workspace with multiple projects
86
+ bgl add <name> Add a new project to workspace
87
+ bgl list List all projects in workspace
88
+ bgl lint init Set up linting (auto-detects workspace)
89
+ bgl sdk generate Generate SDK (auto-detects workspace)
78
90
 
79
91
  Options:
80
- --help, -h Show this help message
92
+ --workspace, -w Force workspace mode
93
+ --project, -p Force single project mode
94
+ --help, -h Show this help message
95
+
96
+ Note: Commands auto-detect workspace mode based on directory structure
81
97
  `);
82
98
  process.exit(command === "--help" || command === "-h" ? 0 : 1);
83
99
  }
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 workspace = require('./shared/workspace.dQE-K3dI.cjs');
6
+ const detect = require('./shared/workspace.Ndvn7T1u.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 workspace.generateWorkspaceConfig(root, configFile);
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
- workspace.writeNetlifyConfig(config, outPath, additionalConfig);
134
+ detect.writeNetlifyConfig(config, outPath, additionalConfig);
135
135
  },
136
136
  /**
137
137
  * Set build environment variables
138
138
  */
139
139
  setBuildEnv(config) {
140
- workspace.setBuildEnvVars(config);
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 = workspace.addProject;
152
- exports.generateNetlifyConfig = workspace.generateNetlifyConfig;
153
- exports.generateNetlifyRedirect = workspace.generateNetlifyRedirect;
154
- exports.generateSDK = workspace.generateSDK;
155
- exports.generateSDKForWorkspace = workspace.generateSDKForWorkspace;
156
- exports.generateWorkspaceConfig = workspace.generateWorkspaceConfig;
157
- exports.generateWorkspaceConfigSync = workspace.generateWorkspaceConfigSync;
158
- exports.initWorkspace = workspace.initWorkspace;
159
- exports.listProjects = workspace.listProjects;
160
- exports.setBuildEnvVars = workspace.setBuildEnvVars;
161
- exports.setupLint = workspace.setupLint;
162
- exports.writeNetlifyConfig = workspace.writeNetlifyConfig;
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
@@ -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
@@ -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
@@ -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.CTMBmbXa.mjs';
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.CTMBmbXa.mjs';
4
+ import { g as generateWorkspaceConfig, s as setBuildEnvVars, w as writeNetlifyConfig } from './shared/workspace.B6LGs4Ed.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.B6LGs4Ed.mjs';
6
6
  import 'prompts';
7
7
 
8
8
  async function resolveConfig(mode = "development", options = {}) {
@@ -1,6 +1,6 @@
1
1
  import { writeFileSync, existsSync, readFileSync, mkdirSync, readdirSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
- import process from 'node:process';
3
+ import process$1 from 'node:process';
4
4
  import prompts from 'prompts';
5
5
 
6
6
  function generateNetlifyRedirect(config) {
@@ -28,14 +28,14 @@ function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig
28
28
  console.log(`\u2713 Generated netlify.toml at ${resolvedPath}`);
29
29
  }
30
30
  function setBuildEnvVars(config) {
31
- process.env.BGL_PROXY_PATH = config.proxy;
32
- process.env.BGL_API_HOST = config.host;
31
+ process$1.env.BGL_PROXY_PATH = config.proxy;
32
+ process$1.env.BGL_API_HOST = config.host;
33
33
  if (config.openapi_url !== void 0 && config.openapi_url !== "") {
34
- process.env.BGL_OPENAPI_URL = config.openapi_url;
34
+ process$1.env.BGL_OPENAPI_URL = config.openapi_url;
35
35
  }
36
36
  }
37
37
 
38
- async function generateWorkspaceConfig(root = process.cwd(), configFile = "bgl.config.ts") {
38
+ async function generateWorkspaceConfig(root = process$1.cwd(), configFile = "bgl.config.ts") {
39
39
  console.log("\n\u{1F527} No bgl.config.ts found. Let's create one!\n");
40
40
  const response = await prompts([
41
41
  {
@@ -60,7 +60,7 @@ async function generateWorkspaceConfig(root = process.cwd(), configFile = "bgl.c
60
60
  ]);
61
61
  if (!response || !response.projectId) {
62
62
  console.log("\n\u274C Config generation cancelled.\n");
63
- process.exit(1);
63
+ process$1.exit(1);
64
64
  }
65
65
  const productionHost = response.useCustomHost === true ? response.customHost : `https://${response.projectId}.bagel.to`;
66
66
  const configContent = `import { defineWorkspace } from '@bagelink/workspace'
@@ -128,7 +128,7 @@ export default defineWorkspace(configs)
128
128
  }
129
129
  console.log("\n\u{1F4A1} You can edit these files to customize your configuration.\n");
130
130
  }
131
- function generateWorkspaceConfigSync(projectId, root = process.cwd(), configFile = "bgl.config.ts", customHost) {
131
+ function generateWorkspaceConfigSync(projectId, root = process$1.cwd(), configFile = "bgl.config.ts", customHost) {
132
132
  const productionHost = customHost ?? `https://${projectId}.bagel.to`;
133
133
  const configContent = `import { defineWorkspace } from '@bagelink/workspace'
134
134
  import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
@@ -231,7 +231,7 @@ export default defineConfig(({ mode }) => {
231
231
  console.log("\u2705 Created vite.config.ts");
232
232
  }
233
233
 
234
- async function setupLint(root = process.cwd(), isWorkspace = false) {
234
+ async function setupLint(root = process$1.cwd(), isWorkspace = false) {
235
235
  console.log("\n\u{1F50D} Setting up linting...\n");
236
236
  const response = await prompts([
237
237
  {
@@ -254,7 +254,7 @@ async function setupLint(root = process.cwd(), isWorkspace = false) {
254
254
  ]);
255
255
  if (!response || !response.configs) {
256
256
  console.log("\n\u274C Setup cancelled.\n");
257
- process.exit(1);
257
+ process$1.exit(1);
258
258
  }
259
259
  const { configs, installDeps } = response;
260
260
  if (configs.includes("eslint")) {
@@ -401,7 +401,7 @@ function updatePackageJsonLint(root, configs) {
401
401
  }
402
402
  }
403
403
 
404
- async function generateSDK(root = process.cwd(), projectName) {
404
+ async function generateSDK(root = process$1.cwd(), projectName) {
405
405
  console.log("\n\u{1F527} Generating SDK from OpenAPI...\n");
406
406
  let config = null;
407
407
  let openApiUrl;
@@ -440,7 +440,7 @@ async function generateSDK(root = process.cwd(), projectName) {
440
440
  ]);
441
441
  if (!response) {
442
442
  console.log("\n\u274C SDK generation cancelled.\n");
443
- process.exit(1);
443
+ process$1.exit(1);
444
444
  }
445
445
  const finalUrl = openApiUrl || response.openApiUrl;
446
446
  const { outputDir, splitFiles } = response;
@@ -500,10 +500,10 @@ Import it in your code:`);
500
500
  console.log(" 1. @bagelink/sdk is installed: bun add -D @bagelink/sdk");
501
501
  console.log(" 2. OpenAPI URL is accessible");
502
502
  console.log(" 3. API server is running (if using localhost)");
503
- process.exit(1);
503
+ process$1.exit(1);
504
504
  }
505
505
  }
506
- async function generateSDKForWorkspace(root = process.cwd()) {
506
+ async function generateSDKForWorkspace(root = process$1.cwd()) {
507
507
  console.log("\n\u{1F3E2} Generating SDK for workspace projects...\n");
508
508
  const fs = await import('node:fs');
509
509
  const items = fs.readdirSync(root, { withFileTypes: true });
@@ -537,7 +537,7 @@ async function generateSDKForWorkspace(root = process.cwd()) {
537
537
  console.log("\n\u2705 All SDKs generated!");
538
538
  }
539
539
 
540
- async function initWorkspace(root = process.cwd()) {
540
+ async function initWorkspace(root = process$1.cwd()) {
541
541
  console.log("\n\u{1F680} Creating Bagel workspace...\n");
542
542
  const response = await prompts([
543
543
  {
@@ -567,7 +567,7 @@ async function initWorkspace(root = process.cwd()) {
567
567
  ]);
568
568
  if (!response || !response.workspaceName) {
569
569
  console.log("\n\u274C Workspace creation cancelled.\n");
570
- process.exit(1);
570
+ process$1.exit(1);
571
571
  }
572
572
  const { workspaceName, projectId, createFirstProject, firstProjectName } = response;
573
573
  createWorkspaceRoot(root, workspaceName, projectId);
@@ -590,7 +590,7 @@ function createWorkspaceRoot(root, name, projectId) {
590
590
  const workspaceDir = resolve(root, name);
591
591
  if (existsSync(workspaceDir)) {
592
592
  console.error(`\u274C Directory ${name} already exists`);
593
- process.exit(1);
593
+ process$1.exit(1);
594
594
  }
595
595
  mkdirSync(workspaceDir, { recursive: true });
596
596
  const packageJson = {
@@ -706,11 +706,11 @@ function createSharedPackage(root) {
706
706
  );
707
707
  console.log("\u2705 Created shared package");
708
708
  }
709
- async function addProject(name, root = process.cwd()) {
709
+ async function addProject(name, root = process$1.cwd()) {
710
710
  const projectDir = resolve(root, name);
711
711
  if (existsSync(projectDir)) {
712
712
  console.error(`\u274C Project ${name} already exists`);
713
- process.exit(1);
713
+ process$1.exit(1);
714
714
  }
715
715
  console.log(`
716
716
  \u{1F4E6} Creating project: ${name}
@@ -852,7 +852,7 @@ function updateWorkspaceScripts(root, projectName) {
852
852
  console.warn("\u26A0\uFE0F Could not update workspace scripts");
853
853
  }
854
854
  }
855
- function listProjects(root = process.cwd()) {
855
+ function listProjects(root = process$1.cwd()) {
856
856
  try {
857
857
  const items = readdirSync(root, { withFileTypes: true });
858
858
  return items.filter(
@@ -863,4 +863,54 @@ function listProjects(root = process.cwd()) {
863
863
  }
864
864
  }
865
865
 
866
- 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, listProjects as l, setBuildEnvVars as s, writeNetlifyConfig as w };
866
+ function isWorkspace(root = process.cwd()) {
867
+ const packageJsonPath = resolve(root, "package.json");
868
+ if (existsSync(packageJsonPath)) {
869
+ try {
870
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
871
+ if (packageJson.workspaces) {
872
+ return true;
873
+ }
874
+ } catch {
875
+ }
876
+ }
877
+ try {
878
+ const items = readdirSync(root, { withFileTypes: true });
879
+ const projectDirs = items.filter(
880
+ (item) => item.isDirectory() && item.name !== "node_modules" && item.name !== "shared" && item.name !== ".git" && !item.name.startsWith(".") && existsSync(resolve(root, item.name, "package.json"))
881
+ );
882
+ return projectDirs.length >= 2;
883
+ } catch {
884
+ return false;
885
+ }
886
+ }
887
+ function getWorkspaceInfo(root = process.cwd()) {
888
+ const workspace = isWorkspace(root);
889
+ if (!workspace) {
890
+ return {
891
+ isWorkspace: false,
892
+ projects: [],
893
+ hasShared: false
894
+ };
895
+ }
896
+ try {
897
+ const items = readdirSync(root, { withFileTypes: true });
898
+ const projects = items.filter(
899
+ (item) => item.isDirectory() && item.name !== "node_modules" && item.name !== "shared" && item.name !== ".git" && !item.name.startsWith(".") && existsSync(resolve(root, item.name, "package.json"))
900
+ ).map((item) => item.name);
901
+ const hasShared = existsSync(resolve(root, "shared"));
902
+ return {
903
+ isWorkspace: true,
904
+ projects,
905
+ hasShared
906
+ };
907
+ } catch {
908
+ return {
909
+ isWorkspace: false,
910
+ projects: [],
911
+ hasShared: false
912
+ };
913
+ }
914
+ }
915
+
916
+ 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 };
@@ -2,12 +2,12 @@
2
2
 
3
3
  const node_fs = require('node:fs');
4
4
  const node_path = require('node:path');
5
- const process = require('node:process');
5
+ const process$1 = require('node:process');
6
6
  const prompts = require('prompts');
7
7
 
8
8
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
9
9
 
10
- const process__default = /*#__PURE__*/_interopDefaultCompat(process);
10
+ const process__default = /*#__PURE__*/_interopDefaultCompat(process$1);
11
11
  const prompts__default = /*#__PURE__*/_interopDefaultCompat(prompts);
12
12
 
13
13
  function generateNetlifyRedirect(config) {
@@ -870,6 +870,56 @@ function listProjects(root = process__default.cwd()) {
870
870
  }
871
871
  }
872
872
 
873
+ function isWorkspace(root = process.cwd()) {
874
+ const packageJsonPath = node_path.resolve(root, "package.json");
875
+ if (node_fs.existsSync(packageJsonPath)) {
876
+ try {
877
+ const packageJson = JSON.parse(node_fs.readFileSync(packageJsonPath, "utf-8"));
878
+ if (packageJson.workspaces) {
879
+ return true;
880
+ }
881
+ } catch {
882
+ }
883
+ }
884
+ try {
885
+ const items = node_fs.readdirSync(root, { withFileTypes: true });
886
+ const projectDirs = items.filter(
887
+ (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"))
888
+ );
889
+ return projectDirs.length >= 2;
890
+ } catch {
891
+ return false;
892
+ }
893
+ }
894
+ function getWorkspaceInfo(root = process.cwd()) {
895
+ const workspace = isWorkspace(root);
896
+ if (!workspace) {
897
+ return {
898
+ isWorkspace: false,
899
+ projects: [],
900
+ hasShared: false
901
+ };
902
+ }
903
+ try {
904
+ const items = node_fs.readdirSync(root, { withFileTypes: true });
905
+ const projects = items.filter(
906
+ (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"))
907
+ ).map((item) => item.name);
908
+ const hasShared = node_fs.existsSync(node_path.resolve(root, "shared"));
909
+ return {
910
+ isWorkspace: true,
911
+ projects,
912
+ hasShared
913
+ };
914
+ } catch {
915
+ return {
916
+ isWorkspace: false,
917
+ projects: [],
918
+ hasShared: false
919
+ };
920
+ }
921
+ }
922
+
873
923
  exports.addProject = addProject;
874
924
  exports.generateNetlifyConfig = generateNetlifyConfig;
875
925
  exports.generateNetlifyRedirect = generateNetlifyRedirect;
@@ -877,7 +927,9 @@ exports.generateSDK = generateSDK;
877
927
  exports.generateSDKForWorkspace = generateSDKForWorkspace;
878
928
  exports.generateWorkspaceConfig = generateWorkspaceConfig;
879
929
  exports.generateWorkspaceConfigSync = generateWorkspaceConfigSync;
930
+ exports.getWorkspaceInfo = getWorkspaceInfo;
880
931
  exports.initWorkspace = initWorkspace;
932
+ exports.isWorkspace = isWorkspace;
881
933
  exports.listProjects = listProjects;
882
934
  exports.setBuildEnvVars = setBuildEnvVars;
883
935
  exports.setupLint = setupLint;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/workspace",
3
3
  "type": "module",
4
- "version": "1.10.0",
4
+ "version": "1.10.1",
5
5
  "description": "Monorepo workspace tooling for Bagel projects with proxy and config management",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
package/src/detect.ts ADDED
@@ -0,0 +1,91 @@
1
+ import { existsSync, readdirSync, readFileSync } from 'node:fs'
2
+ import { resolve } from 'node:path'
3
+
4
+ /**
5
+ * Detect if current directory is a workspace root
6
+ */
7
+ export function isWorkspace(root: string = process.cwd()): boolean {
8
+ // Check if package.json has workspaces field
9
+ const packageJsonPath = resolve(root, 'package.json')
10
+ if (existsSync(packageJsonPath)) {
11
+ try {
12
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
13
+ if (packageJson.workspaces) {
14
+ return true
15
+ }
16
+ }
17
+ catch {
18
+ // Ignore parse errors
19
+ }
20
+ }
21
+
22
+ // Check if there are multiple project directories
23
+ // (directories with their own package.json, excluding shared, node_modules, etc.)
24
+ try {
25
+ const items = readdirSync(root, { withFileTypes: true })
26
+ const projectDirs = items.filter(
27
+ item =>
28
+ 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 =>
67
+ item.isDirectory()
68
+ && item.name !== 'node_modules'
69
+ && item.name !== 'shared'
70
+ && item.name !== '.git'
71
+ && !item.name.startsWith('.')
72
+ && existsSync(resolve(root, item.name, 'package.json')),
73
+ )
74
+ .map(item => item.name)
75
+
76
+ const hasShared = existsSync(resolve(root, 'shared'))
77
+
78
+ return {
79
+ isWorkspace: true,
80
+ projects,
81
+ hasShared,
82
+ }
83
+ }
84
+ catch {
85
+ return {
86
+ isWorkspace: false,
87
+ projects: [],
88
+ hasShared: false,
89
+ }
90
+ }
91
+ }
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