@farming-labs/docs 0.0.2-beta.4 → 0.0.2-beta.6
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/dist/cli/index.mjs +97 -44
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -128,14 +128,41 @@ function spawnAndWaitFor(command, args, cwd, waitFor, timeoutMs = 6e4) {
|
|
|
128
128
|
|
|
129
129
|
//#endregion
|
|
130
130
|
//#region src/cli/templates.ts
|
|
131
|
+
const THEME_INFO = {
|
|
132
|
+
fumadocs: {
|
|
133
|
+
factory: "fumadocs",
|
|
134
|
+
nextImport: "@farming-labs/theme",
|
|
135
|
+
svelteImport: "@farming-labs/svelte-theme",
|
|
136
|
+
nextCssImport: "default",
|
|
137
|
+
svelteCssTheme: "fumadocs"
|
|
138
|
+
},
|
|
139
|
+
darksharp: {
|
|
140
|
+
factory: "darksharp",
|
|
141
|
+
nextImport: "@farming-labs/theme/darksharp",
|
|
142
|
+
svelteImport: "@farming-labs/svelte-theme/darksharp",
|
|
143
|
+
nextCssImport: "darksharp",
|
|
144
|
+
svelteCssTheme: "darksharp"
|
|
145
|
+
},
|
|
146
|
+
"pixel-border": {
|
|
147
|
+
factory: "pixelBorder",
|
|
148
|
+
nextImport: "@farming-labs/theme/pixel-border",
|
|
149
|
+
svelteImport: "@farming-labs/svelte-theme/pixel-border",
|
|
150
|
+
nextCssImport: "pixel-border",
|
|
151
|
+
svelteCssTheme: "pixel-border"
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
function getThemeInfo(theme) {
|
|
155
|
+
return THEME_INFO[theme] ?? THEME_INFO.fumadocs;
|
|
156
|
+
}
|
|
131
157
|
function docsConfigTemplate(cfg) {
|
|
158
|
+
const t = getThemeInfo(cfg.theme);
|
|
132
159
|
return `\
|
|
133
160
|
import { defineDocs } from "@farming-labs/docs";
|
|
134
|
-
import {
|
|
161
|
+
import { ${t.factory} } from "${t.nextImport}";
|
|
135
162
|
|
|
136
163
|
export default defineDocs({
|
|
137
164
|
entry: "${cfg.entry}",
|
|
138
|
-
theme:
|
|
165
|
+
theme: ${t.factory}({
|
|
139
166
|
ui: {
|
|
140
167
|
colors: { primary: "#6366f1" },
|
|
141
168
|
},
|
|
@@ -209,7 +236,7 @@ export default function RootLayout({
|
|
|
209
236
|
function globalCssTemplate(theme) {
|
|
210
237
|
return `\
|
|
211
238
|
@import "tailwindcss";
|
|
212
|
-
@import "@farming-labs/${theme}/css";
|
|
239
|
+
@import "@farming-labs/theme/${getThemeInfo(theme).nextCssImport}/css";
|
|
213
240
|
`;
|
|
214
241
|
}
|
|
215
242
|
/**
|
|
@@ -217,8 +244,9 @@ function globalCssTemplate(theme) {
|
|
|
217
244
|
* Returns the modified content, or null if already present.
|
|
218
245
|
*/
|
|
219
246
|
function injectCssImport(existingContent, theme) {
|
|
220
|
-
const importLine = `@import "@farming-labs/${theme}/css";`;
|
|
247
|
+
const importLine = `@import "@farming-labs/theme/${getThemeInfo(theme).nextCssImport}/css";`;
|
|
221
248
|
if (existingContent.includes(importLine)) return null;
|
|
249
|
+
if (existingContent.includes("@farming-labs/theme/") && existingContent.includes("/css")) return null;
|
|
222
250
|
const lines = existingContent.split("\n");
|
|
223
251
|
const lastImportIdx = lines.reduce((acc, l, i) => l.trimStart().startsWith("@import") ? i : acc, -1);
|
|
224
252
|
if (lastImportIdx >= 0) lines.splice(lastImportIdx + 1, 0, importLine);
|
|
@@ -307,6 +335,7 @@ Start by reading the [Installation](/${cfg.entry}/installation) guide, then foll
|
|
|
307
335
|
`;
|
|
308
336
|
}
|
|
309
337
|
function installationPageTemplate(cfg) {
|
|
338
|
+
const t = getThemeInfo(cfg.theme);
|
|
310
339
|
return `\
|
|
311
340
|
---
|
|
312
341
|
title: "Installation"
|
|
@@ -333,11 +362,11 @@ Your project includes a \`docs.config.ts\` at the root:
|
|
|
333
362
|
|
|
334
363
|
\`\`\`ts
|
|
335
364
|
import { defineDocs } from "@farming-labs/docs";
|
|
336
|
-
import {
|
|
365
|
+
import { ${t.factory} } from "${t.nextImport}";
|
|
337
366
|
|
|
338
367
|
export default defineDocs({
|
|
339
368
|
entry: "${cfg.entry}",
|
|
340
|
-
theme:
|
|
369
|
+
theme: ${t.factory}({
|
|
341
370
|
ui: { colors: { primary: "#6366f1" } },
|
|
342
371
|
}),
|
|
343
372
|
});
|
|
@@ -364,6 +393,7 @@ Head to the [Quickstart](/${cfg.entry}/quickstart) guide to start writing your f
|
|
|
364
393
|
`;
|
|
365
394
|
}
|
|
366
395
|
function quickstartPageTemplate(cfg) {
|
|
396
|
+
const t = getThemeInfo(cfg.theme);
|
|
367
397
|
return `\
|
|
368
398
|
---
|
|
369
399
|
title: "Quickstart"
|
|
@@ -426,7 +456,7 @@ console.log(greet("World"));
|
|
|
426
456
|
Edit \`docs.config.ts\` to change colors, typography, and component defaults:
|
|
427
457
|
|
|
428
458
|
\`\`\`ts
|
|
429
|
-
theme:
|
|
459
|
+
theme: ${t.factory}({
|
|
430
460
|
ui: {
|
|
431
461
|
colors: { primary: "#22c55e" },
|
|
432
462
|
},
|
|
@@ -445,14 +475,15 @@ Deploy to Vercel, Netlify, or any Node.js hosting platform.
|
|
|
445
475
|
`;
|
|
446
476
|
}
|
|
447
477
|
function svelteDocsConfigTemplate(cfg) {
|
|
478
|
+
const t = getThemeInfo(cfg.theme);
|
|
448
479
|
return `\
|
|
449
480
|
import { defineDocs } from "@farming-labs/docs";
|
|
450
|
-
import {
|
|
481
|
+
import { ${t.factory} } from "${t.svelteImport}";
|
|
451
482
|
|
|
452
483
|
export default defineDocs({
|
|
453
484
|
entry: "${cfg.entry}",
|
|
454
485
|
contentDir: "${cfg.entry}",
|
|
455
|
-
theme:
|
|
486
|
+
theme: ${t.factory}({
|
|
456
487
|
ui: {
|
|
457
488
|
colors: { primary: "#6366f1" },
|
|
458
489
|
},
|
|
@@ -475,7 +506,7 @@ export default defineDocs({
|
|
|
475
506
|
function svelteDocsServerTemplate(cfg) {
|
|
476
507
|
return `\
|
|
477
508
|
import { createDocsServer } from "@farming-labs/svelte/server";
|
|
478
|
-
import config from "
|
|
509
|
+
import config from "$lib/docs.config.js";
|
|
479
510
|
|
|
480
511
|
export const { load, GET, POST } = createDocsServer(config);
|
|
481
512
|
`;
|
|
@@ -484,7 +515,7 @@ function svelteDocsLayoutTemplate(cfg) {
|
|
|
484
515
|
return `\
|
|
485
516
|
<script>
|
|
486
517
|
import { DocsLayout } from "@farming-labs/svelte-theme";
|
|
487
|
-
import config from "
|
|
518
|
+
import config from "$lib/docs.config.js";
|
|
488
519
|
|
|
489
520
|
let { data, children } = $props();
|
|
490
521
|
<\/script>
|
|
@@ -503,7 +534,7 @@ function svelteDocsPageTemplate(cfg) {
|
|
|
503
534
|
return `\
|
|
504
535
|
<script>
|
|
505
536
|
import { DocsContent } from "@farming-labs/svelte-theme";
|
|
506
|
-
import config from "
|
|
537
|
+
import config from "$lib/docs.config.js";
|
|
507
538
|
|
|
508
539
|
let { data } = $props();
|
|
509
540
|
<\/script>
|
|
@@ -573,6 +604,7 @@ Start by reading the [Installation](/${cfg.entry}/installation) guide, then foll
|
|
|
573
604
|
`;
|
|
574
605
|
}
|
|
575
606
|
function svelteInstallationPageTemplate(cfg) {
|
|
607
|
+
const t = getThemeInfo(cfg.theme);
|
|
576
608
|
return `\
|
|
577
609
|
---
|
|
578
610
|
title: "Installation"
|
|
@@ -596,16 +628,16 @@ pnpm add @farming-labs/docs @farming-labs/svelte @farming-labs/svelte-theme
|
|
|
596
628
|
|
|
597
629
|
## Configuration
|
|
598
630
|
|
|
599
|
-
Your project includes a \`docs.config.ts\`
|
|
631
|
+
Your project includes a \`docs.config.ts\` in \`src/lib/\`:
|
|
600
632
|
|
|
601
|
-
\`\`\`ts title="docs.config.ts"
|
|
633
|
+
\`\`\`ts title="src/lib/docs.config.ts"
|
|
602
634
|
import { defineDocs } from "@farming-labs/docs";
|
|
603
|
-
import {
|
|
635
|
+
import { ${t.factory} } from "${t.svelteImport}";
|
|
604
636
|
|
|
605
637
|
export default defineDocs({
|
|
606
638
|
entry: "${cfg.entry}",
|
|
607
639
|
contentDir: "${cfg.entry}",
|
|
608
|
-
theme:
|
|
640
|
+
theme: ${t.factory}({
|
|
609
641
|
ui: { colors: { primary: "#6366f1" } },
|
|
610
642
|
}),
|
|
611
643
|
});
|
|
@@ -622,6 +654,7 @@ ${cfg.entry}/ # Markdown content
|
|
|
622
654
|
page.md # /${cfg.entry}/quickstart
|
|
623
655
|
src/
|
|
624
656
|
lib/
|
|
657
|
+
docs.config.ts # Docs configuration
|
|
625
658
|
docs.server.ts # Server-side docs loader
|
|
626
659
|
routes/
|
|
627
660
|
${cfg.entry}/
|
|
@@ -629,7 +662,6 @@ src/
|
|
|
629
662
|
+layout.server.js # Layout data loader
|
|
630
663
|
[...slug]/
|
|
631
664
|
+page.svelte # Dynamic doc page
|
|
632
|
-
docs.config.ts # Docs configuration
|
|
633
665
|
\`\`\`
|
|
634
666
|
|
|
635
667
|
## What's Next?
|
|
@@ -638,6 +670,7 @@ Head to the [Quickstart](/${cfg.entry}/quickstart) guide to start writing your f
|
|
|
638
670
|
`;
|
|
639
671
|
}
|
|
640
672
|
function svelteQuickstartPageTemplate(cfg) {
|
|
673
|
+
const t = getThemeInfo(cfg.theme);
|
|
641
674
|
return `\
|
|
642
675
|
---
|
|
643
676
|
title: "Quickstart"
|
|
@@ -685,10 +718,10 @@ console.log(greet("World"));
|
|
|
685
718
|
|
|
686
719
|
## Customizing the Theme
|
|
687
720
|
|
|
688
|
-
Edit \`docs.config.ts\` to change colors, typography, and component defaults:
|
|
721
|
+
Edit \`src/lib/docs.config.ts\` to change colors, typography, and component defaults:
|
|
689
722
|
|
|
690
|
-
\`\`\`ts title="docs.config.ts"
|
|
691
|
-
theme:
|
|
723
|
+
\`\`\`ts title="src/lib/docs.config.ts"
|
|
724
|
+
theme: ${t.factory}({
|
|
692
725
|
ui: {
|
|
693
726
|
colors: { primary: "#22c55e" },
|
|
694
727
|
},
|
|
@@ -712,30 +745,49 @@ Deploy to Vercel, Netlify, or any Node.js hosting platform.
|
|
|
712
745
|
async function init() {
|
|
713
746
|
const cwd = process.cwd();
|
|
714
747
|
p.intro(pc.bgCyan(pc.black(" @farming-labs/docs ")));
|
|
715
|
-
|
|
716
|
-
if (
|
|
717
|
-
|
|
718
|
-
p.
|
|
719
|
-
|
|
748
|
+
let framework = detectFramework(cwd);
|
|
749
|
+
if (framework) {
|
|
750
|
+
const frameworkName = framework === "nextjs" ? "Next.js" : "SvelteKit";
|
|
751
|
+
p.log.success(`Detected framework: ${pc.cyan(frameworkName)}`);
|
|
752
|
+
} else {
|
|
753
|
+
p.log.warn("Could not auto-detect a framework from " + pc.cyan("package.json") + ".");
|
|
754
|
+
const picked = await p.select({
|
|
755
|
+
message: "Which framework are you using?",
|
|
756
|
+
options: [{
|
|
757
|
+
value: "nextjs",
|
|
758
|
+
label: "Next.js",
|
|
759
|
+
hint: "React framework with App Router"
|
|
760
|
+
}, {
|
|
761
|
+
value: "sveltekit",
|
|
762
|
+
label: "SvelteKit",
|
|
763
|
+
hint: "Svelte framework with file-based routing"
|
|
764
|
+
}]
|
|
765
|
+
});
|
|
766
|
+
if (p.isCancel(picked)) {
|
|
767
|
+
p.outro(pc.red("Init cancelled."));
|
|
768
|
+
process.exit(0);
|
|
769
|
+
}
|
|
770
|
+
framework = picked;
|
|
720
771
|
}
|
|
721
|
-
const frameworkName = framework === "nextjs" ? "Next.js" : "SvelteKit";
|
|
722
|
-
p.log.success(`Detected framework: ${pc.cyan(frameworkName)}`);
|
|
723
|
-
const themeOptions = framework === "sveltekit" ? [{
|
|
724
|
-
value: "default",
|
|
725
|
-
label: "Default",
|
|
726
|
-
hint: "Clean, modern docs theme with sidebar, search, and dark mode"
|
|
727
|
-
}, {
|
|
728
|
-
value: "pixel-border",
|
|
729
|
-
label: "Pixel Border",
|
|
730
|
-
hint: "Sharp pixel-art inspired theme with monospace text"
|
|
731
|
-
}] : [{
|
|
732
|
-
value: "fumadocs",
|
|
733
|
-
label: "Fumadocs",
|
|
734
|
-
hint: "Clean, modern docs theme with sidebar, search, and dark mode"
|
|
735
|
-
}];
|
|
736
772
|
const theme = await p.select({
|
|
737
773
|
message: "Which theme would you like to use?",
|
|
738
|
-
options:
|
|
774
|
+
options: [
|
|
775
|
+
{
|
|
776
|
+
value: "fumadocs",
|
|
777
|
+
label: "Fumadocs (Default)",
|
|
778
|
+
hint: "Clean, modern docs theme with sidebar, search, and dark mode"
|
|
779
|
+
},
|
|
780
|
+
{
|
|
781
|
+
value: "darksharp",
|
|
782
|
+
label: "Darksharp",
|
|
783
|
+
hint: "All-black, sharp edges, zero-radius look"
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
value: "pixel-border",
|
|
787
|
+
label: "Pixel Border",
|
|
788
|
+
hint: "Rounded borders, pixel-perfect spacing, refined sidebar"
|
|
789
|
+
}
|
|
790
|
+
]
|
|
739
791
|
});
|
|
740
792
|
if (p.isCancel(theme)) {
|
|
741
793
|
p.outro(pc.red("Init cancelled."));
|
|
@@ -920,7 +972,7 @@ function scaffoldNextJs(cwd, cfg, globalCssRelPath, write, skipped, written) {
|
|
|
920
972
|
write(`app/${cfg.entry}/quickstart/page.mdx`, quickstartPageTemplate(cfg));
|
|
921
973
|
}
|
|
922
974
|
function scaffoldSvelteKit(cwd, cfg, globalCssRelPath, write, skipped, written) {
|
|
923
|
-
write("docs.config.ts", svelteDocsConfigTemplate(cfg));
|
|
975
|
+
write("src/lib/docs.config.ts", svelteDocsConfigTemplate(cfg));
|
|
924
976
|
write("src/lib/docs.server.ts", svelteDocsServerTemplate(cfg));
|
|
925
977
|
write(`src/routes/${cfg.entry}/+layout.svelte`, svelteDocsLayoutTemplate(cfg));
|
|
926
978
|
write(`src/routes/${cfg.entry}/+layout.server.js`, svelteDocsLayoutServerTemplate());
|
|
@@ -929,9 +981,10 @@ function scaffoldSvelteKit(cwd, cfg, globalCssRelPath, write, skipped, written)
|
|
|
929
981
|
const globalCssAbsPath = path.join(cwd, globalCssRelPath);
|
|
930
982
|
const existingGlobalCss = readFileSafe(globalCssAbsPath);
|
|
931
983
|
const cssTheme = {
|
|
932
|
-
|
|
984
|
+
fumadocs: "fumadocs",
|
|
985
|
+
darksharp: "darksharp",
|
|
933
986
|
"pixel-border": "pixel-border",
|
|
934
|
-
|
|
987
|
+
default: "fumadocs"
|
|
935
988
|
}[cfg.theme] || "fumadocs";
|
|
936
989
|
if (existingGlobalCss) {
|
|
937
990
|
const injected = injectSvelteCssImport(existingGlobalCss, cssTheme);
|