lildocs 0.1.17 → 0.1.19

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.mjs +66 -5
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -4,7 +4,7 @@ import { createRequire } from "node:module";
4
4
  import { spawn } from "node:child_process";
5
5
  import { command, flag, option, optional, positional, run, string, subcommands } from "cmd-ts";
6
6
  import { existsSync, readFileSync } from "node:fs";
7
- import { access, copyFile, mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
7
+ import { access, appendFile, copyFile, mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
8
8
  import path from "node:path";
9
9
  import matter from "gray-matter";
10
10
  import { Lexer, Marked, Parser, Renderer, marked } from "marked";
@@ -516,7 +516,10 @@ async function frontendViteConfig(cwd, mode) {
516
516
  clearScreen: false,
517
517
  logLevel: "warn",
518
518
  plugins: [octaneRuntimeCompatibility(), octane()],
519
- optimizeDeps: { exclude: ["octane"] },
519
+ optimizeDeps: {
520
+ exclude: ["octane"],
521
+ ...mode === "dev" ? { noDiscovery: true } : {}
522
+ },
520
523
  ssr: { noExternal: [/^octane(?:$|\/)/] }
521
524
  };
522
525
  }
@@ -1062,12 +1065,14 @@ async function buildReferencePages(options) {
1062
1065
  outDir: tempDir
1063
1066
  });
1064
1067
  const markdownPaths = await collectMarkdownPaths(tempDir);
1068
+ const packageName = packageJsonData.name;
1069
+ if (typeof packageName !== "string" || !packageName) throw new Error(`Package name not found: ${packageJson.packagePath}`);
1065
1070
  return Promise.all(markdownPaths.map(async (sourcePath) => {
1066
- const generatedPath = toPosixPath(path.relative(tempDir, sourcePath));
1071
+ const rawMarkdown = await readFile(sourcePath, "utf8");
1067
1072
  return {
1068
1073
  sourcePath,
1069
- relativePath: toPosixPath(path.posix.join("reference", generatedPath)),
1070
- rawMarkdown: await readFile(sourcePath, "utf8")
1074
+ relativePath: referenceMarkdownPath(rawMarkdown, packageName),
1075
+ rawMarkdown
1071
1076
  };
1072
1077
  }));
1073
1078
  } catch (error) {
@@ -1103,6 +1108,11 @@ async function readPackageJson(packagePath) {
1103
1108
  throw error;
1104
1109
  }
1105
1110
  }
1111
+ function referenceMarkdownPath(rawMarkdown, packageName) {
1112
+ const packageSpecifier = rawMarkdown.match(/^#\s+(.+)$/m)?.[1]?.trim();
1113
+ if (!packageSpecifier || packageSpecifier !== packageName && !packageSpecifier.startsWith(`${packageName}/`) || packageSpecifier.split("/").some((part) => !part || part === "." || part === "..")) throw new Error(`Invalid package entry heading: ${packageSpecifier ?? "missing"}`);
1114
+ return toPosixPath(path.posix.join("reference", `${packageSpecifier}.md`));
1115
+ }
1106
1116
  function errorMessage(error) {
1107
1117
  if (error instanceof Error) return error.message;
1108
1118
  return String(error);
@@ -1847,6 +1857,7 @@ async function startDevServer(options) {
1847
1857
  const input = await resolveInput(options.input, options.cwd, { homePagePreference: "readme-first" });
1848
1858
  const outDir = path.resolve(options.cwd, options.outDir);
1849
1859
  validateDevOutDir(options.cwd, input.docsRoot, outDir, options.outDir);
1860
+ await addGitExclude(options.cwd, outDir);
1850
1861
  await mkdir(outDir, { recursive: true });
1851
1862
  const vite = await createFrontendDevServer({
1852
1863
  cwd: options.cwd,
@@ -1941,6 +1952,56 @@ function isInside(parent, child) {
1941
1952
  const relative = path.relative(parent, child);
1942
1953
  return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
1943
1954
  }
1955
+ async function addGitExclude(cwd, outDir) {
1956
+ try {
1957
+ const repository = await findGitRepository(cwd);
1958
+ if (!repository || !isInside(repository.root, outDir)) return;
1959
+ const relativeOutDir = path.relative(repository.root, outDir);
1960
+ if (!relativeOutDir) return;
1961
+ const pattern = `${relativeOutDir.split(path.sep).join("/")}/`;
1962
+ let contents = "";
1963
+ try {
1964
+ contents = await readFile(repository.excludePath, "utf8");
1965
+ } catch (error) {
1966
+ if (error.code !== "ENOENT") throw error;
1967
+ await mkdir(path.dirname(repository.excludePath), { recursive: true });
1968
+ }
1969
+ const entries = contents.split(/\r?\n/).map((entry) => entry.trim());
1970
+ const normalizedPattern = pattern.replace(/^\/|\/$/g, "");
1971
+ if (entries.some((entry) => entry.replace(/^\/|\/$/g, "") === normalizedPattern)) return;
1972
+ const separator = contents.length > 0 && !contents.endsWith("\n") ? "\n" : "";
1973
+ await appendFile(repository.excludePath, `${separator}${pattern}\n`);
1974
+ } catch {}
1975
+ }
1976
+ async function findGitRepository(start) {
1977
+ let current = path.resolve(start);
1978
+ while (true) {
1979
+ const dotGit = path.join(current, ".git");
1980
+ try {
1981
+ const metadata = await stat(dotGit);
1982
+ let gitDir = dotGit;
1983
+ if (!metadata.isDirectory()) {
1984
+ const pointer = await readFile(dotGit, "utf8");
1985
+ const match = /^gitdir:\s*(.+)\s*$/im.exec(pointer);
1986
+ if (!match?.[1]) return;
1987
+ gitDir = path.resolve(current, match[1]);
1988
+ }
1989
+ let commonDir = gitDir;
1990
+ try {
1991
+ const pointer = (await readFile(path.join(gitDir, "commondir"), "utf8")).trim();
1992
+ commonDir = path.resolve(gitDir, pointer);
1993
+ } catch {}
1994
+ return {
1995
+ root: current,
1996
+ excludePath: path.join(commonDir, "info", "exclude")
1997
+ };
1998
+ } catch {
1999
+ const parent = path.dirname(current);
2000
+ if (parent === current) return;
2001
+ current = parent;
2002
+ }
2003
+ }
2004
+ }
1944
2005
  //#endregion
1945
2006
  //#region src/core/deploy.ts
1946
2007
  async function deployGitHubPages(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lildocs",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "A lightweight CLI that turns Markdown docs into a static searchable documentation site.",
5
5
  "homepage": "https://aleclarson.github.io/lildocs/",
6
6
  "repository": {