@farming-labs/docs 0.0.2-beta.27 → 0.0.2-beta.29

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.
@@ -363,7 +363,8 @@ const config = {
363
363
  export default config;
364
364
  `;
365
365
  }
366
- function tsconfigTemplate() {
366
+ /** @param useAlias - When false, paths (e.g. @/*) are omitted so no alias is added. */
367
+ function tsconfigTemplate(useAlias = false) {
367
368
  return `\
368
369
  {
369
370
  "compilerOptions": {
@@ -380,8 +381,7 @@ function tsconfigTemplate() {
380
381
  "isolatedModules": true,
381
382
  "jsx": "react-jsx",
382
383
  "incremental": true,
383
- "plugins": [{ "name": "next" }],
384
- "paths": { "@/*": ["./*"] }
384
+ "plugins": [{ "name": "next" }]${useAlias ? ",\n \"paths\": { \"@/*\": [\"./*\"] }" : ""}
385
385
  },
386
386
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
387
387
  "exclude": ["node_modules"]
@@ -1190,11 +1190,12 @@ export default defineDocs({
1190
1190
  `;
1191
1191
  }
1192
1192
  function nuxtDocsServerTemplate(cfg) {
1193
+ const contentDirName = cfg.entry ?? "docs";
1193
1194
  return `\
1194
1195
  import { createDocsServer } from "@farming-labs/nuxt/server";
1195
- import config from "../../docs.config";
1196
+ import config from "${cfg.useAlias ? "~/docs.config" : "../../docs.config"}";
1196
1197
 
1197
- const contentFiles = import.meta.glob("/${cfg.entry ?? "docs"}/**/*.{md,mdx}", {
1198
+ const contentFiles = import.meta.glob("/${contentDirName}/**/*.{md,mdx}", {
1198
1199
  query: "?raw",
1199
1200
  import: "default",
1200
1201
  eager: true,
@@ -1479,9 +1480,43 @@ function injectNuxtCssImport(existingContent, theme) {
1479
1480
 
1480
1481
  //#endregion
1481
1482
  //#region src/cli/init.ts
1482
- async function init() {
1483
+ const EXAMPLES_REPO = "farming-labs/docs";
1484
+ const VALID_TEMPLATES = [
1485
+ "next",
1486
+ "nuxt",
1487
+ "sveltekit",
1488
+ "astro"
1489
+ ];
1490
+ async function init(options = {}) {
1483
1491
  const cwd = process.cwd();
1484
1492
  p.intro(pc.bgCyan(pc.black(" @farming-labs/docs ")));
1493
+ if (options.template) {
1494
+ const template = options.template.toLowerCase();
1495
+ if (!VALID_TEMPLATES.includes(template)) {
1496
+ p.log.error(`Invalid ${pc.cyan("--template")}. Use one of: ${VALID_TEMPLATES.map((t) => pc.cyan(t)).join(", ")}`);
1497
+ process.exit(1);
1498
+ }
1499
+ const templateLabel = template === "next" ? "Next.js" : template === "nuxt" ? "Nuxt" : template === "sveltekit" ? "SvelteKit" : "Astro";
1500
+ p.log.step(`Cloning ${pc.cyan(`examples/${template}`)} from ${pc.cyan(EXAMPLES_REPO)}...`);
1501
+ try {
1502
+ exec(`npx degit ${EXAMPLES_REPO}/examples/${template} . --force`, cwd);
1503
+ } catch (err) {
1504
+ p.log.error("Failed to clone the example. Check your connection and that the repo exists.");
1505
+ process.exit(1);
1506
+ }
1507
+ p.log.success(`Cloned ${templateLabel} example. Installing dependencies...`);
1508
+ const pm = detectPackageManager(cwd);
1509
+ try {
1510
+ if (pm === "pnpm") exec("pnpm install", cwd);
1511
+ else if (pm === "yarn") exec("yarn install", cwd);
1512
+ else if (pm === "bun") exec("bun install", cwd);
1513
+ else exec("npm install", cwd);
1514
+ } catch {
1515
+ p.log.warn("Dependency install failed. Run your package manager install command manually.");
1516
+ }
1517
+ p.outro(pc.green(`Done! Run ${pc.cyan(pm === "yarn" ? "yarn dev" : pm === "bun" ? "bun dev" : `${pm} run dev`)} to start the dev server.`));
1518
+ process.exit(0);
1519
+ }
1485
1520
  let framework = detectFramework(cwd);
1486
1521
  if (framework) {
1487
1522
  const frameworkName = framework === "nextjs" ? "Next.js" : framework === "sveltekit" ? "SvelteKit" : framework === "astro" ? "Astro" : "Nuxt";
@@ -1793,7 +1828,7 @@ function scaffoldNextJs(cwd, cfg, globalCssRelPath, write, skipped, written) {
1793
1828
  } else write(globalCssRelPath, globalCssTemplate(cfg.theme));
1794
1829
  write(`app/${cfg.entry}/layout.tsx`, docsLayoutTemplate(cfg));
1795
1830
  write("postcss.config.mjs", postcssConfigTemplate());
1796
- if (!fileExists(path.join(cwd, "tsconfig.json"))) write("tsconfig.json", tsconfigTemplate());
1831
+ if (!fileExists(path.join(cwd, "tsconfig.json"))) write("tsconfig.json", tsconfigTemplate(cfg.useAlias));
1797
1832
  write(`app/${cfg.entry}/page.mdx`, welcomePageTemplate(cfg));
1798
1833
  write(`app/${cfg.entry}/installation/page.mdx`, installationPageTemplate(cfg));
1799
1834
  write(`app/${cfg.entry}/quickstart/page.mdx`, quickstartPageTemplate(cfg));
@@ -1893,9 +1928,31 @@ function scaffoldNuxt(cwd, cfg, globalCssRelPath, write, skipped, written) {
1893
1928
 
1894
1929
  //#endregion
1895
1930
  //#region src/cli/index.ts
1896
- const command = process.argv.slice(2)[0];
1931
+ const args = process.argv.slice(2);
1932
+ const command = args[0];
1933
+ /** Parse flags like --template next, --theme darksharp, --entry docs */
1934
+ function parseFlags(argv) {
1935
+ const flags = {};
1936
+ for (let i = 0; i < argv.length; i++) {
1937
+ const arg = argv[i];
1938
+ if (arg.startsWith("--") && arg.includes("=")) {
1939
+ const [key, value] = arg.slice(2).split("=");
1940
+ flags[key] = value;
1941
+ } else if (arg.startsWith("--") && argv[i + 1] && !argv[i + 1].startsWith("--")) {
1942
+ flags[arg.slice(2)] = argv[i + 1];
1943
+ i++;
1944
+ }
1945
+ }
1946
+ return flags;
1947
+ }
1897
1948
  async function main() {
1898
- if (!command || command === "init") await init();
1949
+ const flags = parseFlags(args);
1950
+ const initOptions = {
1951
+ template: flags.template,
1952
+ theme: flags.theme,
1953
+ entry: flags.entry
1954
+ };
1955
+ if (!command || command === "init") await init(initOptions);
1899
1956
  else if (command === "--help" || command === "-h") printHelp();
1900
1957
  else if (command === "--version" || command === "-v") printVersion();
1901
1958
  else {
@@ -1918,9 +1975,12 @@ ${pc.dim("Commands:")}
1918
1975
  ${pc.dim("Supported frameworks:")}
1919
1976
  Next.js, SvelteKit, Astro, Nuxt
1920
1977
 
1921
- ${pc.dim("Options:")}
1922
- ${pc.cyan("-h, --help")} Show this help message
1923
- ${pc.cyan("-v, --version")} Show version
1978
+ ${pc.dim("Options for init:")}
1979
+ ${pc.cyan("--template <name>")} Clone an example (${pc.dim("next")}, ${pc.dim("nuxt")}, ${pc.dim("sveltekit")}, ${pc.dim("astro")}) and get started
1980
+ ${pc.cyan("--theme <name>")} Skip theme prompt (e.g. ${pc.dim("darksharp")}, ${pc.dim("greentree")})
1981
+ ${pc.cyan("--entry <path>")} Skip entry path prompt (e.g. ${pc.dim("docs")})
1982
+ ${pc.cyan("-h, --help")} Show this help message
1983
+ ${pc.cyan("-v, --version")} Show version
1924
1984
  `);
1925
1985
  }
1926
1986
  function printVersion() {
package/dist/index.d.mts CHANGED
@@ -431,10 +431,13 @@ interface OpenDocsProvider {
431
431
  /** Icon element rendered next to the name */
432
432
  icon?: unknown;
433
433
  /**
434
- * URL template. `{url}` is replaced with the current page URL.
435
- * `{mdxUrl}` is replaced with the `.mdx` variant of the page URL.
434
+ * URL template. Placeholders:
435
+ * - `{url}` current page URL (encoded).
436
+ * - `{mdxUrl}` — page URL with `.mdx` suffix (encoded).
437
+ * - `{githubUrl}` — GitHub edit URL for the current page (same as "Edit on GitHub"). Requires `github` in config.
436
438
  *
437
439
  * @example "https://claude.ai/new?q=Read+this+doc:+{url}"
440
+ * @example "{githubUrl}" — open current page file on GitHub (edit view)
438
441
  */
439
442
  urlTemplate: string;
440
443
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/docs",
3
- "version": "0.0.2-beta.27",
3
+ "version": "0.0.2-beta.29",
4
4
  "description": "Modern, flexible MDX-based docs framework — core types, config, and CLI",
5
5
  "keywords": [
6
6
  "docs",