@bagelink/workspace 1.8.7 → 1.8.9

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/dist/bin/bgl.cjs CHANGED
@@ -1142,37 +1142,71 @@ Import directly in your code:`);
1142
1142
  }
1143
1143
  }
1144
1144
  async function generateSDKForWorkspace(root = process__default.cwd()) {
1145
- console.log("\n\u{1F3E2} Generating SDK for workspace projects...\n");
1146
- const fs = await import('node:fs');
1147
- const items = fs.readdirSync(root, { withFileTypes: true });
1148
- const projects = items.filter(
1149
- (item) => item.isDirectory() && item.name !== "node_modules" && item.name !== "shared" && item.name !== ".git" && !item.name.startsWith(".")
1150
- ).map((item) => item.name);
1151
- if (projects.length === 0) {
1152
- console.log("No projects found in workspace");
1153
- return;
1145
+ console.log("\n\u{1F3E2} Generating SDK for workspace...\n");
1146
+ let config = null;
1147
+ let openApiUrl;
1148
+ try {
1149
+ const configPath = node_path.resolve(root, "bgl.config.ts");
1150
+ if (node_fs.existsSync(configPath)) {
1151
+ const module = await import(`file://${configPath}`);
1152
+ const workspace = module.default;
1153
+ if (typeof workspace === "function") {
1154
+ config = workspace("development");
1155
+ if (config?.openapi_url) {
1156
+ openApiUrl = config.openapi_url;
1157
+ }
1158
+ }
1159
+ }
1160
+ } catch {
1154
1161
  }
1155
1162
  const response = await prompts__default({
1156
- type: "multiselect",
1157
- name: "selectedProjects",
1158
- message: "Select projects to generate SDK for:",
1159
- choices: projects.map((p) => ({ title: p, value: p, selected: true }))
1163
+ type: openApiUrl !== void 0 ? null : "text",
1164
+ name: "openApiUrl",
1165
+ message: "OpenAPI spec URL:",
1166
+ initial: openApiUrl ?? "http://localhost:8000/openapi.json"
1160
1167
  });
1161
- if (!response || !response.selectedProjects || response.selectedProjects.length === 0) {
1162
- console.log("\n\u274C No projects selected.\n");
1163
- return;
1168
+ if (response === void 0 || openApiUrl === void 0 && !response.openApiUrl) {
1169
+ console.log("\n\u274C SDK generation cancelled.\n");
1170
+ process__default.exit(1);
1164
1171
  }
1165
- for (const project of response.selectedProjects) {
1172
+ const finalUrl = openApiUrl ?? response.openApiUrl;
1173
+ const outputDir = "./shared";
1174
+ console.log(`
1175
+ \u{1F4E1} Fetching OpenAPI spec from: ${finalUrl}`);
1176
+ console.log(`\u{1F4C1} Output directory: ${outputDir}
1177
+ `);
1178
+ try {
1179
+ const { openAPI } = await import('@bagelink/sdk');
1180
+ const { types, code } = await openAPI(finalUrl, "/api");
1181
+ const outputPath = node_path.resolve(root, outputDir);
1182
+ if (!node_fs.existsSync(outputPath)) {
1183
+ node_fs.mkdirSync(outputPath, { recursive: true });
1184
+ }
1185
+ const typesPath = node_path.resolve(outputPath, "types.d.ts");
1186
+ node_fs.writeFileSync(typesPath, types);
1187
+ console.log("\u2705 Generated types.d.ts");
1188
+ const apiPath = node_path.resolve(outputPath, "api.ts");
1189
+ node_fs.writeFileSync(apiPath, code);
1190
+ console.log("\u2705 Generated api.ts");
1191
+ console.log("\n\u2705 SDK generated successfully in shared folder!");
1166
1192
  console.log(`
1167
- \u{1F4E6} Generating SDK for: ${project}`);
1168
- const projectPath = node_path.resolve(root, project);
1169
- try {
1170
- await generateSDK(projectPath);
1171
- } catch {
1172
- console.error(`Failed to generate SDK for ${project}`);
1193
+ Import from shared in your projects:`);
1194
+ console.log(` import { agents } from '../shared/api'`);
1195
+ console.log(` import type { SendMessageRequest } from '../shared/types'`);
1196
+ console.log("");
1197
+ } catch (error) {
1198
+ console.error("\n\u274C Failed to generate SDK:");
1199
+ if (error instanceof Error) {
1200
+ console.error(error.message);
1201
+ } else {
1202
+ console.error(error);
1173
1203
  }
1204
+ console.log("\nMake sure:");
1205
+ console.log(" 1. @bagelink/sdk is installed: bun add -D @bagelink/sdk");
1206
+ console.log(" 2. OpenAPI URL is accessible");
1207
+ console.log(" 3. API server is running (if using localhost)");
1208
+ process__default.exit(1);
1174
1209
  }
1175
- console.log("\n\u2705 All SDKs generated!");
1176
1210
  }
1177
1211
 
1178
1212
  const [, , command, subcommand, ...args] = process__default.argv;
package/dist/bin/bgl.mjs CHANGED
@@ -1135,37 +1135,71 @@ Import directly in your code:`);
1135
1135
  }
1136
1136
  }
1137
1137
  async function generateSDKForWorkspace(root = process.cwd()) {
1138
- console.log("\n\u{1F3E2} Generating SDK for workspace projects...\n");
1139
- const fs = await import('node:fs');
1140
- const items = fs.readdirSync(root, { withFileTypes: true });
1141
- const projects = items.filter(
1142
- (item) => item.isDirectory() && item.name !== "node_modules" && item.name !== "shared" && item.name !== ".git" && !item.name.startsWith(".")
1143
- ).map((item) => item.name);
1144
- if (projects.length === 0) {
1145
- console.log("No projects found in workspace");
1146
- return;
1138
+ console.log("\n\u{1F3E2} Generating SDK for workspace...\n");
1139
+ let config = null;
1140
+ let openApiUrl;
1141
+ try {
1142
+ const configPath = resolve(root, "bgl.config.ts");
1143
+ if (existsSync(configPath)) {
1144
+ const module = await import(`file://${configPath}`);
1145
+ const workspace = module.default;
1146
+ if (typeof workspace === "function") {
1147
+ config = workspace("development");
1148
+ if (config?.openapi_url) {
1149
+ openApiUrl = config.openapi_url;
1150
+ }
1151
+ }
1152
+ }
1153
+ } catch {
1147
1154
  }
1148
1155
  const response = await prompts({
1149
- type: "multiselect",
1150
- name: "selectedProjects",
1151
- message: "Select projects to generate SDK for:",
1152
- choices: projects.map((p) => ({ title: p, value: p, selected: true }))
1156
+ type: openApiUrl !== void 0 ? null : "text",
1157
+ name: "openApiUrl",
1158
+ message: "OpenAPI spec URL:",
1159
+ initial: openApiUrl ?? "http://localhost:8000/openapi.json"
1153
1160
  });
1154
- if (!response || !response.selectedProjects || response.selectedProjects.length === 0) {
1155
- console.log("\n\u274C No projects selected.\n");
1156
- return;
1161
+ if (response === void 0 || openApiUrl === void 0 && !response.openApiUrl) {
1162
+ console.log("\n\u274C SDK generation cancelled.\n");
1163
+ process.exit(1);
1157
1164
  }
1158
- for (const project of response.selectedProjects) {
1165
+ const finalUrl = openApiUrl ?? response.openApiUrl;
1166
+ const outputDir = "./shared";
1167
+ console.log(`
1168
+ \u{1F4E1} Fetching OpenAPI spec from: ${finalUrl}`);
1169
+ console.log(`\u{1F4C1} Output directory: ${outputDir}
1170
+ `);
1171
+ try {
1172
+ const { openAPI } = await import('@bagelink/sdk');
1173
+ const { types, code } = await openAPI(finalUrl, "/api");
1174
+ const outputPath = resolve(root, outputDir);
1175
+ if (!existsSync(outputPath)) {
1176
+ mkdirSync(outputPath, { recursive: true });
1177
+ }
1178
+ const typesPath = resolve(outputPath, "types.d.ts");
1179
+ writeFileSync(typesPath, types);
1180
+ console.log("\u2705 Generated types.d.ts");
1181
+ const apiPath = resolve(outputPath, "api.ts");
1182
+ writeFileSync(apiPath, code);
1183
+ console.log("\u2705 Generated api.ts");
1184
+ console.log("\n\u2705 SDK generated successfully in shared folder!");
1159
1185
  console.log(`
1160
- \u{1F4E6} Generating SDK for: ${project}`);
1161
- const projectPath = resolve(root, project);
1162
- try {
1163
- await generateSDK(projectPath);
1164
- } catch {
1165
- console.error(`Failed to generate SDK for ${project}`);
1186
+ Import from shared in your projects:`);
1187
+ console.log(` import { agents } from '../shared/api'`);
1188
+ console.log(` import type { SendMessageRequest } from '../shared/types'`);
1189
+ console.log("");
1190
+ } catch (error) {
1191
+ console.error("\n\u274C Failed to generate SDK:");
1192
+ if (error instanceof Error) {
1193
+ console.error(error.message);
1194
+ } else {
1195
+ console.error(error);
1166
1196
  }
1197
+ console.log("\nMake sure:");
1198
+ console.log(" 1. @bagelink/sdk is installed: bun add -D @bagelink/sdk");
1199
+ console.log(" 2. OpenAPI URL is accessible");
1200
+ console.log(" 3. API server is running (if using localhost)");
1201
+ process.exit(1);
1167
1202
  }
1168
- console.log("\n\u2705 All SDKs generated!");
1169
1203
  }
1170
1204
 
1171
1205
  const [, , command, subcommand, ...args] = process.argv;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/workspace",
3
3
  "type": "module",
4
- "version": "1.8.7",
4
+ "version": "1.8.9",
5
5
  "description": "Monorepo workspace tooling for Bagel projects with proxy and config management",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
package/src/sdk.ts CHANGED
@@ -151,48 +151,87 @@ export async function generateSDK(
151
151
  * Generate SDK for all projects in workspace
152
152
  */
153
153
  export async function generateSDKForWorkspace(root: string = process.cwd()): Promise<void> {
154
- console.log('\nšŸ¢ Generating SDK for workspace projects...\n')
155
-
156
- // Find all projects
157
- const fs = await import('node:fs')
158
- const items = fs.readdirSync(root, { withFileTypes: true })
159
- const projects = items
160
- .filter(
161
- item => item.isDirectory()
162
- && item.name !== 'node_modules'
163
- && item.name !== 'shared'
164
- && item.name !== '.git'
165
- && !item.name.startsWith('.'),
166
- )
167
- .map(item => item.name)
168
-
169
- if (projects.length === 0) {
170
- console.log('No projects found in workspace')
171
- return
154
+ console.log('\nšŸ¢ Generating SDK for workspace...\n')
155
+
156
+ // Try to load config
157
+ let config: WorkspaceConfig | null = null
158
+ let openApiUrl: string | undefined
159
+
160
+ try {
161
+ const configPath = resolve(root, 'bgl.config.ts')
162
+ if (existsSync(configPath)) {
163
+ const module = await import(`file://${configPath}`)
164
+ const workspace = module.default
165
+ if (typeof workspace === 'function') {
166
+ config = workspace('development')
167
+ if (config?.openapi_url) {
168
+ openApiUrl = config.openapi_url
169
+ }
170
+ }
171
+ }
172
+ }
173
+ catch {
174
+ // Ignore config load errors
172
175
  }
173
176
 
177
+ // Prompt for OpenAPI URL if not in config
174
178
  const response = await prompts({
175
- type: 'multiselect',
176
- name: 'selectedProjects',
177
- message: 'Select projects to generate SDK for:',
178
- choices: projects.map(p => ({ title: p, value: p, selected: true })),
179
+ type: openApiUrl !== undefined ? null : 'text',
180
+ name: 'openApiUrl',
181
+ message: 'OpenAPI spec URL:',
182
+ initial: openApiUrl ?? 'http://localhost:8000/openapi.json',
179
183
  })
180
184
 
181
- if (!response || !response.selectedProjects || response.selectedProjects.length === 0) {
182
- console.log('\nāŒ No projects selected.\n')
183
- return
185
+ if (response === undefined || (openApiUrl === undefined && !response.openApiUrl)) {
186
+ console.log('\nāŒ SDK generation cancelled.\n')
187
+ process.exit(1)
184
188
  }
185
189
 
186
- for (const project of response.selectedProjects) {
187
- console.log(`\nšŸ“¦ Generating SDK for: ${project}`)
188
- const projectPath = resolve(root, project)
189
- try {
190
- await generateSDK(projectPath)
190
+ const finalUrl = openApiUrl ?? response.openApiUrl
191
+ const outputDir = './shared'
192
+
193
+ console.log(`\nšŸ“” Fetching OpenAPI spec from: ${finalUrl}`)
194
+ console.log(`šŸ“ Output directory: ${outputDir}\n`)
195
+
196
+ try {
197
+ // Dynamic import of @bagelink/sdk
198
+ const { openAPI } = await import('@bagelink/sdk')
199
+
200
+ const { types, code } = await openAPI(finalUrl, '/api')
201
+
202
+ const outputPath = resolve(root, outputDir)
203
+ if (!existsSync(outputPath)) {
204
+ mkdirSync(outputPath, { recursive: true })
191
205
  }
192
- catch {
193
- console.error(`Failed to generate SDK for ${project}`)
206
+
207
+ // Write types
208
+ const typesPath = resolve(outputPath, 'types.d.ts')
209
+ writeFileSync(typesPath, types)
210
+ console.log('āœ… Generated types.d.ts')
211
+
212
+ // Write API client
213
+ const apiPath = resolve(outputPath, 'api.ts')
214
+ writeFileSync(apiPath, code)
215
+ console.log('āœ… Generated api.ts')
216
+
217
+ console.log('\nāœ… SDK generated successfully in shared folder!')
218
+ console.log(`\nImport from shared in your projects:`)
219
+ console.log(` import { agents } from '../shared/api'`)
220
+ console.log(` import type { SendMessageRequest } from '../shared/types'`)
221
+ console.log('')
222
+ }
223
+ catch (error: unknown) {
224
+ console.error('\nāŒ Failed to generate SDK:')
225
+ if (error instanceof Error) {
226
+ console.error(error.message)
194
227
  }
228
+ else {
229
+ console.error(error)
230
+ }
231
+ console.log('\nMake sure:')
232
+ console.log(' 1. @bagelink/sdk is installed: bun add -D @bagelink/sdk')
233
+ console.log(' 2. OpenAPI URL is accessible')
234
+ console.log(' 3. API server is running (if using localhost)')
235
+ process.exit(1)
195
236
  }
196
-
197
- console.log('\nāœ… All SDKs generated!')
198
237
  }