docstra 1.5.2-next.1 → 1.5.2-next.2

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.
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1 from 'react';
3
- import { D as DocstraConfig, p as pageDataContent, a as DocstraContextType } from '../types-QIYN3ZUM.mjs';
3
+ import { D as DocstraConfig, p as pageDataContent, a as DocstraContextType } from '../types-BpWZQq13.mjs';
4
4
 
5
5
  declare function DocstraProvider({ children, docstraConfig, pageData }: {
6
6
  children: React$1.ReactNode;
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1 from 'react';
3
- import { D as DocstraConfig, p as pageDataContent, a as DocstraContextType } from '../types-QIYN3ZUM.js';
3
+ import { D as DocstraConfig, p as pageDataContent, a as DocstraContextType } from '../types-BpWZQq13.js';
4
4
 
5
5
  declare function DocstraProvider({ children, docstraConfig, pageData }: {
6
6
  children: React$1.ReactNode;
@@ -1,4 +1,4 @@
1
- import { D as DocstraConfig, b as DocstraMdxCompilerProps } from '../types-QIYN3ZUM.mjs';
1
+ import { D as DocstraConfig, b as DocstraMdxCompilerProps } from '../types-BpWZQq13.mjs';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import { NextConfig } from 'next';
4
4
 
@@ -1,4 +1,4 @@
1
- import { D as DocstraConfig, b as DocstraMdxCompilerProps } from '../types-QIYN3ZUM.js';
1
+ import { D as DocstraConfig, b as DocstraMdxCompilerProps } from '../types-BpWZQq13.js';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import { NextConfig } from 'next';
4
4
 
@@ -1809,10 +1809,8 @@ function DocstraMDXCompiler({ content, components = {} }) {
1809
1809
  var import_fs = __toESM(require("fs"));
1810
1810
  var import_path = __toESM(require("path"));
1811
1811
  var import_gray_matter = __toESM(require("gray-matter"));
1812
- var DEFAULT_CONTENT_DIR = "docs/content";
1813
- function runDocstraBuild() {
1812
+ function runDocstraBuild(contentDir) {
1814
1813
  const root = process.cwd();
1815
- const contentDir = import_path.default.join(root, DEFAULT_CONTENT_DIR);
1816
1814
  const outDir = import_path.default.join(root, ".docstra");
1817
1815
  const outFile = import_path.default.join(outDir, "index.ts");
1818
1816
  if (!import_fs.default.existsSync(contentDir)) return;
@@ -1827,7 +1825,7 @@ function runDocstraBuild() {
1827
1825
  exportEntries.push(`{
1828
1826
  info: {
1829
1827
  path: "${relFromContent}",
1830
- fullPath: "${DEFAULT_CONTENT_DIR}/${relFromContent}",
1828
+ fullPath: "${contentDir}/${relFromContent}",
1831
1829
  slug: "${slug}"
1832
1830
  },
1833
1831
  frontmatter: ${JSON.stringify(frontmatter, null, 2)},
@@ -1860,24 +1858,20 @@ function resolveSlugFromFile(relFromContent) {
1860
1858
  }
1861
1859
 
1862
1860
  // src/server/dev.ts
1863
- var import_node_path2 = __toESM(require("path"));
1864
1861
  var watcherStarted = false;
1865
1862
  var rebuildTimeout = null;
1866
- async function runDocstraDev() {
1863
+ async function runDocstraDev(contentDir) {
1867
1864
  if (watcherStarted) return;
1868
1865
  watcherStarted = true;
1869
- console.log("\u2705 Docstra DEV started");
1870
- await runDocstraBuild();
1866
+ await runDocstraBuild(contentDir);
1871
1867
  const { FSWatcher: FSWatcher2 } = await Promise.resolve().then(() => (init_esm2(), esm_exports));
1872
- const root = process.cwd();
1873
- const docsDir = import_node_path2.default.join(root, "docs/content");
1874
- const configFile = import_node_path2.default.join(root, "docstra.config.ts");
1868
+ const configFile = "docstra.config.ts";
1875
1869
  const watcher = new FSWatcher2({
1876
1870
  ignoreInitial: true,
1877
1871
  persistent: true,
1878
1872
  ignored: ["node_modules", ".next"]
1879
1873
  });
1880
- watcher.add([docsDir, configFile]);
1874
+ watcher.add([contentDir, configFile]);
1881
1875
  watcher.on("ready", () => {
1882
1876
  console.log("\u{1F440} Docstra watching content & config");
1883
1877
  });
@@ -1888,7 +1882,7 @@ async function runDocstraDev() {
1888
1882
  if (rebuildTimeout) clearTimeout(rebuildTimeout);
1889
1883
  rebuildTimeout = setTimeout(async () => {
1890
1884
  console.log(`\u{1F504} Rebuilding \u2192 ${file}`);
1891
- await runDocstraBuild();
1885
+ await runDocstraBuild(contentDir);
1892
1886
  }, 200);
1893
1887
  });
1894
1888
  process.on("exit", () => {
@@ -1898,18 +1892,43 @@ async function runDocstraDev() {
1898
1892
  });
1899
1893
  }
1900
1894
 
1895
+ // src/server/load-config.ts
1896
+ var import_node_path2 = __toESM(require("path"));
1897
+ var import_node_fs = __toESM(require("fs"));
1898
+ var DEFAULT_CONTENT_DIR = "docs/content";
1899
+ function loadDocstraConfig() {
1900
+ const root = process.cwd();
1901
+ const configPath = import_node_path2.default.join(root, "docstra.config.ts");
1902
+ let userConfig = {};
1903
+ if (import_node_fs.default.existsSync(configPath)) {
1904
+ try {
1905
+ const mod = require(configPath);
1906
+ userConfig = mod.default ?? mod;
1907
+ } catch (err) {
1908
+ console.error("\u274C Failed to load docstra.config.ts");
1909
+ console.error(err);
1910
+ }
1911
+ }
1912
+ const contentDir = userConfig.contentDir ?? DEFAULT_CONTENT_DIR;
1913
+ return {
1914
+ root,
1915
+ contentDir
1916
+ };
1917
+ }
1918
+
1901
1919
  // src/server/with-docstra.ts
1902
1920
  var initialized = false;
1903
1921
  function withDocstra(nextConfig = {}) {
1904
1922
  const isDev = process.env.NODE_ENV === "development";
1905
1923
  const isBuild = process.env.NODE_ENV === "production";
1924
+ const contentDir = loadDocstraConfig().contentDir;
1906
1925
  if (!initialized) {
1907
1926
  initialized = true;
1908
1927
  if (isDev) {
1909
- runDocstraDev();
1928
+ runDocstraDev(contentDir);
1910
1929
  }
1911
1930
  if (isBuild) {
1912
- runDocstraBuild();
1931
+ runDocstraBuild(contentDir);
1913
1932
  }
1914
1933
  }
1915
1934
  return {