@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 +58 -24
- package/dist/bin/bgl.mjs +58 -24
- package/package.json +1 -1
- package/src/sdk.ts +73 -34
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
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
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: "
|
|
1157
|
-
name: "
|
|
1158
|
-
message: "
|
|
1159
|
-
|
|
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 (
|
|
1162
|
-
console.log("\n\u274C
|
|
1163
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
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
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
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: "
|
|
1150
|
-
name: "
|
|
1151
|
-
message: "
|
|
1152
|
-
|
|
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 (
|
|
1155
|
-
console.log("\n\u274C
|
|
1156
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
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
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
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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: '
|
|
176
|
-
name: '
|
|
177
|
-
message: '
|
|
178
|
-
|
|
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 (
|
|
182
|
-
console.log('\nā
|
|
183
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
193
|
-
|
|
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
|
}
|