@bagelink/workspace 1.7.4 → 1.9.0

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.
@@ -0,0 +1,730 @@
1
+ import { writeFileSync, existsSync, readFileSync, mkdirSync, readdirSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import process from 'node:process';
4
+ import prompts from 'prompts';
5
+
6
+ function generateNetlifyRedirect(config) {
7
+ const redirect = `[[redirects]]
8
+ from = "${config.proxy}/*"
9
+ to = "${config.host}/:splat"
10
+ status = 200
11
+ force = true
12
+ headers = {X-From = "Netlify"}
13
+ `;
14
+ return redirect;
15
+ }
16
+ function generateNetlifyConfig(config, additionalConfig) {
17
+ const redirect = generateNetlifyRedirect(config);
18
+ if (additionalConfig !== void 0 && additionalConfig !== "") {
19
+ return `${redirect}
20
+ ${additionalConfig}`;
21
+ }
22
+ return redirect;
23
+ }
24
+ function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig) {
25
+ const content = generateNetlifyConfig(config, additionalConfig);
26
+ const resolvedPath = resolve(outPath);
27
+ writeFileSync(resolvedPath, content, "utf-8");
28
+ console.log(`\u2713 Generated netlify.toml at ${resolvedPath}`);
29
+ }
30
+ function setBuildEnvVars(config) {
31
+ process.env.BGL_PROXY_PATH = config.proxy;
32
+ process.env.BGL_API_HOST = config.host;
33
+ if (config.openapi_url !== void 0 && config.openapi_url !== "") {
34
+ process.env.BGL_OPENAPI_URL = config.openapi_url;
35
+ }
36
+ }
37
+
38
+ async function generateWorkspaceConfig(root = process.cwd(), configFile = "bgl.config.ts") {
39
+ console.log("\n\u{1F527} No bgl.config.ts found. Let's create one!\n");
40
+ const response = await prompts([
41
+ {
42
+ type: "text",
43
+ name: "projectId",
44
+ message: "What is your Bagel project ID?",
45
+ initial: "my-project",
46
+ validate: (value) => value.length > 0 ? true : "Project ID is required"
47
+ },
48
+ {
49
+ type: "confirm",
50
+ name: "useCustomHost",
51
+ message: "Use custom production host?",
52
+ initial: false
53
+ },
54
+ {
55
+ type: (prev) => prev ? "text" : null,
56
+ name: "customHost",
57
+ message: "Enter production host URL:",
58
+ initial: "https://api.example.com"
59
+ }
60
+ ]);
61
+ if (!response || !response.projectId) {
62
+ console.log("\n\u274C Config generation cancelled.\n");
63
+ process.exit(1);
64
+ }
65
+ const productionHost = response.useCustomHost === true ? response.customHost : `https://${response.projectId}.bagel.to`;
66
+ const configContent = `import { defineWorkspace } from '@bagelink/workspace'
67
+ import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
68
+
69
+ const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
70
+ localhost: {
71
+ host: 'http://localhost:8000',
72
+ proxy: '/api',
73
+ openapi_url: 'http://localhost:8000/openapi.json',
74
+ },
75
+ development: {
76
+ host: '${productionHost}',
77
+ proxy: '/api',
78
+ openapi_url: '${productionHost}/openapi.json',
79
+ },
80
+ production: {
81
+ host: '${productionHost}',
82
+ proxy: '/api',
83
+ openapi_url: '${productionHost}/openapi.json',
84
+ },
85
+ }
86
+
87
+ export default defineWorkspace(configs)
88
+ `;
89
+ const configPath = resolve(root, configFile);
90
+ writeFileSync(configPath, configContent, "utf-8");
91
+ console.log(`
92
+ \u2705 Created ${configFile}`);
93
+ console.log(` Production host: ${productionHost}`);
94
+ console.log(` Local dev host: http://localhost:8000
95
+ `);
96
+ const setupResponse = await prompts([
97
+ {
98
+ type: "confirm",
99
+ name: "updatePackageJson",
100
+ message: "Add/update dev scripts in package.json?",
101
+ initial: true
102
+ },
103
+ {
104
+ type: "confirm",
105
+ name: "updateViteConfig",
106
+ message: "Create/update vite.config.ts?",
107
+ initial: true
108
+ },
109
+ {
110
+ type: "confirm",
111
+ name: "generateNetlify",
112
+ message: "Generate netlify.toml for deployment?",
113
+ initial: true
114
+ }
115
+ ]);
116
+ if (setupResponse.updatePackageJson) {
117
+ updatePackageJsonScripts(root);
118
+ }
119
+ if (setupResponse.updateViteConfig) {
120
+ updateViteConfig(root);
121
+ }
122
+ if (setupResponse.generateNetlify) {
123
+ const prodConfig = {
124
+ host: productionHost,
125
+ proxy: "/api"
126
+ };
127
+ writeNetlifyConfig(prodConfig, resolve(root, "netlify.toml"));
128
+ }
129
+ console.log("\n\u{1F4A1} You can edit these files to customize your configuration.\n");
130
+ }
131
+ function generateWorkspaceConfigSync(projectId, root = process.cwd(), configFile = "bgl.config.ts", customHost) {
132
+ const productionHost = customHost ?? `https://${projectId}.bagel.to`;
133
+ const configContent = `import { defineWorkspace } from '@bagelink/workspace'
134
+ import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
135
+
136
+ const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
137
+ localhost: {
138
+ host: 'http://localhost:8000',
139
+ proxy: '/api',
140
+ openapi_url: 'http://localhost:8000/openapi.json',
141
+ },
142
+ development: {
143
+ host: '${productionHost}',
144
+ proxy: '/api',
145
+ openapi_url: '${productionHost}/openapi.json',
146
+ },
147
+ production: {
148
+ host: '${productionHost}',
149
+ proxy: '/api',
150
+ openapi_url: '${productionHost}/openapi.json',
151
+ },
152
+ }
153
+
154
+ export default defineWorkspace(configs)
155
+ `;
156
+ const configPath = resolve(root, configFile);
157
+ writeFileSync(configPath, configContent, "utf-8");
158
+ console.log(`\u2705 Created ${configPath}`);
159
+ }
160
+ function updatePackageJsonScripts(root) {
161
+ const packageJsonPath = resolve(root, "package.json");
162
+ if (!existsSync(packageJsonPath)) {
163
+ console.log("\u26A0\uFE0F No package.json found, skipping script update");
164
+ return;
165
+ }
166
+ try {
167
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
168
+ if (!packageJson.scripts) {
169
+ packageJson.scripts = {};
170
+ }
171
+ const scriptsToAdd = {
172
+ "dev": "vite",
173
+ "dev:local": "vite --mode localhost",
174
+ "build": "vite build",
175
+ "preview": "vite preview"
176
+ };
177
+ let modified = false;
178
+ for (const [key, value] of Object.entries(scriptsToAdd)) {
179
+ if (key === "dev" || key === "dev:local") {
180
+ if (packageJson.scripts[key] !== value) {
181
+ packageJson.scripts[key] = value;
182
+ modified = true;
183
+ }
184
+ } else {
185
+ if (!packageJson.scripts[key]) {
186
+ packageJson.scripts[key] = value;
187
+ modified = true;
188
+ }
189
+ }
190
+ }
191
+ if (modified) {
192
+ writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
193
+ `, "utf-8");
194
+ console.log("\u2705 Updated package.json with dev scripts");
195
+ } else {
196
+ console.log("\u2139\uFE0F Scripts already up to date in package.json");
197
+ }
198
+ } catch (error) {
199
+ console.error("\u274C Failed to update package.json:", error);
200
+ }
201
+ }
202
+ function updateViteConfig(root) {
203
+ const viteConfigPath = resolve(root, "vite.config.ts");
204
+ const viteConfigExists = existsSync(viteConfigPath);
205
+ if (viteConfigExists) {
206
+ const existingConfig = readFileSync(viteConfigPath, "utf-8");
207
+ if (existingConfig.includes("@bagelink/workspace")) {
208
+ console.log("\u2139\uFE0F vite.config.ts already configured");
209
+ return;
210
+ }
211
+ console.log("\u26A0\uFE0F vite.config.ts exists. Please manually add the workspace configuration.");
212
+ console.log(" See: https://github.com/bageldb/bagelink/tree/master/packages/workspace#readme");
213
+ return;
214
+ }
215
+ const viteConfigContent = `import { defineConfig } from 'vite'
216
+ import { createViteProxy } from '@bagelink/workspace'
217
+ import workspace from './bgl.config'
218
+
219
+ // https://vitejs.dev/config/
220
+ export default defineConfig(({ mode }) => {
221
+ const config = workspace(mode as 'localhost' | 'development' | 'production')
222
+
223
+ return {
224
+ server: {
225
+ proxy: createViteProxy(config),
226
+ },
227
+ }
228
+ })
229
+ `;
230
+ writeFileSync(viteConfigPath, viteConfigContent, "utf-8");
231
+ console.log("\u2705 Created vite.config.ts");
232
+ }
233
+
234
+ async function initWorkspace(root = process.cwd()) {
235
+ console.log("\n\u{1F680} Creating Bagel workspace...\n");
236
+ const response = await prompts([
237
+ {
238
+ type: "text",
239
+ name: "workspaceName",
240
+ message: "Workspace name:",
241
+ initial: "my-workspace"
242
+ },
243
+ {
244
+ type: "text",
245
+ name: "projectId",
246
+ message: "Bagel project ID:",
247
+ initial: "my-project"
248
+ },
249
+ {
250
+ type: "confirm",
251
+ name: "createFirstProject",
252
+ message: "Create first project?",
253
+ initial: true
254
+ },
255
+ {
256
+ type: (prev) => prev ? "text" : null,
257
+ name: "firstProjectName",
258
+ message: "First project name:",
259
+ initial: "web"
260
+ }
261
+ ]);
262
+ if (!response || !response.workspaceName) {
263
+ console.log("\n\u274C Workspace creation cancelled.\n");
264
+ process.exit(1);
265
+ }
266
+ const { workspaceName, projectId, createFirstProject, firstProjectName } = response;
267
+ createWorkspaceRoot(root, workspaceName, projectId);
268
+ createSharedPackage(root);
269
+ if (createFirstProject && firstProjectName) {
270
+ await addProject(firstProjectName, root);
271
+ }
272
+ console.log("\n\u2705 Workspace created successfully!");
273
+ console.log("\nNext steps:");
274
+ console.log(` cd ${workspaceName}`);
275
+ console.log(" bun install");
276
+ if (createFirstProject) {
277
+ console.log(` bun run dev:${firstProjectName}`);
278
+ } else {
279
+ console.log(" bgl add <project-name> # Add a project");
280
+ }
281
+ console.log("");
282
+ }
283
+ function createWorkspaceRoot(root, name, projectId) {
284
+ const workspaceDir = resolve(root, name);
285
+ if (existsSync(workspaceDir)) {
286
+ console.error(`\u274C Directory ${name} already exists`);
287
+ process.exit(1);
288
+ }
289
+ mkdirSync(workspaceDir, { recursive: true });
290
+ const packageJson = {
291
+ name,
292
+ private: true,
293
+ workspaces: ["*", "!node_modules"],
294
+ scripts: {
295
+ dev: "bun run --filter './[!shared]*' dev",
296
+ build: "bun run --filter './[!shared]*' build",
297
+ typecheck: "tsc --noEmit"
298
+ },
299
+ devDependencies: {
300
+ "@bagelink/workspace": "latest",
301
+ typescript: "^5.0.0",
302
+ vite: "latest"
303
+ }
304
+ };
305
+ writeFileSync(
306
+ resolve(workspaceDir, "package.json"),
307
+ `${JSON.stringify(packageJson, null, 2)}
308
+ `
309
+ );
310
+ const bglConfig = `import { defineWorkspace } from '@bagelink/workspace'
311
+
312
+ export default defineWorkspace({
313
+ localhost: {
314
+ host: 'http://localhost:8000',
315
+ proxy: '/api',
316
+ openapi_url: 'http://localhost:8000/openapi.json',
317
+ },
318
+ development: {
319
+ host: 'https://${projectId}.bagel.to',
320
+ proxy: '/api',
321
+ openapi_url: 'https://${projectId}.bagel.to/openapi.json',
322
+ },
323
+ production: {
324
+ host: 'https://${projectId}.bagel.to',
325
+ proxy: '/api',
326
+ openapi_url: 'https://${projectId}.bagel.to/openapi.json',
327
+ },
328
+ })
329
+ `;
330
+ writeFileSync(resolve(workspaceDir, "bgl.config.ts"), bglConfig);
331
+ const tsConfig = {
332
+ compilerOptions: {
333
+ target: "ES2020",
334
+ useDefineForClassFields: true,
335
+ module: "ESNext",
336
+ lib: ["ES2020", "DOM", "DOM.Iterable"],
337
+ skipLibCheck: true,
338
+ moduleResolution: "bundler",
339
+ allowImportingTsExtensions: true,
340
+ resolveJsonModule: true,
341
+ isolatedModules: true,
342
+ noEmit: true,
343
+ jsx: "preserve",
344
+ strict: true,
345
+ noUnusedLocals: true,
346
+ noUnusedParameters: true,
347
+ noFallthroughCasesInSwitch: true,
348
+ baseUrl: ".",
349
+ paths: {
350
+ "shared/*": ["./shared/*"]
351
+ }
352
+ }
353
+ };
354
+ writeFileSync(
355
+ resolve(workspaceDir, "tsconfig.json"),
356
+ `${JSON.stringify(tsConfig, null, 2)}
357
+ `
358
+ );
359
+ const gitignore = `node_modules
360
+ dist
361
+ .DS_Store
362
+ *.local
363
+ .env.local
364
+ .vite
365
+ `;
366
+ writeFileSync(resolve(workspaceDir, ".gitignore"), gitignore);
367
+ console.log(`\u2705 Created workspace: ${name}`);
368
+ }
369
+ function createSharedPackage(root) {
370
+ const sharedDir = resolve(root, "shared");
371
+ mkdirSync(sharedDir, { recursive: true });
372
+ const packageJson = {
373
+ name: "shared",
374
+ version: "1.0.0",
375
+ type: "module",
376
+ exports: {
377
+ ".": "./index.ts",
378
+ "./utils": "./utils/index.ts",
379
+ "./types": "./types/index.ts"
380
+ }
381
+ };
382
+ writeFileSync(
383
+ resolve(sharedDir, "package.json"),
384
+ `${JSON.stringify(packageJson, null, 2)}
385
+ `
386
+ );
387
+ writeFileSync(
388
+ resolve(sharedDir, "index.ts"),
389
+ "// Shared utilities and exports\nexport * from './utils'\n"
390
+ );
391
+ mkdirSync(resolve(sharedDir, "utils"), { recursive: true });
392
+ writeFileSync(
393
+ resolve(sharedDir, "utils", "index.ts"),
394
+ "// Shared utility functions\nexport function formatDate(date: Date): string {\n return date.toISOString()\n}\n"
395
+ );
396
+ mkdirSync(resolve(sharedDir, "types"), { recursive: true });
397
+ writeFileSync(
398
+ resolve(sharedDir, "types", "index.ts"),
399
+ "// Shared types\nexport interface User {\n id: string\n name: string\n}\n"
400
+ );
401
+ console.log("\u2705 Created shared package");
402
+ }
403
+ async function addProject(name, root = process.cwd()) {
404
+ const projectDir = resolve(root, name);
405
+ if (existsSync(projectDir)) {
406
+ console.error(`\u274C Project ${name} already exists`);
407
+ process.exit(1);
408
+ }
409
+ console.log(`
410
+ \u{1F4E6} Creating project: ${name}
411
+ `);
412
+ mkdirSync(projectDir, { recursive: true });
413
+ const isWorkspace = existsSync(resolve(root, "bgl.config.ts"));
414
+ const packageJson = {
415
+ name,
416
+ type: "module",
417
+ scripts: {
418
+ dev: "vite",
419
+ build: "vite build",
420
+ preview: "vite preview"
421
+ },
422
+ dependencies: {},
423
+ devDependencies: {
424
+ "@vitejs/plugin-vue": "latest",
425
+ vite: "latest",
426
+ vue: "latest"
427
+ }
428
+ };
429
+ if (isWorkspace) {
430
+ packageJson.dependencies.shared = "workspace:*";
431
+ }
432
+ writeFileSync(
433
+ resolve(projectDir, "package.json"),
434
+ `${JSON.stringify(packageJson, null, 2)}
435
+ `
436
+ );
437
+ const bglConfigContent = isWorkspace ? `import { defineWorkspace } from '@bagelink/workspace'
438
+ import rootWorkspace from '../bgl.config'
439
+
440
+ export default defineWorkspace({
441
+ localhost: rootWorkspace('localhost'),
442
+ development: rootWorkspace('development'),
443
+ production: rootWorkspace('production'),
444
+ })
445
+ ` : `import { defineWorkspace } from '@bagelink/workspace'
446
+
447
+ export default defineWorkspace({
448
+ localhost: {
449
+ host: 'http://localhost:8000',
450
+ proxy: '/api',
451
+ },
452
+ development: {
453
+ host: 'https://my-project.bagel.to',
454
+ proxy: '/api',
455
+ },
456
+ production: {
457
+ host: 'https://my-project.bagel.to',
458
+ proxy: '/api',
459
+ },
460
+ })
461
+ `;
462
+ writeFileSync(resolve(projectDir, "bgl.config.ts"), bglConfigContent);
463
+ const viteConfig = `import { defineConfig } from 'vite'
464
+ import vue from '@vitejs/plugin-vue'
465
+ import { createViteProxy } from '@bagelink/workspace'
466
+ import workspace from './bgl.config'
467
+
468
+ export default defineConfig(({ mode }) => {
469
+ const config = workspace(mode as 'localhost' | 'development' | 'production')
470
+
471
+ return {
472
+ plugins: [vue()],
473
+ server: {
474
+ proxy: createViteProxy(config),
475
+ },
476
+ }
477
+ })
478
+ `;
479
+ writeFileSync(resolve(projectDir, "vite.config.ts"), viteConfig);
480
+ const srcDir = resolve(projectDir, "src");
481
+ mkdirSync(srcDir, { recursive: true });
482
+ const indexHtml = `<!DOCTYPE html>
483
+ <html lang="en">
484
+ <head>
485
+ <meta charset="UTF-8">
486
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
487
+ <title>${name}</title>
488
+ </head>
489
+ <body>
490
+ <div id="app"></div>
491
+ <script type="module" src="/src/main.ts"><\/script>
492
+ </body>
493
+ </html>
494
+ `;
495
+ writeFileSync(resolve(projectDir, "index.html"), indexHtml);
496
+ const mainTs = `import { createApp } from 'vue'
497
+ import App from './App.vue'
498
+
499
+ createApp(App).mount('#app')
500
+ `;
501
+ writeFileSync(resolve(srcDir, "main.ts"), mainTs);
502
+ const appVue = `<script setup lang="ts">
503
+ import { ref } from 'vue'
504
+ ${isWorkspace ? "import { formatDate } from 'shared/utils'\n" : ""}
505
+ const count = ref(0)
506
+ <\/script>
507
+
508
+ <template>
509
+ <div>
510
+ <h1>${name}</h1>
511
+ <button @click="count++">Count: {{ count }}</button>
512
+ ${isWorkspace ? "<p>{{ formatDate(new Date()) }}</p>" : ""}
513
+ </div>
514
+ </template>
515
+ `;
516
+ writeFileSync(resolve(srcDir, "App.vue"), appVue);
517
+ console.log(`\u2705 Created project: ${name}`);
518
+ if (isWorkspace) {
519
+ updateWorkspaceScripts(root, name);
520
+ }
521
+ console.log("\nNext steps:");
522
+ console.log(` cd ${name}`);
523
+ console.log(" bun install");
524
+ console.log(" bun run dev");
525
+ console.log("");
526
+ }
527
+ function updateWorkspaceScripts(root, projectName) {
528
+ const packageJsonPath = resolve(root, "package.json");
529
+ if (!existsSync(packageJsonPath)) return;
530
+ try {
531
+ const packageJson = JSON.parse(
532
+ require("fs").readFileSync(packageJsonPath, "utf-8")
533
+ );
534
+ if (!packageJson.scripts) {
535
+ packageJson.scripts = {};
536
+ }
537
+ packageJson.scripts[`dev:${projectName}`] = `bun --filter ${projectName} dev`;
538
+ packageJson.scripts[`build:${projectName}`] = `bun --filter ${projectName} build`;
539
+ writeFileSync(
540
+ packageJsonPath,
541
+ `${JSON.stringify(packageJson, null, 2)}
542
+ `
543
+ );
544
+ console.log(`\u2705 Added scripts: dev:${projectName}, build:${projectName}`);
545
+ } catch (error) {
546
+ console.warn("\u26A0\uFE0F Could not update workspace scripts");
547
+ }
548
+ }
549
+ function listProjects(root = process.cwd()) {
550
+ try {
551
+ const items = readdirSync(root, { withFileTypes: true });
552
+ return items.filter(
553
+ (item) => item.isDirectory() && item.name !== "node_modules" && item.name !== "shared" && item.name !== ".git" && !item.name.startsWith(".")
554
+ ).map((item) => item.name);
555
+ } catch {
556
+ return [];
557
+ }
558
+ }
559
+
560
+ async function setupLint(root = process.cwd(), isWorkspace = false) {
561
+ console.log("\n\u{1F50D} Setting up linting...\n");
562
+ const response = await prompts([
563
+ {
564
+ type: "multiselect",
565
+ name: "configs",
566
+ message: "Select configurations to set up:",
567
+ choices: [
568
+ { title: "ESLint", value: "eslint", selected: true },
569
+ { title: "Prettier", value: "prettier", selected: true },
570
+ { title: "EditorConfig", value: "editorconfig", selected: true },
571
+ { title: "Git Hooks", value: "githooks", selected: false }
572
+ ]
573
+ },
574
+ {
575
+ type: "confirm",
576
+ name: "installDeps",
577
+ message: "Install dependencies?",
578
+ initial: true
579
+ }
580
+ ]);
581
+ if (!response || !response.configs) {
582
+ console.log("\n\u274C Setup cancelled.\n");
583
+ process.exit(1);
584
+ }
585
+ const { configs, installDeps } = response;
586
+ if (configs.includes("eslint")) {
587
+ createEslintConfig(root, isWorkspace);
588
+ }
589
+ if (configs.includes("prettier")) {
590
+ createPrettierConfig(root);
591
+ }
592
+ if (configs.includes("editorconfig")) {
593
+ createEditorConfig(root);
594
+ }
595
+ if (configs.includes("githooks")) {
596
+ createGitHooks(root);
597
+ }
598
+ updatePackageJsonLint(root, configs);
599
+ if (installDeps) {
600
+ console.log("\n\u{1F4E6} Installing dependencies...");
601
+ console.log("Run: bun add -D @bagelink/lint-config eslint prettier typescript");
602
+ }
603
+ console.log("\n\u2705 Linting setup complete!");
604
+ console.log("\nAvailable commands:");
605
+ console.log(" bun run lint - Run linter");
606
+ console.log(" bun run lint:fix - Fix linting issues");
607
+ console.log(" bun run format - Format code with Prettier");
608
+ console.log("");
609
+ }
610
+ function createEslintConfig(root, isWorkspace) {
611
+ const configPath = resolve(root, "eslint.config.js");
612
+ const config = isWorkspace ? `import { defineConfig } from '@bagelink/lint-config/eslint'
613
+
614
+ export default defineConfig({
615
+ // Workspace-level ESLint config
616
+ ignores: ['**/dist/**', '**/node_modules/**', '**/.bun-cache/**'],
617
+ })
618
+ ` : `import vue3Config from '@bagelink/lint-config/eslint/vue3'
619
+
620
+ export default vue3Config
621
+ `;
622
+ writeFileSync(configPath, config);
623
+ console.log("\u2705 Created eslint.config.js");
624
+ }
625
+ function createPrettierConfig(root) {
626
+ const configPath = resolve(root, ".prettierrc");
627
+ const config = {
628
+ semi: false,
629
+ singleQuote: true,
630
+ tabWidth: 2,
631
+ useTabs: true,
632
+ trailingComma: "all",
633
+ printWidth: 100,
634
+ arrowParens: "avoid"
635
+ };
636
+ writeFileSync(configPath, `${JSON.stringify(config, null, 2)}
637
+ `);
638
+ console.log("\u2705 Created .prettierrc");
639
+ const ignorePath = resolve(root, ".prettierignore");
640
+ const ignore = `dist
641
+ node_modules
642
+ .bun-cache
643
+ *.min.js
644
+ *.min.css
645
+ `;
646
+ writeFileSync(ignorePath, ignore);
647
+ console.log("\u2705 Created .prettierignore");
648
+ }
649
+ function createEditorConfig(root) {
650
+ const configPath = resolve(root, ".editorconfig");
651
+ const config = `root = true
652
+
653
+ [*]
654
+ charset = utf-8
655
+ indent_style = tab
656
+ indent_size = 2
657
+ end_of_line = lf
658
+ insert_final_newline = true
659
+ trim_trailing_whitespace = true
660
+
661
+ [*.md]
662
+ trim_trailing_whitespace = false
663
+
664
+ [*.{json,yml,yaml}]
665
+ indent_style = space
666
+ indent_size = 2
667
+ `;
668
+ writeFileSync(configPath, config);
669
+ console.log("\u2705 Created .editorconfig");
670
+ }
671
+ function createGitHooks(root) {
672
+ const packageJsonPath = resolve(root, "package.json");
673
+ if (!existsSync(packageJsonPath)) {
674
+ console.warn("\u26A0\uFE0F No package.json found, skipping git hooks");
675
+ return;
676
+ }
677
+ const lintStagedConfig = {
678
+ "*.{js,jsx,ts,tsx,vue}": ["eslint --fix"],
679
+ "*.{json,md,yml,yaml}": ["prettier --write"]
680
+ };
681
+ writeFileSync(
682
+ resolve(root, ".lintstagedrc"),
683
+ `${JSON.stringify(lintStagedConfig, null, 2)}
684
+ `
685
+ );
686
+ console.log("\u2705 Created .lintstagedrc");
687
+ console.log("\u2139\uFE0F Add simple-git-hooks and lint-staged to devDependencies");
688
+ console.log(" Then run: npx simple-git-hooks");
689
+ }
690
+ function updatePackageJsonLint(root, configs) {
691
+ const packageJsonPath = resolve(root, "package.json");
692
+ if (!existsSync(packageJsonPath)) {
693
+ console.warn("\u26A0\uFE0F No package.json found");
694
+ return;
695
+ }
696
+ try {
697
+ const packageJson = JSON.parse(
698
+ require("fs").readFileSync(packageJsonPath, "utf-8")
699
+ );
700
+ if (!packageJson.scripts) {
701
+ packageJson.scripts = {};
702
+ }
703
+ if (configs.includes("eslint")) {
704
+ if (!packageJson.scripts.lint) {
705
+ packageJson.scripts.lint = "eslint .";
706
+ }
707
+ if (!packageJson.scripts["lint:fix"]) {
708
+ packageJson.scripts["lint:fix"] = "eslint . --fix";
709
+ }
710
+ }
711
+ if (configs.includes("prettier")) {
712
+ if (!packageJson.scripts.format) {
713
+ packageJson.scripts.format = "prettier --write .";
714
+ }
715
+ if (!packageJson.scripts["format:check"]) {
716
+ packageJson.scripts["format:check"] = "prettier --check .";
717
+ }
718
+ }
719
+ writeFileSync(
720
+ packageJsonPath,
721
+ `${JSON.stringify(packageJson, null, 2)}
722
+ `
723
+ );
724
+ console.log("\u2705 Updated package.json with lint scripts");
725
+ } catch (error) {
726
+ console.error("\u274C Failed to update package.json:", error);
727
+ }
728
+ }
729
+
730
+ export { generateNetlifyConfig as a, generateNetlifyRedirect as b, generateWorkspaceConfigSync as c, addProject as d, setupLint as e, generateWorkspaceConfig as g, initWorkspace as i, listProjects as l, setBuildEnvVars as s, writeNetlifyConfig as w };