@farming-labs/docs 0.0.2-beta.6 → 0.0.2-beta.8

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 +49 -19
  2. package/package.json +1 -1
@@ -154,6 +154,30 @@ const THEME_INFO = {
154
154
  function getThemeInfo(theme) {
155
155
  return THEME_INFO[theme] ?? THEME_INFO.fumadocs;
156
156
  }
157
+ /** Config import for Next.js app/layout.tsx → root docs.config */
158
+ function nextRootLayoutConfigImport(useAlias) {
159
+ return useAlias ? "@/docs.config" : "../docs.config";
160
+ }
161
+ /** Config import for Next.js app/{entry}/layout.tsx → root docs.config */
162
+ function nextDocsLayoutConfigImport(useAlias) {
163
+ return useAlias ? "@/docs.config" : "../../docs.config";
164
+ }
165
+ /** Config import for SvelteKit src/lib/docs.server.ts → src/lib/docs.config.js */
166
+ function svelteServerConfigImport(useAlias) {
167
+ return useAlias ? "$lib/docs.config.js" : "./docs.config.js";
168
+ }
169
+ /** Config import for SvelteKit src/routes/{entry}/+layout.svelte → src/lib/docs.config.js */
170
+ function svelteLayoutConfigImport(useAlias) {
171
+ return useAlias ? "$lib/docs.config.js" : "../../lib/docs.config.js";
172
+ }
173
+ /** Config import for SvelteKit src/routes/{entry}/[...slug]/+page.svelte → src/lib/docs.config.js */
174
+ function sveltePageConfigImport(useAlias) {
175
+ return useAlias ? "$lib/docs.config.js" : "../../../lib/docs.config.js";
176
+ }
177
+ /** Server import for SvelteKit +layout.server.js → src/lib/docs.server.js */
178
+ function svelteLayoutServerImport(useAlias) {
179
+ return useAlias ? "$lib/docs.server.js" : "../../lib/docs.server.js";
180
+ }
157
181
  function docsConfigTemplate(cfg) {
158
182
  const t = getThemeInfo(cfg.theme);
159
183
  return `\
@@ -199,7 +223,7 @@ function nextConfigMergedTemplate(existingContent) {
199
223
  }
200
224
  return lines.join("\n");
201
225
  }
202
- function rootLayoutTemplate(globalCssRelPath = "app/globals.css") {
226
+ function rootLayoutTemplate(cfg, globalCssRelPath = "app/globals.css") {
203
227
  let cssImport;
204
228
  if (globalCssRelPath.startsWith("app/")) cssImport = "./" + globalCssRelPath.slice(4);
205
229
  else if (globalCssRelPath.startsWith("src/app/")) cssImport = "./" + globalCssRelPath.slice(8);
@@ -207,7 +231,7 @@ function rootLayoutTemplate(globalCssRelPath = "app/globals.css") {
207
231
  return `\
208
232
  import type { Metadata } from "next";
209
233
  import { RootProvider } from "@farming-labs/theme";
210
- import docsConfig from "@/docs.config";
234
+ import docsConfig from "${nextRootLayoutConfigImport(cfg.useAlias)}";
211
235
  import "${cssImport}";
212
236
 
213
237
  export const metadata: Metadata = {
@@ -239,10 +263,6 @@ function globalCssTemplate(theme) {
239
263
  @import "@farming-labs/theme/${getThemeInfo(theme).nextCssImport}/css";
240
264
  `;
241
265
  }
242
- /**
243
- * Inject the fumadocs CSS import into an existing global.css.
244
- * Returns the modified content, or null if already present.
245
- */
246
266
  function injectCssImport(existingContent, theme) {
247
267
  const importLine = `@import "@farming-labs/theme/${getThemeInfo(theme).nextCssImport}/css";`;
248
268
  if (existingContent.includes(importLine)) return null;
@@ -253,9 +273,9 @@ function injectCssImport(existingContent, theme) {
253
273
  else lines.unshift(importLine);
254
274
  return lines.join("\n");
255
275
  }
256
- function docsLayoutTemplate() {
276
+ function docsLayoutTemplate(cfg) {
257
277
  return `\
258
- import docsConfig from "@/docs.config";
278
+ import docsConfig from "${nextDocsLayoutConfigImport(cfg.useAlias)}";
259
279
  import { createDocsLayout } from "@farming-labs/theme";
260
280
 
261
281
  export default createDocsLayout(docsConfig);
@@ -482,7 +502,6 @@ import { ${t.factory} } from "${t.svelteImport}";
482
502
 
483
503
  export default defineDocs({
484
504
  entry: "${cfg.entry}",
485
- contentDir: "${cfg.entry}",
486
505
  theme: ${t.factory}({
487
506
  ui: {
488
507
  colors: { primary: "#6366f1" },
@@ -506,7 +525,7 @@ export default defineDocs({
506
525
  function svelteDocsServerTemplate(cfg) {
507
526
  return `\
508
527
  import { createDocsServer } from "@farming-labs/svelte/server";
509
- import config from "$lib/docs.config.js";
528
+ import config from "${svelteServerConfigImport(cfg.useAlias)}";
510
529
 
511
530
  export const { load, GET, POST } = createDocsServer(config);
512
531
  `;
@@ -515,7 +534,7 @@ function svelteDocsLayoutTemplate(cfg) {
515
534
  return `\
516
535
  <script>
517
536
  import { DocsLayout } from "@farming-labs/svelte-theme";
518
- import config from "$lib/docs.config.js";
537
+ import config from "${svelteLayoutConfigImport(cfg.useAlias)}";
519
538
 
520
539
  let { data, children } = $props();
521
540
  <\/script>
@@ -525,16 +544,16 @@ function svelteDocsLayoutTemplate(cfg) {
525
544
  </DocsLayout>
526
545
  `;
527
546
  }
528
- function svelteDocsLayoutServerTemplate() {
547
+ function svelteDocsLayoutServerTemplate(cfg) {
529
548
  return `\
530
- export { load } from "$lib/docs.server.js";
549
+ export { load } from "${svelteLayoutServerImport(cfg.useAlias)}";
531
550
  `;
532
551
  }
533
552
  function svelteDocsPageTemplate(cfg) {
534
553
  return `\
535
554
  <script>
536
555
  import { DocsContent } from "@farming-labs/svelte-theme";
537
- import config from "$lib/docs.config.js";
556
+ import config from "${sveltePageConfigImport(cfg.useAlias)}";
538
557
 
539
558
  let { data } = $props();
540
559
  <\/script>
@@ -793,6 +812,15 @@ async function init() {
793
812
  p.outro(pc.red("Init cancelled."));
794
813
  process.exit(0);
795
814
  }
815
+ const aliasHint = framework === "nextjs" ? `Uses ${pc.cyan("@/")} prefix (requires tsconfig paths)` : `Uses ${pc.cyan("$lib/")} prefix (SvelteKit built-in)`;
816
+ const useAlias = await p.confirm({
817
+ message: `Use path aliases for imports? ${pc.dim(aliasHint)}`,
818
+ initialValue: false
819
+ });
820
+ if (p.isCancel(useAlias)) {
821
+ p.outro(pc.red("Init cancelled."));
822
+ process.exit(0);
823
+ }
796
824
  const entry = await p.text({
797
825
  message: "Where should your docs live?",
798
826
  placeholder: "docs",
@@ -843,12 +871,14 @@ async function init() {
843
871
  }
844
872
  globalCssRelPath = cssPath;
845
873
  }
846
- const pkgJson = JSON.parse(readFileSafe(path.join(cwd, "package.json")));
874
+ const pkgJsonContent = readFileSafe(path.join(cwd, "package.json"));
875
+ const pkgJson = pkgJsonContent ? JSON.parse(pkgJsonContent) : { name: "my-project" };
847
876
  const cfg = {
848
877
  entry: entryPath,
849
878
  theme,
850
879
  projectName: pkgJson.name || "My Project",
851
- framework
880
+ framework,
881
+ useAlias
852
882
  };
853
883
  const s = p.spinner();
854
884
  s.start("Scaffolding docs files");
@@ -954,7 +984,7 @@ function scaffoldNextJs(cwd, cfg, globalCssRelPath, write, skipped, written) {
954
984
  written.push(configFile + " (updated)");
955
985
  } else skipped.push(configFile + " (already configured)");
956
986
  } else write("next.config.ts", nextConfigTemplate());
957
- write("app/layout.tsx", rootLayoutTemplate(globalCssRelPath));
987
+ write("app/layout.tsx", rootLayoutTemplate(cfg, globalCssRelPath));
958
988
  const globalCssAbsPath = path.join(cwd, globalCssRelPath);
959
989
  const existingGlobalCss = readFileSafe(globalCssAbsPath);
960
990
  if (existingGlobalCss) {
@@ -964,7 +994,7 @@ function scaffoldNextJs(cwd, cfg, globalCssRelPath, write, skipped, written) {
964
994
  written.push(globalCssRelPath + " (updated)");
965
995
  } else skipped.push(globalCssRelPath + " (already configured)");
966
996
  } else write(globalCssRelPath, globalCssTemplate(cfg.theme));
967
- write(`app/${cfg.entry}/layout.tsx`, docsLayoutTemplate());
997
+ write(`app/${cfg.entry}/layout.tsx`, docsLayoutTemplate(cfg));
968
998
  write("postcss.config.mjs", postcssConfigTemplate());
969
999
  if (!fileExists(path.join(cwd, "tsconfig.json"))) write("tsconfig.json", tsconfigTemplate());
970
1000
  write(`app/${cfg.entry}/page.mdx`, welcomePageTemplate(cfg));
@@ -975,7 +1005,7 @@ function scaffoldSvelteKit(cwd, cfg, globalCssRelPath, write, skipped, written)
975
1005
  write("src/lib/docs.config.ts", svelteDocsConfigTemplate(cfg));
976
1006
  write("src/lib/docs.server.ts", svelteDocsServerTemplate(cfg));
977
1007
  write(`src/routes/${cfg.entry}/+layout.svelte`, svelteDocsLayoutTemplate(cfg));
978
- write(`src/routes/${cfg.entry}/+layout.server.js`, svelteDocsLayoutServerTemplate());
1008
+ write(`src/routes/${cfg.entry}/+layout.server.js`, svelteDocsLayoutServerTemplate(cfg));
979
1009
  write(`src/routes/${cfg.entry}/[...slug]/+page.svelte`, svelteDocsPageTemplate(cfg));
980
1010
  if (!readFileSafe(path.join(cwd, "src/routes/+layout.svelte"))) write("src/routes/+layout.svelte", svelteRootLayoutTemplate(globalCssRelPath));
981
1011
  const globalCssAbsPath = path.join(cwd, globalCssRelPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/docs",
3
- "version": "0.0.2-beta.6",
3
+ "version": "0.0.2-beta.8",
4
4
  "description": "Modern, flexible MDX-based docs framework — core types, config, and CLI",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",