bejamas 0.2.10 → 0.2.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 +2 -0
- package/dist/{generate-mdx-C1y987mC.js → generate-mdx-C8gXBOHp.js} +3 -3
- package/dist/{generate-mdx-C1y987mC.js.map → generate-mdx-C8gXBOHp.js.map} +1 -1
- package/dist/index.js +95 -35
- package/dist/index.js.map +1 -1
- package/dist/{utils-gYZJgF4G.js → utils-Dr0kJLcx.js} +6 -103
- package/dist/utils-Dr0kJLcx.js.map +1 -0
- package/package.json +1 -1
- package/dist/utils-gYZJgF4G.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { _ as getWorkspaceConfig, b as highlighter, d as parseJsDocMetadata, g as getConfig, o as extractFrontmatter, p as resolveUiRoot, v as spinner, y as logger } from "./utils-Dr0kJLcx.js";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { createRequire } from "module";
|
|
5
|
+
import { promises } from "fs";
|
|
5
6
|
import path from "path";
|
|
6
7
|
import fsExtra from "fs-extra";
|
|
7
8
|
import os from "os";
|
|
@@ -13,7 +14,7 @@ import { execa } from "execa";
|
|
|
13
14
|
import prompts from "prompts";
|
|
14
15
|
import fg from "fast-glob";
|
|
15
16
|
import path$1, { extname as extname$1, isAbsolute, join as join$1, relative as relative$1, resolve } from "node:path";
|
|
16
|
-
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
17
|
+
import { existsSync as existsSync$1, readFileSync, readdirSync } from "node:fs";
|
|
17
18
|
import fs from "node:fs/promises";
|
|
18
19
|
|
|
19
20
|
//#region src/utils/errors.ts
|
|
@@ -290,6 +291,8 @@ async function createProjectFromTemplate(projectPath, options) {
|
|
|
290
291
|
//#endregion
|
|
291
292
|
//#region src/commands/init.ts
|
|
292
293
|
const DEFAULT_REGISTRY_URL$1 = "https://ui.bejamas.com/r";
|
|
294
|
+
const DEFAULT_COMPONENTS_BASE_COLOR = "neutral";
|
|
295
|
+
const SHADCN_INIT_ARGS = ["init"];
|
|
293
296
|
const initOptionsSchema = z.object({
|
|
294
297
|
cwd: z.string(),
|
|
295
298
|
components: z.array(z.string()).optional(),
|
|
@@ -304,13 +307,82 @@ const initOptionsSchema = z.object({
|
|
|
304
307
|
if (val) return TEMPLATES[val];
|
|
305
308
|
return true;
|
|
306
309
|
}, { message: "Invalid template. Please use 'next' or 'next-monorepo'." }),
|
|
307
|
-
baseColor: z.string().optional()
|
|
308
|
-
if (val) return BASE_COLORS.find((color) => color.name === val);
|
|
309
|
-
return true;
|
|
310
|
-
}, { message: `Invalid base color. Please use '${BASE_COLORS.map((color) => color.name).join("', '")}'` }),
|
|
310
|
+
baseColor: z.string().optional(),
|
|
311
311
|
baseStyle: z.boolean()
|
|
312
312
|
});
|
|
313
|
-
|
|
313
|
+
function buildShadcnInitInvocation(localShadcnPath, hasLocalShadcn, localShadcnVersion) {
|
|
314
|
+
if (hasLocalShadcn) {
|
|
315
|
+
const args = [...SHADCN_INIT_ARGS];
|
|
316
|
+
if (usesLegacyBaseColorFlag(localShadcnVersion)) args.push("--base-color", DEFAULT_COMPONENTS_BASE_COLOR);
|
|
317
|
+
return {
|
|
318
|
+
cmd: localShadcnPath,
|
|
319
|
+
args
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
cmd: "npx",
|
|
324
|
+
args: [
|
|
325
|
+
"-y",
|
|
326
|
+
"shadcn@latest",
|
|
327
|
+
...SHADCN_INIT_ARGS
|
|
328
|
+
]
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
function usesLegacyBaseColorFlag(version) {
|
|
332
|
+
if (!version) return false;
|
|
333
|
+
const major = Number.parseInt(version.split(".")[0] ?? "", 10);
|
|
334
|
+
return Number.isFinite(major) && major > 0 && major < 4;
|
|
335
|
+
}
|
|
336
|
+
async function getLocalShadcnVersion(cwd) {
|
|
337
|
+
const filePath = path.resolve(cwd, "node_modules", "shadcn", "package.json");
|
|
338
|
+
try {
|
|
339
|
+
const contents = await promises.readFile(filePath, "utf8");
|
|
340
|
+
const parsed = JSON.parse(contents);
|
|
341
|
+
return typeof parsed.version === "string" ? parsed.version : null;
|
|
342
|
+
} catch {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function getDeprecatedBaseColorWarning(baseColor) {
|
|
347
|
+
if (!baseColor) return null;
|
|
348
|
+
return [
|
|
349
|
+
"The --base-color option is deprecated and ignored.",
|
|
350
|
+
"Bejamas now aligns with shadcn CLI v4.",
|
|
351
|
+
`Edit ${highlighter.info("components.json")} to change`,
|
|
352
|
+
`${highlighter.info("tailwind.baseColor")} after init.`
|
|
353
|
+
].join(" ");
|
|
354
|
+
}
|
|
355
|
+
async function normalizeComponentsBaseColor(cwd, baseColor = DEFAULT_COMPONENTS_BASE_COLOR) {
|
|
356
|
+
const filePath = path.resolve(cwd, "components.json");
|
|
357
|
+
let originalContents;
|
|
358
|
+
try {
|
|
359
|
+
originalContents = await promises.readFile(filePath, "utf8");
|
|
360
|
+
} catch {
|
|
361
|
+
throw new Error(`Failed to read ${highlighter.info(filePath)} after shadcn init. Make sure the command completed successfully and created a valid components.json file.`);
|
|
362
|
+
}
|
|
363
|
+
let parsedConfig;
|
|
364
|
+
try {
|
|
365
|
+
const parsed = JSON.parse(originalContents);
|
|
366
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("Expected a JSON object.");
|
|
367
|
+
parsedConfig = parsed;
|
|
368
|
+
} catch {
|
|
369
|
+
throw new Error(`Failed to parse ${highlighter.info(filePath)} after shadcn init. Expected a valid JSON object with a tailwind configuration.`);
|
|
370
|
+
}
|
|
371
|
+
const tailwind = parsedConfig.tailwind;
|
|
372
|
+
if (!tailwind || typeof tailwind !== "object" || Array.isArray(tailwind)) throw new Error(`Invalid ${highlighter.info(filePath)} generated by shadcn init. Expected a ${highlighter.info("tailwind")} object so Bejamas can normalize ${highlighter.info("baseColor")}.`);
|
|
373
|
+
const normalizedConfig = {
|
|
374
|
+
...parsedConfig,
|
|
375
|
+
tailwind: {
|
|
376
|
+
...tailwind,
|
|
377
|
+
baseColor
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
const normalizedContents = `${JSON.stringify(normalizedConfig, null, 2)}\n`;
|
|
381
|
+
if (normalizedContents === originalContents) return false;
|
|
382
|
+
await promises.writeFile(filePath, normalizedContents, "utf8");
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
const init = new Command().name("init").description("initialize your project and install dependencies").argument("[components...]", "names, url or local path to component").option("-t, --template <template>", "the template to use. (next, next-monorepo)").option("-b, --base-color <base-color>", "deprecated: accepted for compatibility but ignored. Edit components.json to change tailwind.baseColor.", void 0).option("-y, --yes", "skip confirmation prompt.", true).option("-d, --defaults,", "use default configuration.", false).option("-f, --force", "force overwrite of existing configuration.", false).option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("-s, --silent", "mute output.", false).option("--src-dir", "use the src directory when creating a new project.", false).option("--no-src-dir", "do not use the src directory when creating a new project.").option("--css-variables", "use css variables for theming.", true).option("--no-css-variables", "do not use css variables for theming.").option("--no-base-style", "do not install the base shadcn style.").action(async (_components, opts) => {
|
|
314
386
|
try {
|
|
315
387
|
await runInit(opts);
|
|
316
388
|
} catch (error) {
|
|
@@ -321,18 +393,18 @@ const init = new Command().name("init").description("initialize your project and
|
|
|
321
393
|
}
|
|
322
394
|
});
|
|
323
395
|
async function runInit(options) {
|
|
396
|
+
const baseColorWarning = getDeprecatedBaseColorWarning(options.baseColor);
|
|
397
|
+
if (baseColorWarning && !options.silent) logger.warn(baseColorWarning);
|
|
324
398
|
let newProjectTemplate;
|
|
325
399
|
if (!options.skipPreflight) {
|
|
326
|
-
|
|
327
|
-
if (preflight.errors[MISSING_DIR_OR_EMPTY_PROJECT]) {
|
|
400
|
+
if ((await preFlightInit(options)).errors[MISSING_DIR_OR_EMPTY_PROJECT]) {
|
|
328
401
|
const { projectPath, template } = await createProject(options);
|
|
329
402
|
if (!projectPath) process.exit(1);
|
|
330
403
|
options.cwd = projectPath;
|
|
331
404
|
options.isNewProject = true;
|
|
332
405
|
newProjectTemplate = template;
|
|
333
406
|
}
|
|
334
|
-
|
|
335
|
-
} else await getProjectInfo(options.cwd);
|
|
407
|
+
}
|
|
336
408
|
if (newProjectTemplate) {
|
|
337
409
|
options.cwd = path.resolve(options.cwd, {
|
|
338
410
|
"astro-monorepo": "apps/web",
|
|
@@ -349,22 +421,9 @@ async function runInit(options) {
|
|
|
349
421
|
...process.env,
|
|
350
422
|
REGISTRY_URL: process.env.REGISTRY_URL || DEFAULT_REGISTRY_URL$1
|
|
351
423
|
};
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
"neutral"
|
|
356
|
-
], {
|
|
357
|
-
stdio: "inherit",
|
|
358
|
-
cwd: options.cwd,
|
|
359
|
-
env
|
|
360
|
-
});
|
|
361
|
-
else await execa("npx", [
|
|
362
|
-
"-y",
|
|
363
|
-
"shadcn@latest",
|
|
364
|
-
"init",
|
|
365
|
-
"--base-color",
|
|
366
|
-
"neutral"
|
|
367
|
-
], {
|
|
424
|
+
const hasLocalShadcn = await fsExtra.pathExists(localShadcnPath);
|
|
425
|
+
const invocation = buildShadcnInitInvocation(localShadcnPath, hasLocalShadcn, hasLocalShadcn ? await getLocalShadcnVersion(options.cwd) : null);
|
|
426
|
+
await execa(invocation.cmd, invocation.args, {
|
|
368
427
|
stdio: "inherit",
|
|
369
428
|
cwd: options.cwd,
|
|
370
429
|
env
|
|
@@ -372,6 +431,7 @@ async function runInit(options) {
|
|
|
372
431
|
} catch (err) {
|
|
373
432
|
process.exit(1);
|
|
374
433
|
}
|
|
434
|
+
await normalizeComponentsBaseColor(options.cwd);
|
|
375
435
|
}
|
|
376
436
|
|
|
377
437
|
//#endregion
|
|
@@ -382,7 +442,7 @@ async function runInit(options) {
|
|
|
382
442
|
function readTsConfig(projectRoot) {
|
|
383
443
|
try {
|
|
384
444
|
const tsconfigPath = resolve(projectRoot, "tsconfig.json");
|
|
385
|
-
if (!existsSync(tsconfigPath)) return null;
|
|
445
|
+
if (!existsSync$1(tsconfigPath)) return null;
|
|
386
446
|
const raw = readFileSync(tsconfigPath, "utf-8");
|
|
387
447
|
return JSON.parse(raw);
|
|
388
448
|
} catch {
|
|
@@ -420,7 +480,7 @@ async function generateDocs({ cwd, outDir, verbose }) {
|
|
|
420
480
|
let probe = shellCwd;
|
|
421
481
|
for (let i = 0; i < 6 && probe; i += 1) {
|
|
422
482
|
const candidate = resolve(probe, "components.json");
|
|
423
|
-
if (existsSync(candidate)) {
|
|
483
|
+
if (existsSync$1(candidate)) {
|
|
424
484
|
projectRoot = probe;
|
|
425
485
|
try {
|
|
426
486
|
const raw = readFileSync(candidate, "utf-8");
|
|
@@ -474,7 +534,7 @@ async function generateDocs({ cwd, outDir, verbose }) {
|
|
|
474
534
|
initial: (() => {
|
|
475
535
|
let current = shellCwd;
|
|
476
536
|
for (let i = 0; i < 6; i += 1) {
|
|
477
|
-
if (existsSync(resolve(current, "packages/ui/package.json"))) {
|
|
537
|
+
if (existsSync$1(resolve(current, "packages/ui/package.json"))) {
|
|
478
538
|
const abs = resolve(current, "packages/ui");
|
|
479
539
|
return relative$1(shellCwd, abs) || abs;
|
|
480
540
|
}
|
|
@@ -482,7 +542,7 @@ async function generateDocs({ cwd, outDir, verbose }) {
|
|
|
482
542
|
if (parent === current) break;
|
|
483
543
|
current = parent;
|
|
484
544
|
}
|
|
485
|
-
if (existsSync(resolve(shellCwd, "node_modules/@bejamas/ui/package.json"))) {
|
|
545
|
+
if (existsSync$1(resolve(shellCwd, "node_modules/@bejamas/ui/package.json"))) {
|
|
486
546
|
const abs = resolve(shellCwd, "node_modules/@bejamas/ui");
|
|
487
547
|
return relative$1(shellCwd, abs) || abs;
|
|
488
548
|
}
|
|
@@ -490,7 +550,7 @@ async function generateDocs({ cwd, outDir, verbose }) {
|
|
|
490
550
|
})(),
|
|
491
551
|
validate: (val) => {
|
|
492
552
|
const p = resolve(shellCwd, val);
|
|
493
|
-
return existsSync(resolve(p, "package.json")) ? true : `No package.json found in ${p}`;
|
|
553
|
+
return existsSync$1(resolve(p, "package.json")) ? true : `No package.json found in ${p}`;
|
|
494
554
|
}
|
|
495
555
|
});
|
|
496
556
|
if (!uiRoot) {
|
|
@@ -523,7 +583,7 @@ async function generateDocs({ cwd, outDir, verbose }) {
|
|
|
523
583
|
if (process.env.BEJAMAS_DOCS_CWD) logger.info(`Docs CWD: ${process.env.BEJAMAS_DOCS_CWD}`);
|
|
524
584
|
if (process.env.BEJAMAS_DOCS_OUT_DIR) logger.info(`Docs out: ${process.env.BEJAMAS_DOCS_OUT_DIR}`);
|
|
525
585
|
}
|
|
526
|
-
const mod = await import("./generate-mdx-
|
|
586
|
+
const mod = await import("./generate-mdx-C8gXBOHp.js");
|
|
527
587
|
if (typeof mod.runDocsGenerator === "function") await mod.runDocsGenerator();
|
|
528
588
|
else throw new Error("Failed to load docs generator. Export 'runDocsGenerator' not found.");
|
|
529
589
|
} catch (err) {
|
|
@@ -591,7 +651,7 @@ async function checkDocs({ cwd, json }) {
|
|
|
591
651
|
let probe = shellCwd;
|
|
592
652
|
for (let i = 0; i < 6 && probe; i += 1) {
|
|
593
653
|
const candidate = resolve(probe, "components.json");
|
|
594
|
-
if (existsSync(candidate)) {
|
|
654
|
+
if (existsSync$1(candidate)) {
|
|
595
655
|
projectRoot = probe;
|
|
596
656
|
try {
|
|
597
657
|
const raw = readFileSync(candidate, "utf-8");
|
|
@@ -630,7 +690,7 @@ async function checkDocs({ cwd, json }) {
|
|
|
630
690
|
process.exit(1);
|
|
631
691
|
}
|
|
632
692
|
const componentsDir = join$1(uiRoot, "src", "components");
|
|
633
|
-
if (!existsSync(componentsDir)) {
|
|
693
|
+
if (!existsSync$1(componentsDir)) {
|
|
634
694
|
logger.error(`Components directory not found: ${componentsDir}\n\nExpected structure: <uiRoot>/src/components/*.astro\nUse --cwd to specify a different UI package root.`);
|
|
635
695
|
process.exit(1);
|
|
636
696
|
}
|