@farming-labs/docs 0.0.2-beta.2 → 0.0.2-beta.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.
Files changed (2) hide show
  1. package/dist/cli/index.mjs +65 -9
  2. package/package.json +1 -1
@@ -53,6 +53,24 @@ function readFileSafe(filePath) {
53
53
  if (!fs.existsSync(filePath)) return null;
54
54
  return fs.readFileSync(filePath, "utf-8");
55
55
  }
56
+ /** Common locations where global CSS files live in Next.js projects. */
57
+ const GLOBAL_CSS_CANDIDATES = [
58
+ "app/globals.css",
59
+ "app/global.css",
60
+ "src/app/globals.css",
61
+ "src/app/global.css",
62
+ "styles/globals.css",
63
+ "styles/global.css",
64
+ "src/styles/globals.css",
65
+ "src/styles/global.css"
66
+ ];
67
+ /**
68
+ * Find existing global CSS files in the project.
69
+ * Returns relative paths that exist.
70
+ */
71
+ function detectGlobalCssFiles(cwd) {
72
+ return GLOBAL_CSS_CANDIDATES.filter((rel) => fs.existsSync(path.join(cwd, rel)));
73
+ }
56
74
  /**
57
75
  * Run a shell command synchronously, inheriting stdio.
58
76
  */
@@ -151,12 +169,16 @@ function nextConfigMergedTemplate(existingContent) {
151
169
  }
152
170
  return lines.join("\n");
153
171
  }
154
- function rootLayoutTemplate() {
172
+ function rootLayoutTemplate(globalCssRelPath = "app/globals.css") {
173
+ let cssImport;
174
+ if (globalCssRelPath.startsWith("app/")) cssImport = "./" + globalCssRelPath.slice(4);
175
+ else if (globalCssRelPath.startsWith("src/app/")) cssImport = "./" + globalCssRelPath.slice(8);
176
+ else cssImport = "../" + globalCssRelPath;
155
177
  return `\
156
178
  import type { Metadata } from "next";
157
179
  import { RootProvider } from "@farming-labs/fumadocs";
158
180
  import docsConfig from "@/docs.config";
159
- import "./global.css";
181
+ import "${cssImport}";
160
182
 
161
183
  export const metadata: Metadata = {
162
184
  title: {
@@ -458,6 +480,40 @@ async function init() {
458
480
  process.exit(0);
459
481
  }
460
482
  const entryPath = entry;
483
+ const detectedCssFiles = detectGlobalCssFiles(cwd);
484
+ let globalCssRelPath;
485
+ if (detectedCssFiles.length === 1) {
486
+ globalCssRelPath = detectedCssFiles[0];
487
+ p.log.info(`Found global CSS at ${pc.cyan(globalCssRelPath)}`);
488
+ } else if (detectedCssFiles.length > 1) {
489
+ const picked = await p.select({
490
+ message: "Multiple global CSS files found. Which one should we use?",
491
+ options: detectedCssFiles.map((f) => ({
492
+ value: f,
493
+ label: f
494
+ }))
495
+ });
496
+ if (p.isCancel(picked)) {
497
+ p.outro(pc.red("Init cancelled."));
498
+ process.exit(0);
499
+ }
500
+ globalCssRelPath = picked;
501
+ } else {
502
+ const cssPath = await p.text({
503
+ message: "Where is your global CSS file?",
504
+ placeholder: "app/globals.css",
505
+ defaultValue: "app/globals.css",
506
+ validate: (value) => {
507
+ if (!value) return "CSS file path is required";
508
+ if (!value.endsWith(".css")) return "Path must end with .css";
509
+ }
510
+ });
511
+ if (p.isCancel(cssPath)) {
512
+ p.outro(pc.red("Init cancelled."));
513
+ process.exit(0);
514
+ }
515
+ globalCssRelPath = cssPath;
516
+ }
461
517
  const pkgJson = JSON.parse(readFileSafe(path.join(cwd, "package.json")));
462
518
  const cfg = {
463
519
  entry: entryPath,
@@ -482,16 +538,16 @@ async function init() {
482
538
  written.push(configFile + " (updated)");
483
539
  } else skipped.push(configFile + " (already configured)");
484
540
  } else write("next.config.ts", nextConfigTemplate());
485
- write("app/layout.tsx", rootLayoutTemplate());
486
- const globalCssPath = path.join(cwd, "app/global.css");
487
- const existingGlobalCss = readFileSafe(globalCssPath);
541
+ write("app/layout.tsx", rootLayoutTemplate(globalCssRelPath));
542
+ const globalCssAbsPath = path.join(cwd, globalCssRelPath);
543
+ const existingGlobalCss = readFileSafe(globalCssAbsPath);
488
544
  if (existingGlobalCss) {
489
545
  const injected = injectCssImport(existingGlobalCss, theme);
490
546
  if (injected) {
491
- writeFileSafe(globalCssPath, injected, true);
492
- written.push("app/global.css (updated)");
493
- } else skipped.push("app/global.css (already configured)");
494
- } else write("app/global.css", globalCssTemplate(theme));
547
+ writeFileSafe(globalCssAbsPath, injected, true);
548
+ written.push(globalCssRelPath + " (updated)");
549
+ } else skipped.push(globalCssRelPath + " (already configured)");
550
+ } else write(globalCssRelPath, globalCssTemplate(theme));
495
551
  write(`app/${entryPath}/layout.tsx`, docsLayoutTemplate());
496
552
  write("postcss.config.mjs", postcssConfigTemplate());
497
553
  if (!fileExists(path.join(cwd, "tsconfig.json"))) write("tsconfig.json", tsconfigTemplate());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/docs",
3
- "version": "0.0.2-beta.2",
3
+ "version": "0.0.2-beta.3",
4
4
  "description": "Modern, flexible MDX-based docs framework — core types, config, and CLI",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",