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

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 -18
  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);
@@ -506,7 +526,7 @@ export default defineDocs({
506
526
  function svelteDocsServerTemplate(cfg) {
507
527
  return `\
508
528
  import { createDocsServer } from "@farming-labs/svelte/server";
509
- import config from "$lib/docs.config.js";
529
+ import config from "${svelteServerConfigImport(cfg.useAlias)}";
510
530
 
511
531
  export const { load, GET, POST } = createDocsServer(config);
512
532
  `;
@@ -515,7 +535,7 @@ function svelteDocsLayoutTemplate(cfg) {
515
535
  return `\
516
536
  <script>
517
537
  import { DocsLayout } from "@farming-labs/svelte-theme";
518
- import config from "$lib/docs.config.js";
538
+ import config from "${svelteLayoutConfigImport(cfg.useAlias)}";
519
539
 
520
540
  let { data, children } = $props();
521
541
  <\/script>
@@ -525,16 +545,16 @@ function svelteDocsLayoutTemplate(cfg) {
525
545
  </DocsLayout>
526
546
  `;
527
547
  }
528
- function svelteDocsLayoutServerTemplate() {
548
+ function svelteDocsLayoutServerTemplate(cfg) {
529
549
  return `\
530
- export { load } from "$lib/docs.server.js";
550
+ export { load } from "${svelteLayoutServerImport(cfg.useAlias)}";
531
551
  `;
532
552
  }
533
553
  function svelteDocsPageTemplate(cfg) {
534
554
  return `\
535
555
  <script>
536
556
  import { DocsContent } from "@farming-labs/svelte-theme";
537
- import config from "$lib/docs.config.js";
557
+ import config from "${sveltePageConfigImport(cfg.useAlias)}";
538
558
 
539
559
  let { data } = $props();
540
560
  <\/script>
@@ -793,6 +813,15 @@ async function init() {
793
813
  p.outro(pc.red("Init cancelled."));
794
814
  process.exit(0);
795
815
  }
816
+ const aliasHint = framework === "nextjs" ? `Uses ${pc.cyan("@/")} prefix (requires tsconfig paths)` : `Uses ${pc.cyan("$lib/")} prefix (SvelteKit built-in)`;
817
+ const useAlias = await p.confirm({
818
+ message: `Use path aliases for imports? ${pc.dim(aliasHint)}`,
819
+ initialValue: false
820
+ });
821
+ if (p.isCancel(useAlias)) {
822
+ p.outro(pc.red("Init cancelled."));
823
+ process.exit(0);
824
+ }
796
825
  const entry = await p.text({
797
826
  message: "Where should your docs live?",
798
827
  placeholder: "docs",
@@ -843,12 +872,14 @@ async function init() {
843
872
  }
844
873
  globalCssRelPath = cssPath;
845
874
  }
846
- const pkgJson = JSON.parse(readFileSafe(path.join(cwd, "package.json")));
875
+ const pkgJsonContent = readFileSafe(path.join(cwd, "package.json"));
876
+ const pkgJson = pkgJsonContent ? JSON.parse(pkgJsonContent) : { name: "my-project" };
847
877
  const cfg = {
848
878
  entry: entryPath,
849
879
  theme,
850
880
  projectName: pkgJson.name || "My Project",
851
- framework
881
+ framework,
882
+ useAlias
852
883
  };
853
884
  const s = p.spinner();
854
885
  s.start("Scaffolding docs files");
@@ -954,7 +985,7 @@ function scaffoldNextJs(cwd, cfg, globalCssRelPath, write, skipped, written) {
954
985
  written.push(configFile + " (updated)");
955
986
  } else skipped.push(configFile + " (already configured)");
956
987
  } else write("next.config.ts", nextConfigTemplate());
957
- write("app/layout.tsx", rootLayoutTemplate(globalCssRelPath));
988
+ write("app/layout.tsx", rootLayoutTemplate(cfg, globalCssRelPath));
958
989
  const globalCssAbsPath = path.join(cwd, globalCssRelPath);
959
990
  const existingGlobalCss = readFileSafe(globalCssAbsPath);
960
991
  if (existingGlobalCss) {
@@ -964,7 +995,7 @@ function scaffoldNextJs(cwd, cfg, globalCssRelPath, write, skipped, written) {
964
995
  written.push(globalCssRelPath + " (updated)");
965
996
  } else skipped.push(globalCssRelPath + " (already configured)");
966
997
  } else write(globalCssRelPath, globalCssTemplate(cfg.theme));
967
- write(`app/${cfg.entry}/layout.tsx`, docsLayoutTemplate());
998
+ write(`app/${cfg.entry}/layout.tsx`, docsLayoutTemplate(cfg));
968
999
  write("postcss.config.mjs", postcssConfigTemplate());
969
1000
  if (!fileExists(path.join(cwd, "tsconfig.json"))) write("tsconfig.json", tsconfigTemplate());
970
1001
  write(`app/${cfg.entry}/page.mdx`, welcomePageTemplate(cfg));
@@ -975,7 +1006,7 @@ function scaffoldSvelteKit(cwd, cfg, globalCssRelPath, write, skipped, written)
975
1006
  write("src/lib/docs.config.ts", svelteDocsConfigTemplate(cfg));
976
1007
  write("src/lib/docs.server.ts", svelteDocsServerTemplate(cfg));
977
1008
  write(`src/routes/${cfg.entry}/+layout.svelte`, svelteDocsLayoutTemplate(cfg));
978
- write(`src/routes/${cfg.entry}/+layout.server.js`, svelteDocsLayoutServerTemplate());
1009
+ write(`src/routes/${cfg.entry}/+layout.server.js`, svelteDocsLayoutServerTemplate(cfg));
979
1010
  write(`src/routes/${cfg.entry}/[...slug]/+page.svelte`, svelteDocsPageTemplate(cfg));
980
1011
  if (!readFileSafe(path.join(cwd, "src/routes/+layout.svelte"))) write("src/routes/+layout.svelte", svelteRootLayoutTemplate(globalCssRelPath));
981
1012
  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.7",
4
4
  "description": "Modern, flexible MDX-based docs framework — core types, config, and CLI",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",