@bagelink/workspace 1.10.7 → 1.10.11
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 +214 -9
- package/bin/bgl.ts +88 -2
- package/dist/bin/bgl.cjs +854 -14
- package/dist/bin/bgl.mjs +845 -6
- package/dist/composable.cjs +22 -0
- package/dist/composable.d.cts +52 -0
- package/dist/composable.d.mts +52 -0
- package/dist/composable.d.ts +52 -0
- package/dist/composable.mjs +19 -0
- package/dist/index.cjs +3 -160
- package/dist/index.d.cts +4 -160
- package/dist/index.d.mts +4 -160
- package/dist/index.d.ts +4 -160
- package/dist/index.mjs +2 -139
- package/dist/shared/workspace.Bc_dpzhA.mjs +500 -0
- package/dist/shared/workspace.BzlV5kcN.d.cts +50 -0
- package/dist/shared/workspace.BzlV5kcN.d.mts +50 -0
- package/dist/shared/workspace.BzlV5kcN.d.ts +50 -0
- package/dist/shared/workspace.DRlDHdPw.cjs +512 -0
- package/dist/vite.cjs +135 -0
- package/dist/vite.d.cts +98 -0
- package/dist/vite.d.mts +98 -0
- package/dist/vite.d.ts +98 -0
- package/dist/vite.mjs +125 -0
- package/env.d.ts +30 -0
- package/package.json +24 -3
- package/src/build.ts +45 -0
- package/src/composable.ts +70 -0
- package/src/dev.ts +171 -0
- package/src/index.ts +4 -78
- package/src/init.ts +72 -14
- package/src/lint.ts +90 -2
- package/src/netlify.ts +54 -3
- package/src/proxy.ts +23 -3
- package/src/sdk.ts +80 -44
- package/src/types.ts +10 -4
- package/src/vite.ts +166 -0
- package/src/workspace.ts +121 -16
- package/templates/dev-runner.ts +61 -0
- package/templates/tsconfig.app.json +23 -0
- package/dist/shared/workspace.BPEOymAx.cjs +0 -926
- package/dist/shared/workspace.DfYoqH33.mjs +0 -906
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import prompts from 'prompts';
|
|
5
|
+
|
|
6
|
+
async function initWorkspace(root = process.cwd()) {
|
|
7
|
+
console.log("\n\u{1F680} Creating Bagel workspace...\n");
|
|
8
|
+
const response = await prompts([
|
|
9
|
+
{
|
|
10
|
+
type: "text",
|
|
11
|
+
name: "workspaceName",
|
|
12
|
+
message: "Workspace name:",
|
|
13
|
+
initial: "my-workspace"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
type: "text",
|
|
17
|
+
name: "projectId",
|
|
18
|
+
message: "Bagel project ID:",
|
|
19
|
+
initial: "my-project"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: "confirm",
|
|
23
|
+
name: "createFirstProject",
|
|
24
|
+
message: "Create first project?",
|
|
25
|
+
initial: true
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: (prev) => prev ? "text" : null,
|
|
29
|
+
name: "firstProjectName",
|
|
30
|
+
message: "First project name:",
|
|
31
|
+
initial: "web"
|
|
32
|
+
}
|
|
33
|
+
]);
|
|
34
|
+
if (!response || !response.workspaceName) {
|
|
35
|
+
console.log("\n\u274C Workspace creation cancelled.\n");
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const { workspaceName, projectId, createFirstProject, firstProjectName } = response;
|
|
39
|
+
const workspaceDir = resolve(root, workspaceName);
|
|
40
|
+
createWorkspaceRoot(root, workspaceName, projectId);
|
|
41
|
+
createSharedPackage(workspaceDir);
|
|
42
|
+
if (createFirstProject && firstProjectName) {
|
|
43
|
+
await addProject(firstProjectName, workspaceDir);
|
|
44
|
+
}
|
|
45
|
+
console.log("\n\u2705 Workspace created successfully!");
|
|
46
|
+
console.log("\nNext steps:");
|
|
47
|
+
console.log(` cd ${workspaceName}`);
|
|
48
|
+
console.log(" bun install");
|
|
49
|
+
if (createFirstProject) {
|
|
50
|
+
console.log(` bun run dev:${firstProjectName}`);
|
|
51
|
+
} else {
|
|
52
|
+
console.log(" bgl add <project-name> # Add a project");
|
|
53
|
+
}
|
|
54
|
+
console.log("");
|
|
55
|
+
}
|
|
56
|
+
function createWorkspaceRoot(root, name, projectId) {
|
|
57
|
+
const workspaceDir = resolve(root, name);
|
|
58
|
+
if (existsSync(workspaceDir)) {
|
|
59
|
+
console.error(`\u274C Directory ${name} already exists`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
mkdirSync(workspaceDir, { recursive: true });
|
|
63
|
+
const packageJson = {
|
|
64
|
+
name,
|
|
65
|
+
private: true,
|
|
66
|
+
workspaces: ["*", "!node_modules"],
|
|
67
|
+
scripts: {
|
|
68
|
+
"dev": "bgl dev",
|
|
69
|
+
"dev:local": "bgl dev --mode localhost",
|
|
70
|
+
"dev:verbose": "bun run --filter './!shared*' dev",
|
|
71
|
+
"build": "bgl build",
|
|
72
|
+
"typecheck": "tsc --noEmit",
|
|
73
|
+
"lint": "eslint . --cache",
|
|
74
|
+
"lint:fix": "eslint . --cache --fix"
|
|
75
|
+
},
|
|
76
|
+
dependencies: {
|
|
77
|
+
"@bagelink/auth": "latest",
|
|
78
|
+
"@bagelink/sdk": "latest",
|
|
79
|
+
"@bagelink/vue": "latest",
|
|
80
|
+
"pinia": "latest",
|
|
81
|
+
"vue": "latest",
|
|
82
|
+
"vue-router": "latest"
|
|
83
|
+
},
|
|
84
|
+
devDependencies: {
|
|
85
|
+
"@bagelink/lint-config": "latest",
|
|
86
|
+
"@bagelink/workspace": "latest",
|
|
87
|
+
"@vitejs/plugin-vue": "latest",
|
|
88
|
+
"eslint": "latest",
|
|
89
|
+
"typescript": "^5.0.0",
|
|
90
|
+
"vite": "latest"
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
writeFileSync(
|
|
94
|
+
resolve(workspaceDir, "package.json"),
|
|
95
|
+
`${JSON.stringify(packageJson, null, 2)}
|
|
96
|
+
`
|
|
97
|
+
);
|
|
98
|
+
const bglConfig = `import { defineWorkspace } from '@bagelink/workspace'
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Define your workspace environments
|
|
102
|
+
* You can add as many custom environments as needed (e.g., 'staging', 'preview')
|
|
103
|
+
* Use --mode flag to switch: bgl dev --mode <env_name>
|
|
104
|
+
*/
|
|
105
|
+
export default defineWorkspace({
|
|
106
|
+
localhost: {
|
|
107
|
+
host: 'http://localhost:8000',
|
|
108
|
+
proxy: '/api', // Optional: remove to skip proxy setup
|
|
109
|
+
openapi_url: 'http://localhost:8000/openapi.json',
|
|
110
|
+
},
|
|
111
|
+
development: {
|
|
112
|
+
host: 'https://${projectId}.bagel.to',
|
|
113
|
+
proxy: '/api',
|
|
114
|
+
openapi_url: 'https://${projectId}.bagel.to/openapi.json',
|
|
115
|
+
},
|
|
116
|
+
production: {
|
|
117
|
+
host: 'https://${projectId}.bagel.to',
|
|
118
|
+
proxy: '/api',
|
|
119
|
+
openapi_url: 'https://${projectId}.bagel.to/openapi.json',
|
|
120
|
+
},
|
|
121
|
+
})
|
|
122
|
+
`;
|
|
123
|
+
writeFileSync(resolve(workspaceDir, "bgl.config.ts"), bglConfig);
|
|
124
|
+
const tsConfig = {
|
|
125
|
+
compilerOptions: {
|
|
126
|
+
target: "ES2020",
|
|
127
|
+
useDefineForClassFields: true,
|
|
128
|
+
module: "ESNext",
|
|
129
|
+
lib: ["ES2020", "DOM", "DOM.Iterable"],
|
|
130
|
+
skipLibCheck: true,
|
|
131
|
+
moduleResolution: "bundler",
|
|
132
|
+
allowImportingTsExtensions: true,
|
|
133
|
+
resolveJsonModule: true,
|
|
134
|
+
isolatedModules: true,
|
|
135
|
+
noEmit: true,
|
|
136
|
+
jsx: "preserve",
|
|
137
|
+
strict: true,
|
|
138
|
+
noUnusedLocals: true,
|
|
139
|
+
noUnusedParameters: true,
|
|
140
|
+
noFallthroughCasesInSwitch: true,
|
|
141
|
+
baseUrl: ".",
|
|
142
|
+
paths: {
|
|
143
|
+
"shared/*": ["./shared/*"]
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
writeFileSync(
|
|
148
|
+
resolve(workspaceDir, "tsconfig.json"),
|
|
149
|
+
`${JSON.stringify(tsConfig, null, 2)}
|
|
150
|
+
`
|
|
151
|
+
);
|
|
152
|
+
const gitignore = `node_modules
|
|
153
|
+
dist
|
|
154
|
+
.DS_Store
|
|
155
|
+
*.local
|
|
156
|
+
.env.local
|
|
157
|
+
.vite
|
|
158
|
+
`;
|
|
159
|
+
writeFileSync(resolve(workspaceDir, ".gitignore"), gitignore);
|
|
160
|
+
const scriptsDir = resolve(workspaceDir, "scripts");
|
|
161
|
+
mkdirSync(scriptsDir, { recursive: true });
|
|
162
|
+
const devRunnerContent = `#!/usr/bin/env bun
|
|
163
|
+
import { spawn } from 'bun'
|
|
164
|
+
import { readdir } from 'fs/promises'
|
|
165
|
+
import { resolve } from 'path'
|
|
166
|
+
|
|
167
|
+
const projectsRoot = process.cwd()
|
|
168
|
+
const projects = (await readdir(projectsRoot, { withFileTypes: true }))
|
|
169
|
+
.filter(
|
|
170
|
+
item =>
|
|
171
|
+
item.isDirectory()
|
|
172
|
+
&& item.name !== 'node_modules'
|
|
173
|
+
&& item.name !== 'shared'
|
|
174
|
+
&& item.name !== 'scripts'
|
|
175
|
+
&& item.name !== '.git'
|
|
176
|
+
&& !item.name.startsWith('.'),
|
|
177
|
+
)
|
|
178
|
+
.map(item => item.name)
|
|
179
|
+
|
|
180
|
+
console.log(\`\\n\u{1F680} Starting \${projects.length} project\${projects.length > 1 ? 's' : ''}...\\n\`)
|
|
181
|
+
|
|
182
|
+
const urlPattern = /Local:\\s+(http:\\/\\/localhost:\\d+)/
|
|
183
|
+
|
|
184
|
+
projects.forEach((project) => {
|
|
185
|
+
const proc = spawn({
|
|
186
|
+
cmd: ['bun', 'run', 'dev'],
|
|
187
|
+
cwd: resolve(projectsRoot, project),
|
|
188
|
+
stdout: 'pipe',
|
|
189
|
+
stderr: 'pipe',
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
const decoder = new TextDecoder()
|
|
193
|
+
|
|
194
|
+
proc.stdout.pipeTo(
|
|
195
|
+
new WritableStream({
|
|
196
|
+
write(chunk) {
|
|
197
|
+
const text = decoder.decode(chunk)
|
|
198
|
+
const match = text.match(urlPattern)
|
|
199
|
+
if (match) {
|
|
200
|
+
console.log(\` \u2713 \${project.padEnd(15)} \u2192 \${match[1]}\`)
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
}),
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
proc.stderr.pipeTo(
|
|
207
|
+
new WritableStream({
|
|
208
|
+
write(chunk) {
|
|
209
|
+
const text = decoder.decode(chunk)
|
|
210
|
+
if (text.includes('error') || text.includes('Error')) {
|
|
211
|
+
console.error(\` \u2717 \${project}: \${text.trim()}\`)
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
}),
|
|
215
|
+
)
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
console.log('\\n\u{1F4A1} Press Ctrl+C to stop all servers\\n')
|
|
219
|
+
|
|
220
|
+
process.on('SIGINT', () => {
|
|
221
|
+
console.log('\\n\\n\u{1F44B} Stopping all servers...\\n')
|
|
222
|
+
process.exit()
|
|
223
|
+
})
|
|
224
|
+
`;
|
|
225
|
+
writeFileSync(resolve(scriptsDir, "dev.ts"), devRunnerContent);
|
|
226
|
+
console.log(`\u2705 Created workspace: ${name}`);
|
|
227
|
+
}
|
|
228
|
+
function createSharedPackage(root) {
|
|
229
|
+
const sharedDir = resolve(root, "shared");
|
|
230
|
+
mkdirSync(sharedDir, { recursive: true });
|
|
231
|
+
const packageJson = {
|
|
232
|
+
name: "shared",
|
|
233
|
+
version: "1.0.0",
|
|
234
|
+
type: "module",
|
|
235
|
+
exports: {
|
|
236
|
+
".": "./index.ts",
|
|
237
|
+
"./utils": "./utils/index.ts",
|
|
238
|
+
"./types": "./types/index.ts"
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
writeFileSync(
|
|
242
|
+
resolve(sharedDir, "package.json"),
|
|
243
|
+
`${JSON.stringify(packageJson, null, 2)}
|
|
244
|
+
`
|
|
245
|
+
);
|
|
246
|
+
writeFileSync(
|
|
247
|
+
resolve(sharedDir, "index.ts"),
|
|
248
|
+
"// Shared utilities and exports\nexport * from './utils'\n"
|
|
249
|
+
);
|
|
250
|
+
mkdirSync(resolve(sharedDir, "utils"), { recursive: true });
|
|
251
|
+
writeFileSync(
|
|
252
|
+
resolve(sharedDir, "utils", "index.ts"),
|
|
253
|
+
"// Shared utility functions\nexport function formatDate(date: Date): string {\n return date.toISOString()\n}\n"
|
|
254
|
+
);
|
|
255
|
+
mkdirSync(resolve(sharedDir, "types"), { recursive: true });
|
|
256
|
+
writeFileSync(
|
|
257
|
+
resolve(sharedDir, "types", "index.ts"),
|
|
258
|
+
"// Shared types\nexport interface User {\n id: string\n name: string\n}\n"
|
|
259
|
+
);
|
|
260
|
+
console.log("\u2705 Created shared package");
|
|
261
|
+
}
|
|
262
|
+
async function addProject(name, root = process.cwd()) {
|
|
263
|
+
const projectDir = resolve(root, name);
|
|
264
|
+
if (existsSync(projectDir)) {
|
|
265
|
+
console.error(`\u274C Project ${name} already exists`);
|
|
266
|
+
process.exit(1);
|
|
267
|
+
}
|
|
268
|
+
console.log(`
|
|
269
|
+
\u{1F4E6} Creating project: ${name}
|
|
270
|
+
`);
|
|
271
|
+
mkdirSync(projectDir, { recursive: true });
|
|
272
|
+
const isWorkspace = existsSync(resolve(root, "bgl.config.ts"));
|
|
273
|
+
const packageJson = {
|
|
274
|
+
name,
|
|
275
|
+
type: "module",
|
|
276
|
+
scripts: {
|
|
277
|
+
dev: "vite",
|
|
278
|
+
build: "vite build",
|
|
279
|
+
preview: "vite preview"
|
|
280
|
+
},
|
|
281
|
+
dependencies: {},
|
|
282
|
+
devDependencies: {
|
|
283
|
+
"@vitejs/plugin-vue": "latest",
|
|
284
|
+
"vite": "latest",
|
|
285
|
+
"vue": "latest"
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
if (isWorkspace) {
|
|
289
|
+
packageJson.dependencies.shared = "workspace:*";
|
|
290
|
+
}
|
|
291
|
+
writeFileSync(
|
|
292
|
+
resolve(projectDir, "package.json"),
|
|
293
|
+
`${JSON.stringify(packageJson, null, 2)}
|
|
294
|
+
`
|
|
295
|
+
);
|
|
296
|
+
const bglConfigContent = isWorkspace ? `import { defineWorkspace } from '@bagelink/workspace'
|
|
297
|
+
import rootWorkspace from '../bgl.config'
|
|
298
|
+
|
|
299
|
+
export default defineWorkspace({
|
|
300
|
+
localhost: rootWorkspace('localhost'),
|
|
301
|
+
development: rootWorkspace('development'),
|
|
302
|
+
production: rootWorkspace('production'),
|
|
303
|
+
})
|
|
304
|
+
` : `import { defineWorkspace } from '@bagelink/workspace'
|
|
305
|
+
|
|
306
|
+
export default defineWorkspace({
|
|
307
|
+
localhost: {
|
|
308
|
+
host: 'http://localhost:8000',
|
|
309
|
+
proxy: '/api',
|
|
310
|
+
},
|
|
311
|
+
development: {
|
|
312
|
+
host: 'https://my-project.bagel.to',
|
|
313
|
+
proxy: '/api',
|
|
314
|
+
},
|
|
315
|
+
production: {
|
|
316
|
+
host: 'https://my-project.bagel.to',
|
|
317
|
+
proxy: '/api',
|
|
318
|
+
},
|
|
319
|
+
})
|
|
320
|
+
`;
|
|
321
|
+
writeFileSync(resolve(projectDir, "bgl.config.ts"), bglConfigContent);
|
|
322
|
+
const viteConfig = `import { defineConfig } from 'vite'
|
|
323
|
+
import vue from '@vitejs/plugin-vue'
|
|
324
|
+
import { bagelink } from '@bagelink/workspace/vite'
|
|
325
|
+
import workspace from './bgl.config'
|
|
326
|
+
|
|
327
|
+
export default defineConfig({
|
|
328
|
+
plugins: [
|
|
329
|
+
vue(),
|
|
330
|
+
bagelink({ workspace }),
|
|
331
|
+
],
|
|
332
|
+
})
|
|
333
|
+
`;
|
|
334
|
+
writeFileSync(resolve(projectDir, "vite.config.ts"), viteConfig);
|
|
335
|
+
const srcDir = resolve(projectDir, "src");
|
|
336
|
+
mkdirSync(srcDir, { recursive: true });
|
|
337
|
+
const indexHtml = `<!DOCTYPE html>
|
|
338
|
+
<html lang="en">
|
|
339
|
+
<head>
|
|
340
|
+
<meta charset="UTF-8">
|
|
341
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
342
|
+
<title>${name}</title>
|
|
343
|
+
</head>
|
|
344
|
+
<body>
|
|
345
|
+
<div id="app"></div>
|
|
346
|
+
<script type="module" src="/src/main.ts"><\/script>
|
|
347
|
+
</body>
|
|
348
|
+
</html>
|
|
349
|
+
`;
|
|
350
|
+
writeFileSync(resolve(projectDir, "index.html"), indexHtml);
|
|
351
|
+
const mainTs = `import { createApp } from 'vue'
|
|
352
|
+
import { BagelVue } from '@bagelink/vue'
|
|
353
|
+
import App from './App.vue'
|
|
354
|
+
|
|
355
|
+
createApp(App)
|
|
356
|
+
.use(BagelVue)
|
|
357
|
+
.mount('#app')
|
|
358
|
+
`;
|
|
359
|
+
writeFileSync(resolve(srcDir, "main.ts"), mainTs);
|
|
360
|
+
const appVue = `<script setup lang="ts">
|
|
361
|
+
import { ref } from 'vue'
|
|
362
|
+
${isWorkspace ? "import { formatDate } from 'shared/utils'\n" : ""}
|
|
363
|
+
const count = ref(0)
|
|
364
|
+
<\/script>
|
|
365
|
+
|
|
366
|
+
<template>
|
|
367
|
+
<div>
|
|
368
|
+
<h1>${name}</h1>
|
|
369
|
+
<button @click="count++">Count: {{ count }}</button>
|
|
370
|
+
${isWorkspace ? "<p>{{ formatDate(new Date()) }}</p>" : ""}
|
|
371
|
+
</div>
|
|
372
|
+
</template>
|
|
373
|
+
`;
|
|
374
|
+
writeFileSync(resolve(srcDir, "App.vue"), appVue);
|
|
375
|
+
console.log(`\u2705 Created project: ${name}`);
|
|
376
|
+
if (isWorkspace) {
|
|
377
|
+
updateWorkspaceScripts(root, name);
|
|
378
|
+
}
|
|
379
|
+
console.log("\nNext steps:");
|
|
380
|
+
console.log(` cd ${name}`);
|
|
381
|
+
console.log(" bun install");
|
|
382
|
+
console.log(" bun run dev");
|
|
383
|
+
console.log("");
|
|
384
|
+
}
|
|
385
|
+
function updateWorkspaceScripts(root, projectName) {
|
|
386
|
+
const packageJsonPath = resolve(root, "package.json");
|
|
387
|
+
if (!existsSync(packageJsonPath)) return;
|
|
388
|
+
try {
|
|
389
|
+
const packageJson = JSON.parse(
|
|
390
|
+
readFileSync(packageJsonPath, "utf-8")
|
|
391
|
+
);
|
|
392
|
+
if (!packageJson.scripts) {
|
|
393
|
+
packageJson.scripts = {};
|
|
394
|
+
}
|
|
395
|
+
packageJson.scripts[`dev:${projectName}`] = `bun --filter ${projectName} dev`;
|
|
396
|
+
packageJson.scripts[`build:${projectName}`] = `bun --filter ${projectName} build`;
|
|
397
|
+
writeFileSync(
|
|
398
|
+
packageJsonPath,
|
|
399
|
+
`${JSON.stringify(packageJson, null, 2)}
|
|
400
|
+
`
|
|
401
|
+
);
|
|
402
|
+
console.log(`\u2705 Added scripts: dev:${projectName}, build:${projectName}`);
|
|
403
|
+
} catch (error) {
|
|
404
|
+
console.warn("\u26A0\uFE0F Could not update workspace scripts");
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function listProjects(root = process.cwd()) {
|
|
408
|
+
try {
|
|
409
|
+
const items = readdirSync(root, { withFileTypes: true });
|
|
410
|
+
return items.filter(
|
|
411
|
+
(item) => item.isDirectory() && item.name !== "node_modules" && item.name !== "shared" && item.name !== "scripts" && item.name !== ".git" && !item.name.startsWith(".")
|
|
412
|
+
).filter((item) => {
|
|
413
|
+
const packageJsonPath = resolve(root, item.name, "package.json");
|
|
414
|
+
if (!existsSync(packageJsonPath)) return false;
|
|
415
|
+
try {
|
|
416
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
417
|
+
return packageJson.scripts?.dev !== void 0;
|
|
418
|
+
} catch {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
}).map((item) => item.name).sort();
|
|
422
|
+
} catch {
|
|
423
|
+
return [];
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function generateNetlifyRedirect(config) {
|
|
428
|
+
const redirect = `# API Proxy Configuration
|
|
429
|
+
# Environment variables are set in Netlify UI or netlify.toml [build.environment] section
|
|
430
|
+
|
|
431
|
+
[[redirects]]
|
|
432
|
+
from = "${config.proxy}/*"
|
|
433
|
+
to = "${config.host}/:splat"
|
|
434
|
+
status = 200
|
|
435
|
+
force = true
|
|
436
|
+
headers = {X-From = "Netlify"}
|
|
437
|
+
`;
|
|
438
|
+
return redirect;
|
|
439
|
+
}
|
|
440
|
+
function generateNetlifyConfigTemplate() {
|
|
441
|
+
return `# Standard Netlify configuration for Bagelink projects
|
|
442
|
+
# Uses environment variables for proxy configuration
|
|
443
|
+
|
|
444
|
+
[build.environment]
|
|
445
|
+
# Set these in Netlify UI or override here
|
|
446
|
+
# BGL_PROXY_PATH = "/api"
|
|
447
|
+
# BGL_API_HOST = "https://your-project.bagel.to"
|
|
448
|
+
|
|
449
|
+
[[redirects]]
|
|
450
|
+
# Proxy API requests to backend
|
|
451
|
+
# Uses BGL_PROXY_PATH and BGL_API_HOST from environment
|
|
452
|
+
from = "/api/*"
|
|
453
|
+
to = "https://your-project.bagel.to/:splat"
|
|
454
|
+
status = 200
|
|
455
|
+
force = true
|
|
456
|
+
headers = {X-From = "Netlify"}
|
|
457
|
+
|
|
458
|
+
# Example: Multiple API backends
|
|
459
|
+
# [[redirects]]
|
|
460
|
+
# from = "/api/v2/*"
|
|
461
|
+
# to = "https://api-v2.example.com/:splat"
|
|
462
|
+
# status = 200
|
|
463
|
+
# force = true
|
|
464
|
+
`;
|
|
465
|
+
}
|
|
466
|
+
function generateNetlifyConfig(config, additionalConfig, useTemplate = false) {
|
|
467
|
+
if (useTemplate) {
|
|
468
|
+
return generateNetlifyConfigTemplate();
|
|
469
|
+
}
|
|
470
|
+
const redirect = generateNetlifyRedirect(config);
|
|
471
|
+
if (additionalConfig !== void 0 && additionalConfig !== "") {
|
|
472
|
+
return `${redirect}
|
|
473
|
+
${additionalConfig}`;
|
|
474
|
+
}
|
|
475
|
+
return redirect;
|
|
476
|
+
}
|
|
477
|
+
function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig, useTemplate = false) {
|
|
478
|
+
const content = generateNetlifyConfig(config, additionalConfig, useTemplate);
|
|
479
|
+
const resolvedPath = resolve(outPath);
|
|
480
|
+
writeFileSync(resolvedPath, content, "utf-8");
|
|
481
|
+
console.log(`\u2713 Generated netlify.toml at ${resolvedPath}`);
|
|
482
|
+
if (!useTemplate) {
|
|
483
|
+
console.log("\n\u{1F4A1} Tip: For environment-based config, set these in Netlify UI:");
|
|
484
|
+
console.log(` BGL_PROXY_PATH = "${config.proxy}"`);
|
|
485
|
+
console.log(` BGL_API_HOST = "${config.host}"`);
|
|
486
|
+
if (config.openapi_url) {
|
|
487
|
+
console.log(` BGL_OPENAPI_URL = "${config.openapi_url}"`);
|
|
488
|
+
}
|
|
489
|
+
console.log("");
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function setBuildEnvVars(config) {
|
|
493
|
+
process.env.BGL_PROXY_PATH = config.proxy;
|
|
494
|
+
process.env.BGL_API_HOST = config.host;
|
|
495
|
+
if (config.openapi_url !== void 0 && config.openapi_url !== "") {
|
|
496
|
+
process.env.BGL_OPENAPI_URL = config.openapi_url;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
export { addProject as a, generateNetlifyConfig as g, initWorkspace as i, listProjects as l, setBuildEnvVars as s, writeNetlifyConfig as w };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
type WorkspaceEnvironment = string;
|
|
2
|
+
interface WorkspaceConfig {
|
|
3
|
+
/**
|
|
4
|
+
* The host URL of the backend API server
|
|
5
|
+
* @example 'http://localhost:8000' | 'https://project.bagel.to'
|
|
6
|
+
*/
|
|
7
|
+
host: string;
|
|
8
|
+
/**
|
|
9
|
+
* Optional proxy path to use for API requests
|
|
10
|
+
* If not set, no proxy will be configured for this environment
|
|
11
|
+
* @example '/api'
|
|
12
|
+
*/
|
|
13
|
+
proxy?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional OpenAPI specification URL for SDK generation
|
|
16
|
+
*/
|
|
17
|
+
openapi_url?: string;
|
|
18
|
+
}
|
|
19
|
+
interface WorkspaceOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Root directory of the workspace
|
|
22
|
+
* @default process.cwd()
|
|
23
|
+
*/
|
|
24
|
+
root?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Path to the config file relative to root
|
|
27
|
+
* @default 'bgl.config.ts'
|
|
28
|
+
*/
|
|
29
|
+
configFile?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Enable interactive config generation if no config is found
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
interactive?: boolean;
|
|
35
|
+
}
|
|
36
|
+
interface ProxyConfig {
|
|
37
|
+
[path: string]: {
|
|
38
|
+
target: string;
|
|
39
|
+
changeOrigin: boolean;
|
|
40
|
+
rewrite?: (path: string) => string;
|
|
41
|
+
secure: boolean;
|
|
42
|
+
ws?: boolean;
|
|
43
|
+
followRedirects?: boolean;
|
|
44
|
+
autoRewrite?: boolean;
|
|
45
|
+
protocolRewrite?: string;
|
|
46
|
+
configure?: (proxy: any, options: any) => void;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type { ProxyConfig as P, WorkspaceEnvironment as W, WorkspaceConfig as a, WorkspaceOptions as b };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
type WorkspaceEnvironment = string;
|
|
2
|
+
interface WorkspaceConfig {
|
|
3
|
+
/**
|
|
4
|
+
* The host URL of the backend API server
|
|
5
|
+
* @example 'http://localhost:8000' | 'https://project.bagel.to'
|
|
6
|
+
*/
|
|
7
|
+
host: string;
|
|
8
|
+
/**
|
|
9
|
+
* Optional proxy path to use for API requests
|
|
10
|
+
* If not set, no proxy will be configured for this environment
|
|
11
|
+
* @example '/api'
|
|
12
|
+
*/
|
|
13
|
+
proxy?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional OpenAPI specification URL for SDK generation
|
|
16
|
+
*/
|
|
17
|
+
openapi_url?: string;
|
|
18
|
+
}
|
|
19
|
+
interface WorkspaceOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Root directory of the workspace
|
|
22
|
+
* @default process.cwd()
|
|
23
|
+
*/
|
|
24
|
+
root?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Path to the config file relative to root
|
|
27
|
+
* @default 'bgl.config.ts'
|
|
28
|
+
*/
|
|
29
|
+
configFile?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Enable interactive config generation if no config is found
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
interactive?: boolean;
|
|
35
|
+
}
|
|
36
|
+
interface ProxyConfig {
|
|
37
|
+
[path: string]: {
|
|
38
|
+
target: string;
|
|
39
|
+
changeOrigin: boolean;
|
|
40
|
+
rewrite?: (path: string) => string;
|
|
41
|
+
secure: boolean;
|
|
42
|
+
ws?: boolean;
|
|
43
|
+
followRedirects?: boolean;
|
|
44
|
+
autoRewrite?: boolean;
|
|
45
|
+
protocolRewrite?: string;
|
|
46
|
+
configure?: (proxy: any, options: any) => void;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type { ProxyConfig as P, WorkspaceEnvironment as W, WorkspaceConfig as a, WorkspaceOptions as b };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
type WorkspaceEnvironment = string;
|
|
2
|
+
interface WorkspaceConfig {
|
|
3
|
+
/**
|
|
4
|
+
* The host URL of the backend API server
|
|
5
|
+
* @example 'http://localhost:8000' | 'https://project.bagel.to'
|
|
6
|
+
*/
|
|
7
|
+
host: string;
|
|
8
|
+
/**
|
|
9
|
+
* Optional proxy path to use for API requests
|
|
10
|
+
* If not set, no proxy will be configured for this environment
|
|
11
|
+
* @example '/api'
|
|
12
|
+
*/
|
|
13
|
+
proxy?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional OpenAPI specification URL for SDK generation
|
|
16
|
+
*/
|
|
17
|
+
openapi_url?: string;
|
|
18
|
+
}
|
|
19
|
+
interface WorkspaceOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Root directory of the workspace
|
|
22
|
+
* @default process.cwd()
|
|
23
|
+
*/
|
|
24
|
+
root?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Path to the config file relative to root
|
|
27
|
+
* @default 'bgl.config.ts'
|
|
28
|
+
*/
|
|
29
|
+
configFile?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Enable interactive config generation if no config is found
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
interactive?: boolean;
|
|
35
|
+
}
|
|
36
|
+
interface ProxyConfig {
|
|
37
|
+
[path: string]: {
|
|
38
|
+
target: string;
|
|
39
|
+
changeOrigin: boolean;
|
|
40
|
+
rewrite?: (path: string) => string;
|
|
41
|
+
secure: boolean;
|
|
42
|
+
ws?: boolean;
|
|
43
|
+
followRedirects?: boolean;
|
|
44
|
+
autoRewrite?: boolean;
|
|
45
|
+
protocolRewrite?: string;
|
|
46
|
+
configure?: (proxy: any, options: any) => void;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type { ProxyConfig as P, WorkspaceEnvironment as W, WorkspaceConfig as a, WorkspaceOptions as b };
|