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