@bagelink/workspace 1.9.0 → 1.10.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.
- package/README.md +65 -0
- package/bin/bgl.ts +32 -9
- package/dist/bin/bgl.cjs +35 -14
- package/dist/bin/bgl.mjs +30 -9
- package/dist/index.cjs +16 -14
- package/dist/index.d.cts +15 -6
- package/dist/index.d.mts +15 -6
- package/dist/index.d.ts +15 -6
- package/dist/index.mjs +2 -2
- package/dist/shared/{workspace.cX7U2RUq.mjs → workspace.CTMBmbXa.mjs} +307 -171
- package/dist/shared/{workspace.CCUm_5GG.cjs → workspace.dQE-K3dI.cjs} +308 -170
- package/package.json +6 -1
- package/src/index.ts +2 -1
- package/src/sdk.ts +186 -0
|
@@ -238,6 +238,312 @@ export default defineConfig(({ mode }) => {
|
|
|
238
238
|
console.log("\u2705 Created vite.config.ts");
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
+
async function setupLint(root = process__default.cwd(), isWorkspace = false) {
|
|
242
|
+
console.log("\n\u{1F50D} Setting up linting...\n");
|
|
243
|
+
const response = await prompts__default([
|
|
244
|
+
{
|
|
245
|
+
type: "multiselect",
|
|
246
|
+
name: "configs",
|
|
247
|
+
message: "Select configurations to set up:",
|
|
248
|
+
choices: [
|
|
249
|
+
{ title: "ESLint", value: "eslint", selected: true },
|
|
250
|
+
{ title: "Prettier", value: "prettier", selected: true },
|
|
251
|
+
{ title: "EditorConfig", value: "editorconfig", selected: true },
|
|
252
|
+
{ title: "Git Hooks", value: "githooks", selected: false }
|
|
253
|
+
]
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
type: "confirm",
|
|
257
|
+
name: "installDeps",
|
|
258
|
+
message: "Install dependencies?",
|
|
259
|
+
initial: true
|
|
260
|
+
}
|
|
261
|
+
]);
|
|
262
|
+
if (!response || !response.configs) {
|
|
263
|
+
console.log("\n\u274C Setup cancelled.\n");
|
|
264
|
+
process__default.exit(1);
|
|
265
|
+
}
|
|
266
|
+
const { configs, installDeps } = response;
|
|
267
|
+
if (configs.includes("eslint")) {
|
|
268
|
+
createEslintConfig(root, isWorkspace);
|
|
269
|
+
}
|
|
270
|
+
if (configs.includes("prettier")) {
|
|
271
|
+
createPrettierConfig(root);
|
|
272
|
+
}
|
|
273
|
+
if (configs.includes("editorconfig")) {
|
|
274
|
+
createEditorConfig(root);
|
|
275
|
+
}
|
|
276
|
+
if (configs.includes("githooks")) {
|
|
277
|
+
createGitHooks(root);
|
|
278
|
+
}
|
|
279
|
+
updatePackageJsonLint(root, configs);
|
|
280
|
+
if (installDeps) {
|
|
281
|
+
console.log("\n\u{1F4E6} Installing dependencies...");
|
|
282
|
+
console.log("Run: bun add -D @bagelink/lint-config eslint prettier typescript");
|
|
283
|
+
}
|
|
284
|
+
console.log("\n\u2705 Linting setup complete!");
|
|
285
|
+
console.log("\nAvailable commands:");
|
|
286
|
+
console.log(" bun run lint - Run linter");
|
|
287
|
+
console.log(" bun run lint:fix - Fix linting issues");
|
|
288
|
+
console.log(" bun run format - Format code with Prettier");
|
|
289
|
+
console.log("");
|
|
290
|
+
}
|
|
291
|
+
function createEslintConfig(root, isWorkspace) {
|
|
292
|
+
const configPath = node_path.resolve(root, "eslint.config.js");
|
|
293
|
+
const config = isWorkspace ? `import { defineConfig } from '@bagelink/lint-config/eslint'
|
|
294
|
+
|
|
295
|
+
export default defineConfig({
|
|
296
|
+
// Workspace-level ESLint config
|
|
297
|
+
ignores: ['**/dist/**', '**/node_modules/**', '**/.bun-cache/**'],
|
|
298
|
+
})
|
|
299
|
+
` : `import vue3Config from '@bagelink/lint-config/eslint/vue3'
|
|
300
|
+
|
|
301
|
+
export default vue3Config
|
|
302
|
+
`;
|
|
303
|
+
node_fs.writeFileSync(configPath, config);
|
|
304
|
+
console.log("\u2705 Created eslint.config.js");
|
|
305
|
+
}
|
|
306
|
+
function createPrettierConfig(root) {
|
|
307
|
+
const configPath = node_path.resolve(root, ".prettierrc");
|
|
308
|
+
const config = {
|
|
309
|
+
semi: false,
|
|
310
|
+
singleQuote: true,
|
|
311
|
+
tabWidth: 2,
|
|
312
|
+
useTabs: true,
|
|
313
|
+
trailingComma: "all",
|
|
314
|
+
printWidth: 100,
|
|
315
|
+
arrowParens: "avoid"
|
|
316
|
+
};
|
|
317
|
+
node_fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}
|
|
318
|
+
`);
|
|
319
|
+
console.log("\u2705 Created .prettierrc");
|
|
320
|
+
const ignorePath = node_path.resolve(root, ".prettierignore");
|
|
321
|
+
const ignore = `dist
|
|
322
|
+
node_modules
|
|
323
|
+
.bun-cache
|
|
324
|
+
*.min.js
|
|
325
|
+
*.min.css
|
|
326
|
+
`;
|
|
327
|
+
node_fs.writeFileSync(ignorePath, ignore);
|
|
328
|
+
console.log("\u2705 Created .prettierignore");
|
|
329
|
+
}
|
|
330
|
+
function createEditorConfig(root) {
|
|
331
|
+
const configPath = node_path.resolve(root, ".editorconfig");
|
|
332
|
+
const config = `root = true
|
|
333
|
+
|
|
334
|
+
[*]
|
|
335
|
+
charset = utf-8
|
|
336
|
+
indent_style = tab
|
|
337
|
+
indent_size = 2
|
|
338
|
+
end_of_line = lf
|
|
339
|
+
insert_final_newline = true
|
|
340
|
+
trim_trailing_whitespace = true
|
|
341
|
+
|
|
342
|
+
[*.md]
|
|
343
|
+
trim_trailing_whitespace = false
|
|
344
|
+
|
|
345
|
+
[*.{json,yml,yaml}]
|
|
346
|
+
indent_style = space
|
|
347
|
+
indent_size = 2
|
|
348
|
+
`;
|
|
349
|
+
node_fs.writeFileSync(configPath, config);
|
|
350
|
+
console.log("\u2705 Created .editorconfig");
|
|
351
|
+
}
|
|
352
|
+
function createGitHooks(root) {
|
|
353
|
+
const packageJsonPath = node_path.resolve(root, "package.json");
|
|
354
|
+
if (!node_fs.existsSync(packageJsonPath)) {
|
|
355
|
+
console.warn("\u26A0\uFE0F No package.json found, skipping git hooks");
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const lintStagedConfig = {
|
|
359
|
+
"*.{js,jsx,ts,tsx,vue}": ["eslint --fix"],
|
|
360
|
+
"*.{json,md,yml,yaml}": ["prettier --write"]
|
|
361
|
+
};
|
|
362
|
+
node_fs.writeFileSync(
|
|
363
|
+
node_path.resolve(root, ".lintstagedrc"),
|
|
364
|
+
`${JSON.stringify(lintStagedConfig, null, 2)}
|
|
365
|
+
`
|
|
366
|
+
);
|
|
367
|
+
console.log("\u2705 Created .lintstagedrc");
|
|
368
|
+
console.log("\u2139\uFE0F Add simple-git-hooks and lint-staged to devDependencies");
|
|
369
|
+
console.log(" Then run: npx simple-git-hooks");
|
|
370
|
+
}
|
|
371
|
+
function updatePackageJsonLint(root, configs) {
|
|
372
|
+
const packageJsonPath = node_path.resolve(root, "package.json");
|
|
373
|
+
if (!node_fs.existsSync(packageJsonPath)) {
|
|
374
|
+
console.warn("\u26A0\uFE0F No package.json found");
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
try {
|
|
378
|
+
const packageJson = JSON.parse(
|
|
379
|
+
require("fs").readFileSync(packageJsonPath, "utf-8")
|
|
380
|
+
);
|
|
381
|
+
if (!packageJson.scripts) {
|
|
382
|
+
packageJson.scripts = {};
|
|
383
|
+
}
|
|
384
|
+
if (configs.includes("eslint")) {
|
|
385
|
+
if (!packageJson.scripts.lint) {
|
|
386
|
+
packageJson.scripts.lint = "eslint .";
|
|
387
|
+
}
|
|
388
|
+
if (!packageJson.scripts["lint:fix"]) {
|
|
389
|
+
packageJson.scripts["lint:fix"] = "eslint . --fix";
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (configs.includes("prettier")) {
|
|
393
|
+
if (!packageJson.scripts.format) {
|
|
394
|
+
packageJson.scripts.format = "prettier --write .";
|
|
395
|
+
}
|
|
396
|
+
if (!packageJson.scripts["format:check"]) {
|
|
397
|
+
packageJson.scripts["format:check"] = "prettier --check .";
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
node_fs.writeFileSync(
|
|
401
|
+
packageJsonPath,
|
|
402
|
+
`${JSON.stringify(packageJson, null, 2)}
|
|
403
|
+
`
|
|
404
|
+
);
|
|
405
|
+
console.log("\u2705 Updated package.json with lint scripts");
|
|
406
|
+
} catch (error) {
|
|
407
|
+
console.error("\u274C Failed to update package.json:", error);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async function generateSDK(root = process__default.cwd(), projectName) {
|
|
412
|
+
console.log("\n\u{1F527} Generating SDK from OpenAPI...\n");
|
|
413
|
+
let config = null;
|
|
414
|
+
let openApiUrl;
|
|
415
|
+
try {
|
|
416
|
+
const configPath = node_path.resolve(root, "bgl.config.ts");
|
|
417
|
+
if (node_fs.existsSync(configPath)) {
|
|
418
|
+
const module = await import(`file://${configPath}`);
|
|
419
|
+
const workspace = module.default;
|
|
420
|
+
if (typeof workspace === "function") {
|
|
421
|
+
config = workspace("development");
|
|
422
|
+
openApiUrl = config.openapi_url;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
} catch (error) {
|
|
426
|
+
console.warn("\u26A0\uFE0F Could not load bgl.config.ts");
|
|
427
|
+
}
|
|
428
|
+
const response = await prompts__default([
|
|
429
|
+
{
|
|
430
|
+
type: openApiUrl ? null : "text",
|
|
431
|
+
name: "openApiUrl",
|
|
432
|
+
message: "OpenAPI spec URL:",
|
|
433
|
+
initial: openApiUrl || "http://localhost:8000/openapi.json"
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
type: "text",
|
|
437
|
+
name: "outputDir",
|
|
438
|
+
message: "Output directory:",
|
|
439
|
+
initial: "./src/api"
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
type: "confirm",
|
|
443
|
+
name: "splitFiles",
|
|
444
|
+
message: "Split into organized files?",
|
|
445
|
+
initial: true
|
|
446
|
+
}
|
|
447
|
+
]);
|
|
448
|
+
if (!response) {
|
|
449
|
+
console.log("\n\u274C SDK generation cancelled.\n");
|
|
450
|
+
process__default.exit(1);
|
|
451
|
+
}
|
|
452
|
+
const finalUrl = openApiUrl || response.openApiUrl;
|
|
453
|
+
const { outputDir, splitFiles } = response;
|
|
454
|
+
console.log(`
|
|
455
|
+
\u{1F4E1} Fetching OpenAPI spec from: ${finalUrl}`);
|
|
456
|
+
console.log(`\u{1F4C1} Output directory: ${outputDir}
|
|
457
|
+
`);
|
|
458
|
+
try {
|
|
459
|
+
const { default: openAPI } = await import('@bagelink/sdk');
|
|
460
|
+
const { types, code } = await openAPI(finalUrl, "/api");
|
|
461
|
+
const outputPath = node_path.resolve(root, outputDir);
|
|
462
|
+
if (!node_fs.existsSync(outputPath)) {
|
|
463
|
+
node_fs.mkdirSync(outputPath, { recursive: true });
|
|
464
|
+
}
|
|
465
|
+
const typesPath = node_path.resolve(outputPath, "types.d.ts");
|
|
466
|
+
node_fs.writeFileSync(typesPath, types);
|
|
467
|
+
console.log("\u2705 Generated types.d.ts");
|
|
468
|
+
const apiPath = node_path.resolve(outputPath, "api.ts");
|
|
469
|
+
node_fs.writeFileSync(apiPath, code);
|
|
470
|
+
console.log("\u2705 Generated api.ts");
|
|
471
|
+
const indexPath = node_path.resolve(outputPath, "index.ts");
|
|
472
|
+
node_fs.writeFileSync(
|
|
473
|
+
indexPath,
|
|
474
|
+
"export * from './api'\nexport * from './types.d'\n"
|
|
475
|
+
);
|
|
476
|
+
console.log("\u2705 Generated index.ts");
|
|
477
|
+
if (splitFiles) {
|
|
478
|
+
console.log("\n\u{1F500} Splitting into organized files...");
|
|
479
|
+
try {
|
|
480
|
+
const { splitClientCode } = await import('@bagelink/sdk/bin/splitClientGen');
|
|
481
|
+
await splitClientCode({
|
|
482
|
+
bagelinkDir: outputPath,
|
|
483
|
+
useDirectories: true
|
|
484
|
+
});
|
|
485
|
+
const fs = await import('node:fs');
|
|
486
|
+
fs.rmSync(apiPath, { force: true });
|
|
487
|
+
fs.rmSync(typesPath, { force: true });
|
|
488
|
+
fs.rmSync(indexPath, { force: true });
|
|
489
|
+
console.log("\u2705 Files organized into directories");
|
|
490
|
+
} catch (error) {
|
|
491
|
+
console.warn("\u26A0\uFE0F Could not split files, keeping monolithic structure");
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
console.log("\n\u2705 SDK generated successfully!");
|
|
495
|
+
console.log(`
|
|
496
|
+
Import it in your code:`);
|
|
497
|
+
console.log(` import { api } from '${outputDir.replace("./src/", "./")}'`);
|
|
498
|
+
console.log("");
|
|
499
|
+
} catch (error) {
|
|
500
|
+
console.error("\n\u274C Failed to generate SDK:");
|
|
501
|
+
if (error instanceof Error) {
|
|
502
|
+
console.error(error.message);
|
|
503
|
+
} else {
|
|
504
|
+
console.error(error);
|
|
505
|
+
}
|
|
506
|
+
console.log("\nMake sure:");
|
|
507
|
+
console.log(" 1. @bagelink/sdk is installed: bun add -D @bagelink/sdk");
|
|
508
|
+
console.log(" 2. OpenAPI URL is accessible");
|
|
509
|
+
console.log(" 3. API server is running (if using localhost)");
|
|
510
|
+
process__default.exit(1);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
async function generateSDKForWorkspace(root = process__default.cwd()) {
|
|
514
|
+
console.log("\n\u{1F3E2} Generating SDK for workspace projects...\n");
|
|
515
|
+
const fs = await import('node:fs');
|
|
516
|
+
const items = fs.readdirSync(root, { withFileTypes: true });
|
|
517
|
+
const projects = items.filter(
|
|
518
|
+
(item) => item.isDirectory() && item.name !== "node_modules" && item.name !== "shared" && item.name !== ".git" && !item.name.startsWith(".")
|
|
519
|
+
).map((item) => item.name);
|
|
520
|
+
if (projects.length === 0) {
|
|
521
|
+
console.log("No projects found in workspace");
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
const response = await prompts__default({
|
|
525
|
+
type: "multiselect",
|
|
526
|
+
name: "selectedProjects",
|
|
527
|
+
message: "Select projects to generate SDK for:",
|
|
528
|
+
choices: projects.map((p) => ({ title: p, value: p, selected: true }))
|
|
529
|
+
});
|
|
530
|
+
if (!response || !response.selectedProjects || response.selectedProjects.length === 0) {
|
|
531
|
+
console.log("\n\u274C No projects selected.\n");
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
for (const project of response.selectedProjects) {
|
|
535
|
+
console.log(`
|
|
536
|
+
\u{1F4E6} Generating SDK for: ${project}`);
|
|
537
|
+
const projectPath = node_path.resolve(root, project);
|
|
538
|
+
try {
|
|
539
|
+
await generateSDK(projectPath);
|
|
540
|
+
} catch (error) {
|
|
541
|
+
console.error(`Failed to generate SDK for ${project}:`, error);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
console.log("\n\u2705 All SDKs generated!");
|
|
545
|
+
}
|
|
546
|
+
|
|
241
547
|
async function initWorkspace(root = process__default.cwd()) {
|
|
242
548
|
console.log("\n\u{1F680} Creating Bagel workspace...\n");
|
|
243
549
|
const response = await prompts__default([
|
|
@@ -564,179 +870,11 @@ function listProjects(root = process__default.cwd()) {
|
|
|
564
870
|
}
|
|
565
871
|
}
|
|
566
872
|
|
|
567
|
-
async function setupLint(root = process__default.cwd(), isWorkspace = false) {
|
|
568
|
-
console.log("\n\u{1F50D} Setting up linting...\n");
|
|
569
|
-
const response = await prompts__default([
|
|
570
|
-
{
|
|
571
|
-
type: "multiselect",
|
|
572
|
-
name: "configs",
|
|
573
|
-
message: "Select configurations to set up:",
|
|
574
|
-
choices: [
|
|
575
|
-
{ title: "ESLint", value: "eslint", selected: true },
|
|
576
|
-
{ title: "Prettier", value: "prettier", selected: true },
|
|
577
|
-
{ title: "EditorConfig", value: "editorconfig", selected: true },
|
|
578
|
-
{ title: "Git Hooks", value: "githooks", selected: false }
|
|
579
|
-
]
|
|
580
|
-
},
|
|
581
|
-
{
|
|
582
|
-
type: "confirm",
|
|
583
|
-
name: "installDeps",
|
|
584
|
-
message: "Install dependencies?",
|
|
585
|
-
initial: true
|
|
586
|
-
}
|
|
587
|
-
]);
|
|
588
|
-
if (!response || !response.configs) {
|
|
589
|
-
console.log("\n\u274C Setup cancelled.\n");
|
|
590
|
-
process__default.exit(1);
|
|
591
|
-
}
|
|
592
|
-
const { configs, installDeps } = response;
|
|
593
|
-
if (configs.includes("eslint")) {
|
|
594
|
-
createEslintConfig(root, isWorkspace);
|
|
595
|
-
}
|
|
596
|
-
if (configs.includes("prettier")) {
|
|
597
|
-
createPrettierConfig(root);
|
|
598
|
-
}
|
|
599
|
-
if (configs.includes("editorconfig")) {
|
|
600
|
-
createEditorConfig(root);
|
|
601
|
-
}
|
|
602
|
-
if (configs.includes("githooks")) {
|
|
603
|
-
createGitHooks(root);
|
|
604
|
-
}
|
|
605
|
-
updatePackageJsonLint(root, configs);
|
|
606
|
-
if (installDeps) {
|
|
607
|
-
console.log("\n\u{1F4E6} Installing dependencies...");
|
|
608
|
-
console.log("Run: bun add -D @bagelink/lint-config eslint prettier typescript");
|
|
609
|
-
}
|
|
610
|
-
console.log("\n\u2705 Linting setup complete!");
|
|
611
|
-
console.log("\nAvailable commands:");
|
|
612
|
-
console.log(" bun run lint - Run linter");
|
|
613
|
-
console.log(" bun run lint:fix - Fix linting issues");
|
|
614
|
-
console.log(" bun run format - Format code with Prettier");
|
|
615
|
-
console.log("");
|
|
616
|
-
}
|
|
617
|
-
function createEslintConfig(root, isWorkspace) {
|
|
618
|
-
const configPath = node_path.resolve(root, "eslint.config.js");
|
|
619
|
-
const config = isWorkspace ? `import { defineConfig } from '@bagelink/lint-config/eslint'
|
|
620
|
-
|
|
621
|
-
export default defineConfig({
|
|
622
|
-
// Workspace-level ESLint config
|
|
623
|
-
ignores: ['**/dist/**', '**/node_modules/**', '**/.bun-cache/**'],
|
|
624
|
-
})
|
|
625
|
-
` : `import vue3Config from '@bagelink/lint-config/eslint/vue3'
|
|
626
|
-
|
|
627
|
-
export default vue3Config
|
|
628
|
-
`;
|
|
629
|
-
node_fs.writeFileSync(configPath, config);
|
|
630
|
-
console.log("\u2705 Created eslint.config.js");
|
|
631
|
-
}
|
|
632
|
-
function createPrettierConfig(root) {
|
|
633
|
-
const configPath = node_path.resolve(root, ".prettierrc");
|
|
634
|
-
const config = {
|
|
635
|
-
semi: false,
|
|
636
|
-
singleQuote: true,
|
|
637
|
-
tabWidth: 2,
|
|
638
|
-
useTabs: true,
|
|
639
|
-
trailingComma: "all",
|
|
640
|
-
printWidth: 100,
|
|
641
|
-
arrowParens: "avoid"
|
|
642
|
-
};
|
|
643
|
-
node_fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}
|
|
644
|
-
`);
|
|
645
|
-
console.log("\u2705 Created .prettierrc");
|
|
646
|
-
const ignorePath = node_path.resolve(root, ".prettierignore");
|
|
647
|
-
const ignore = `dist
|
|
648
|
-
node_modules
|
|
649
|
-
.bun-cache
|
|
650
|
-
*.min.js
|
|
651
|
-
*.min.css
|
|
652
|
-
`;
|
|
653
|
-
node_fs.writeFileSync(ignorePath, ignore);
|
|
654
|
-
console.log("\u2705 Created .prettierignore");
|
|
655
|
-
}
|
|
656
|
-
function createEditorConfig(root) {
|
|
657
|
-
const configPath = node_path.resolve(root, ".editorconfig");
|
|
658
|
-
const config = `root = true
|
|
659
|
-
|
|
660
|
-
[*]
|
|
661
|
-
charset = utf-8
|
|
662
|
-
indent_style = tab
|
|
663
|
-
indent_size = 2
|
|
664
|
-
end_of_line = lf
|
|
665
|
-
insert_final_newline = true
|
|
666
|
-
trim_trailing_whitespace = true
|
|
667
|
-
|
|
668
|
-
[*.md]
|
|
669
|
-
trim_trailing_whitespace = false
|
|
670
|
-
|
|
671
|
-
[*.{json,yml,yaml}]
|
|
672
|
-
indent_style = space
|
|
673
|
-
indent_size = 2
|
|
674
|
-
`;
|
|
675
|
-
node_fs.writeFileSync(configPath, config);
|
|
676
|
-
console.log("\u2705 Created .editorconfig");
|
|
677
|
-
}
|
|
678
|
-
function createGitHooks(root) {
|
|
679
|
-
const packageJsonPath = node_path.resolve(root, "package.json");
|
|
680
|
-
if (!node_fs.existsSync(packageJsonPath)) {
|
|
681
|
-
console.warn("\u26A0\uFE0F No package.json found, skipping git hooks");
|
|
682
|
-
return;
|
|
683
|
-
}
|
|
684
|
-
const lintStagedConfig = {
|
|
685
|
-
"*.{js,jsx,ts,tsx,vue}": ["eslint --fix"],
|
|
686
|
-
"*.{json,md,yml,yaml}": ["prettier --write"]
|
|
687
|
-
};
|
|
688
|
-
node_fs.writeFileSync(
|
|
689
|
-
node_path.resolve(root, ".lintstagedrc"),
|
|
690
|
-
`${JSON.stringify(lintStagedConfig, null, 2)}
|
|
691
|
-
`
|
|
692
|
-
);
|
|
693
|
-
console.log("\u2705 Created .lintstagedrc");
|
|
694
|
-
console.log("\u2139\uFE0F Add simple-git-hooks and lint-staged to devDependencies");
|
|
695
|
-
console.log(" Then run: npx simple-git-hooks");
|
|
696
|
-
}
|
|
697
|
-
function updatePackageJsonLint(root, configs) {
|
|
698
|
-
const packageJsonPath = node_path.resolve(root, "package.json");
|
|
699
|
-
if (!node_fs.existsSync(packageJsonPath)) {
|
|
700
|
-
console.warn("\u26A0\uFE0F No package.json found");
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
try {
|
|
704
|
-
const packageJson = JSON.parse(
|
|
705
|
-
require("fs").readFileSync(packageJsonPath, "utf-8")
|
|
706
|
-
);
|
|
707
|
-
if (!packageJson.scripts) {
|
|
708
|
-
packageJson.scripts = {};
|
|
709
|
-
}
|
|
710
|
-
if (configs.includes("eslint")) {
|
|
711
|
-
if (!packageJson.scripts.lint) {
|
|
712
|
-
packageJson.scripts.lint = "eslint .";
|
|
713
|
-
}
|
|
714
|
-
if (!packageJson.scripts["lint:fix"]) {
|
|
715
|
-
packageJson.scripts["lint:fix"] = "eslint . --fix";
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
if (configs.includes("prettier")) {
|
|
719
|
-
if (!packageJson.scripts.format) {
|
|
720
|
-
packageJson.scripts.format = "prettier --write .";
|
|
721
|
-
}
|
|
722
|
-
if (!packageJson.scripts["format:check"]) {
|
|
723
|
-
packageJson.scripts["format:check"] = "prettier --check .";
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
node_fs.writeFileSync(
|
|
727
|
-
packageJsonPath,
|
|
728
|
-
`${JSON.stringify(packageJson, null, 2)}
|
|
729
|
-
`
|
|
730
|
-
);
|
|
731
|
-
console.log("\u2705 Updated package.json with lint scripts");
|
|
732
|
-
} catch (error) {
|
|
733
|
-
console.error("\u274C Failed to update package.json:", error);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
|
|
737
873
|
exports.addProject = addProject;
|
|
738
874
|
exports.generateNetlifyConfig = generateNetlifyConfig;
|
|
739
875
|
exports.generateNetlifyRedirect = generateNetlifyRedirect;
|
|
876
|
+
exports.generateSDK = generateSDK;
|
|
877
|
+
exports.generateSDKForWorkspace = generateSDKForWorkspace;
|
|
740
878
|
exports.generateWorkspaceConfig = generateWorkspaceConfig;
|
|
741
879
|
exports.generateWorkspaceConfigSync = generateWorkspaceConfigSync;
|
|
742
880
|
exports.initWorkspace = initWorkspace;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bagelink/workspace",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.10.0",
|
|
5
5
|
"description": "Monorepo workspace tooling for Bagel projects with proxy and config management",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Bagel Studio",
|
|
@@ -53,11 +53,16 @@
|
|
|
53
53
|
"prompts": "^2.4.2"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
+
"@bagelink/lint-config": ">=1.0.0",
|
|
57
|
+
"@bagelink/sdk": ">=1.0.0",
|
|
56
58
|
"vite": ">=5.0.0"
|
|
57
59
|
},
|
|
58
60
|
"peerDependenciesMeta": {
|
|
59
61
|
"@bagelink/lint-config": {
|
|
60
62
|
"optional": true
|
|
63
|
+
},
|
|
64
|
+
"@bagelink/sdk": {
|
|
65
|
+
"optional": true
|
|
61
66
|
}
|
|
62
67
|
},
|
|
63
68
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -34,8 +34,9 @@ export {
|
|
|
34
34
|
writeNetlifyConfig,
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export { addProject, initWorkspace, listProjects } from './workspace'
|
|
38
37
|
export { setupLint } from './lint'
|
|
38
|
+
export { generateSDK, generateSDKForWorkspace } from './sdk'
|
|
39
|
+
export { addProject, initWorkspace, listProjects } from './workspace'
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* Define workspace configuration
|