@raystack/chronicle 0.1.3 → 0.3.0

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.js CHANGED
@@ -9044,8 +9044,9 @@ var {
9044
9044
  } = import__.default;
9045
9045
 
9046
9046
  // src/cli/commands/init.ts
9047
- import fs from "fs";
9048
- import path from "path";
9047
+ import { execSync as execSync2 } from "child_process";
9048
+ import fs3 from "fs";
9049
+ import path4 from "path";
9049
9050
 
9050
9051
  // ../../node_modules/.bun/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
9051
9052
  var ANSI_BACKGROUND_OFFSET = 10;
@@ -9582,6 +9583,156 @@ var $stringify = publicApi.stringify;
9582
9583
  var $visit = visit.visit;
9583
9584
  var $visitAsync = visit.visitAsync;
9584
9585
 
9586
+ // src/cli/utils/config.ts
9587
+ import fs from "fs";
9588
+ import path from "path";
9589
+ function resolveConfigPath(contentDir) {
9590
+ const cwdPath = path.join(process.cwd(), "chronicle.yaml");
9591
+ if (fs.existsSync(cwdPath))
9592
+ return cwdPath;
9593
+ const contentPath = path.join(contentDir, "chronicle.yaml");
9594
+ if (fs.existsSync(contentPath))
9595
+ return contentPath;
9596
+ return null;
9597
+ }
9598
+ function loadCLIConfig(contentDir) {
9599
+ const configPath = resolveConfigPath(contentDir);
9600
+ if (!configPath) {
9601
+ console.log(source_default.red(`Error: chronicle.yaml not found in '${process.cwd()}' or '${contentDir}'`));
9602
+ console.log(source_default.gray(`Run 'chronicle init' to create one`));
9603
+ process.exit(1);
9604
+ }
9605
+ const config = $parse(fs.readFileSync(configPath, "utf-8"));
9606
+ return {
9607
+ config,
9608
+ configPath,
9609
+ contentDir
9610
+ };
9611
+ }
9612
+ // src/cli/utils/process.ts
9613
+ function attachLifecycleHandlers(child) {
9614
+ child.on("close", (code) => process.exit(code ?? 0));
9615
+ process.on("SIGINT", () => child.kill("SIGINT"));
9616
+ process.on("SIGTERM", () => child.kill("SIGTERM"));
9617
+ }
9618
+ // src/cli/utils/scaffold.ts
9619
+ import { execSync } from "child_process";
9620
+ import { createRequire as createRequire2 } from "module";
9621
+ import fs2 from "fs";
9622
+ import path3 from "path";
9623
+
9624
+ // src/cli/utils/resolve.ts
9625
+ import path2 from "path";
9626
+ import { fileURLToPath } from "url";
9627
+ var PACKAGE_ROOT = path2.resolve(path2.dirname(fileURLToPath(import.meta.url)), "..", "..");
9628
+
9629
+ // src/cli/utils/scaffold.ts
9630
+ var COPY_FILES = ["src", "source.config.ts", "tsconfig.json"];
9631
+ function copyRecursive(src, dest) {
9632
+ const stat = fs2.statSync(src);
9633
+ if (stat.isDirectory()) {
9634
+ fs2.mkdirSync(dest, { recursive: true });
9635
+ for (const entry of fs2.readdirSync(src)) {
9636
+ copyRecursive(path3.join(src, entry), path3.join(dest, entry));
9637
+ }
9638
+ } else {
9639
+ fs2.copyFileSync(src, dest);
9640
+ }
9641
+ }
9642
+ function ensureRemoved(targetPath) {
9643
+ try {
9644
+ fs2.lstatSync(targetPath);
9645
+ fs2.rmSync(targetPath, { recursive: true, force: true });
9646
+ } catch {}
9647
+ }
9648
+ function detectPackageManager() {
9649
+ if (process.env.npm_config_user_agent) {
9650
+ return process.env.npm_config_user_agent.split("/")[0];
9651
+ }
9652
+ const cwd = process.cwd();
9653
+ if (fs2.existsSync(path3.join(cwd, "bun.lock")) || fs2.existsSync(path3.join(cwd, "bun.lockb")))
9654
+ return "bun";
9655
+ if (fs2.existsSync(path3.join(cwd, "pnpm-lock.yaml")))
9656
+ return "pnpm";
9657
+ if (fs2.existsSync(path3.join(cwd, "yarn.lock")))
9658
+ return "yarn";
9659
+ return "npm";
9660
+ }
9661
+ function generateNextConfig(scaffoldPath) {
9662
+ const config = `import { createMDX } from 'fumadocs-mdx/next'
9663
+
9664
+ const withMDX = createMDX()
9665
+
9666
+ /** @type {import('next').NextConfig} */
9667
+ const nextConfig = {
9668
+ reactStrictMode: true,
9669
+ }
9670
+
9671
+ export default withMDX(nextConfig)
9672
+ `;
9673
+ fs2.writeFileSync(path3.join(scaffoldPath, "next.config.mjs"), config);
9674
+ }
9675
+ function createPackageJson() {
9676
+ return {
9677
+ name: "chronicle-docs",
9678
+ private: true,
9679
+ dependencies: {
9680
+ "@raystack/chronicle": `^${getChronicleVersion()}`
9681
+ },
9682
+ devDependencies: {
9683
+ "@raystack/tools-config": "0.56.0",
9684
+ "openapi-types": "^12.1.3",
9685
+ typescript: "5.9.3",
9686
+ "@types/react": "^19.2.10",
9687
+ "@types/node": "^25.1.0"
9688
+ }
9689
+ };
9690
+ }
9691
+ function ensureDeps() {
9692
+ const cwd = process.cwd();
9693
+ const cwdPkgJson = path3.join(cwd, "package.json");
9694
+ const cwdNodeModules = path3.join(cwd, "node_modules");
9695
+ if (fs2.existsSync(cwdPkgJson) && fs2.existsSync(cwdNodeModules)) {
9696
+ return;
9697
+ }
9698
+ if (!fs2.existsSync(cwdPkgJson)) {
9699
+ fs2.writeFileSync(cwdPkgJson, JSON.stringify(createPackageJson(), null, 2) + `
9700
+ `);
9701
+ }
9702
+ if (!fs2.existsSync(cwdNodeModules)) {
9703
+ const pm = detectPackageManager();
9704
+ console.log(source_default.cyan(`Installing dependencies with ${pm}...`));
9705
+ execSync(`${pm} install`, { cwd, stdio: "inherit" });
9706
+ }
9707
+ }
9708
+ function getChronicleVersion() {
9709
+ const pkgPath = path3.join(PACKAGE_ROOT, "package.json");
9710
+ const pkg = JSON.parse(fs2.readFileSync(pkgPath, "utf-8"));
9711
+ return pkg.version;
9712
+ }
9713
+ function resolveNextCli() {
9714
+ const chronicleRequire = createRequire2(path3.join(PACKAGE_ROOT, "package.json"));
9715
+ return chronicleRequire.resolve("next/dist/bin/next");
9716
+ }
9717
+ function scaffoldDir(contentDir) {
9718
+ const scaffoldPath = path3.join(process.cwd(), ".chronicle");
9719
+ if (!fs2.existsSync(scaffoldPath)) {
9720
+ fs2.mkdirSync(scaffoldPath, { recursive: true });
9721
+ }
9722
+ for (const name of COPY_FILES) {
9723
+ const src = path3.join(PACKAGE_ROOT, name);
9724
+ const dest = path3.join(scaffoldPath, name);
9725
+ ensureRemoved(dest);
9726
+ copyRecursive(src, dest);
9727
+ }
9728
+ generateNextConfig(scaffoldPath);
9729
+ const contentLink = path3.join(scaffoldPath, "content");
9730
+ ensureRemoved(contentLink);
9731
+ fs2.symlinkSync(path3.resolve(contentDir), contentLink);
9732
+ ensureDeps();
9733
+ console.log(source_default.gray(`Scaffold: ${scaffoldPath}`));
9734
+ return scaffoldPath;
9735
+ }
9585
9736
  // src/cli/commands/init.ts
9586
9737
  function createConfig() {
9587
9738
  return {
@@ -9591,6 +9742,28 @@ function createConfig() {
9591
9742
  search: { enabled: true, placeholder: "Search documentation..." }
9592
9743
  };
9593
9744
  }
9745
+ function createPackageJson2(name) {
9746
+ return {
9747
+ name,
9748
+ private: true,
9749
+ type: "module",
9750
+ scripts: {
9751
+ dev: "chronicle dev",
9752
+ build: "chronicle build",
9753
+ start: "chronicle start"
9754
+ },
9755
+ dependencies: {
9756
+ "@raystack/chronicle": `^${getChronicleVersion()}`
9757
+ },
9758
+ devDependencies: {
9759
+ "@raystack/tools-config": "0.56.0",
9760
+ "openapi-types": "^12.1.3",
9761
+ typescript: "5.9.3",
9762
+ "@types/react": "^19.2.10",
9763
+ "@types/node": "^25.1.0"
9764
+ }
9765
+ };
9766
+ }
9594
9767
  var sampleMdx = `---
9595
9768
  title: Welcome
9596
9769
  description: Getting started with your documentation
@@ -9601,79 +9774,128 @@ order: 1
9601
9774
 
9602
9775
  This is your documentation home page.
9603
9776
  `;
9604
- var initCommand = new Command("init").description("Initialize a new Chronicle project").option("-d, --dir <path>", "Content directory", ".").action((options) => {
9605
- const contentDir = path.resolve(options.dir);
9606
- if (!fs.existsSync(contentDir)) {
9607
- fs.mkdirSync(contentDir, { recursive: true });
9777
+ var initCommand = new Command("init").description("Initialize a new Chronicle project").option("-c, --content <path>", "Content directory name", "content").action((options) => {
9778
+ const projectDir = process.cwd();
9779
+ const dirName = path4.basename(projectDir) || "docs";
9780
+ const contentDir = path4.join(projectDir, options.content);
9781
+ if (!fs3.existsSync(contentDir)) {
9782
+ fs3.mkdirSync(contentDir, { recursive: true });
9608
9783
  console.log(source_default.green("✓"), "Created", contentDir);
9609
9784
  }
9610
- const configPath = path.join(contentDir, "chronicle.yaml");
9611
- if (!fs.existsSync(configPath)) {
9612
- fs.writeFileSync(configPath, $stringify(createConfig()));
9785
+ const packageJsonPath = path4.join(projectDir, "package.json");
9786
+ if (!fs3.existsSync(packageJsonPath)) {
9787
+ fs3.writeFileSync(packageJsonPath, JSON.stringify(createPackageJson2(dirName), null, 2) + `
9788
+ `);
9789
+ console.log(source_default.green("✓"), "Created", packageJsonPath);
9790
+ } else {
9791
+ const existing = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
9792
+ const template = createPackageJson2(dirName);
9793
+ let updated = false;
9794
+ if (existing.type !== "module") {
9795
+ existing.type = "module";
9796
+ updated = true;
9797
+ }
9798
+ if (!existing.scripts)
9799
+ existing.scripts = {};
9800
+ for (const [key, value] of Object.entries(template.scripts)) {
9801
+ if (!existing.scripts[key]) {
9802
+ existing.scripts[key] = value;
9803
+ updated = true;
9804
+ }
9805
+ }
9806
+ if (!existing.dependencies)
9807
+ existing.dependencies = {};
9808
+ for (const [key, value] of Object.entries(template.dependencies)) {
9809
+ if (!existing.dependencies[key]) {
9810
+ existing.dependencies[key] = value;
9811
+ updated = true;
9812
+ }
9813
+ }
9814
+ if (!existing.devDependencies)
9815
+ existing.devDependencies = {};
9816
+ for (const [key, value] of Object.entries(template.devDependencies)) {
9817
+ if (!existing.devDependencies[key]) {
9818
+ existing.devDependencies[key] = value;
9819
+ updated = true;
9820
+ }
9821
+ }
9822
+ if (updated) {
9823
+ fs3.writeFileSync(packageJsonPath, JSON.stringify(existing, null, 2) + `
9824
+ `);
9825
+ console.log(source_default.green("✓"), "Updated", packageJsonPath, "with missing scripts/deps");
9826
+ } else {
9827
+ console.log(source_default.yellow("⚠"), packageJsonPath, "already has all required entries");
9828
+ }
9829
+ }
9830
+ const configPath = path4.join(projectDir, "chronicle.yaml");
9831
+ if (!fs3.existsSync(configPath)) {
9832
+ fs3.writeFileSync(configPath, $stringify(createConfig()));
9613
9833
  console.log(source_default.green("✓"), "Created", configPath);
9614
9834
  } else {
9615
9835
  console.log(source_default.yellow("⚠"), configPath, "already exists");
9616
9836
  }
9617
- const indexPath = path.join(contentDir, "index.mdx");
9618
- if (!fs.existsSync(indexPath)) {
9619
- fs.writeFileSync(indexPath, sampleMdx);
9837
+ const contentFiles = fs3.readdirSync(contentDir);
9838
+ if (contentFiles.length === 0) {
9839
+ const indexPath = path4.join(contentDir, "index.mdx");
9840
+ fs3.writeFileSync(indexPath, sampleMdx);
9620
9841
  console.log(source_default.green("✓"), "Created", indexPath);
9621
9842
  }
9843
+ const gitignorePath = path4.join(projectDir, ".gitignore");
9844
+ const gitignoreEntries = [".chronicle", "node_modules", ".next"];
9845
+ if (fs3.existsSync(gitignorePath)) {
9846
+ const existing = fs3.readFileSync(gitignorePath, "utf-8");
9847
+ const missing = gitignoreEntries.filter((e) => !existing.includes(e));
9848
+ if (missing.length > 0) {
9849
+ fs3.appendFileSync(gitignorePath, `
9850
+ ${missing.join(`
9851
+ `)}
9852
+ `);
9853
+ console.log(source_default.green("✓"), "Added", missing.join(", "), "to .gitignore");
9854
+ }
9855
+ } else {
9856
+ fs3.writeFileSync(gitignorePath, `${gitignoreEntries.join(`
9857
+ `)}
9858
+ `);
9859
+ console.log(source_default.green("✓"), "Created .gitignore");
9860
+ }
9861
+ const pm = detectPackageManager();
9862
+ console.log(source_default.cyan(`
9863
+ Installing dependencies with ${pm}...`));
9864
+ execSync2(`${pm} install`, { cwd: projectDir, stdio: "inherit" });
9865
+ loadCLIConfig(contentDir);
9866
+ scaffoldDir(contentDir);
9867
+ const runCmd = pm === "npm" ? "npx" : pm === "bun" ? "bunx" : `${pm} dlx`;
9622
9868
  console.log(source_default.green(`
9623
9869
  ✓ Chronicle initialized!`));
9624
9870
  console.log(`
9625
- Run`, source_default.cyan("chronicle dev"), "to start development server");
9871
+ Run`, source_default.cyan(`${runCmd} chronicle dev`), "to start development server");
9626
9872
  });
9627
9873
 
9628
9874
  // src/cli/commands/dev.ts
9629
9875
  import { spawn } from "child_process";
9630
- import path3 from "path";
9631
- import { fileURLToPath } from "url";
9632
-
9633
- // src/cli/utils/config.ts
9634
- import fs2 from "fs";
9635
- import path2 from "path";
9636
- function resolveContentDir(contentFlag) {
9637
- if (contentFlag)
9638
- return path2.resolve(contentFlag);
9639
- if (process.env.CHRONICLE_CONTENT_DIR)
9640
- return path2.resolve(process.env.CHRONICLE_CONTENT_DIR);
9641
- return process.cwd();
9642
- }
9643
- function loadCLIConfig(contentDir) {
9644
- const configPath = path2.join(contentDir, "chronicle.yaml");
9645
- if (!fs2.existsSync(configPath)) {
9646
- console.log(source_default.red("Error: chronicle.yaml not found in"), contentDir);
9647
- console.log(source_default.gray(`Run 'chronicle init' to create one`));
9876
+ import path5 from "path";
9877
+ import fs4 from "fs";
9878
+ var devCommand = new Command("dev").description("Start development server").option("-p, --port <port>", "Port number", "3000").action((options) => {
9879
+ const scaffoldPath = path5.join(process.cwd(), ".chronicle");
9880
+ if (!fs4.existsSync(scaffoldPath)) {
9881
+ console.log(source_default.red("Error: .chronicle/ not found. Run"), source_default.cyan("chronicle init"), source_default.red("first."));
9882
+ process.exit(1);
9883
+ }
9884
+ let nextCli;
9885
+ try {
9886
+ nextCli = resolveNextCli();
9887
+ } catch {
9888
+ console.log(source_default.red("Error: Next.js CLI not found. Run"), source_default.cyan("chronicle init"), source_default.red("first."));
9648
9889
  process.exit(1);
9649
9890
  }
9650
- const config = $parse(fs2.readFileSync(configPath, "utf-8"));
9651
- return {
9652
- config,
9653
- configPath,
9654
- contentDir
9655
- };
9656
- }
9657
- // src/cli/utils/process.ts
9658
- function attachLifecycleHandlers(child) {
9659
- child.on("close", (code) => process.exit(code ?? 0));
9660
- process.on("SIGINT", () => child.kill("SIGINT"));
9661
- process.on("SIGTERM", () => child.kill("SIGTERM"));
9662
- }
9663
- // src/cli/commands/dev.ts
9664
- var PACKAGE_ROOT = path3.resolve(path3.dirname(fileURLToPath(import.meta.url)), "..", "..");
9665
- var nextBin = path3.join(PACKAGE_ROOT, "node_modules", ".bin", process.platform === "win32" ? "next.cmd" : "next");
9666
- var devCommand = new Command("dev").description("Start development server").option("-p, --port <port>", "Port number", "3000").option("-c, --content <path>", "Content directory").action((options) => {
9667
- const contentDir = resolveContentDir(options.content);
9668
- loadCLIConfig(contentDir);
9669
9891
  console.log(source_default.cyan("Starting dev server..."));
9670
- console.log(source_default.gray(`Content: ${contentDir}`));
9671
- const child = spawn(nextBin, ["dev", "-p", options.port], {
9892
+ const child = spawn(process.execPath, [nextCli, "dev", "-p", options.port], {
9672
9893
  stdio: "inherit",
9673
- cwd: PACKAGE_ROOT,
9894
+ cwd: scaffoldPath,
9674
9895
  env: {
9675
9896
  ...process.env,
9676
- CHRONICLE_CONTENT_DIR: contentDir
9897
+ CHRONICLE_PROJECT_ROOT: process.cwd(),
9898
+ CHRONICLE_CONTENT_DIR: "./content"
9677
9899
  }
9678
9900
  });
9679
9901
  attachLifecycleHandlers(child);
@@ -9681,21 +9903,29 @@ var devCommand = new Command("dev").description("Start development server").opti
9681
9903
 
9682
9904
  // src/cli/commands/build.ts
9683
9905
  import { spawn as spawn2 } from "child_process";
9684
- import path4 from "path";
9685
- import { fileURLToPath as fileURLToPath2 } from "url";
9686
- var PACKAGE_ROOT2 = path4.resolve(path4.dirname(fileURLToPath2(import.meta.url)), "..", "..");
9687
- var nextBin2 = path4.join(PACKAGE_ROOT2, "node_modules", ".bin", process.platform === "win32" ? "next.cmd" : "next");
9688
- var buildCommand = new Command("build").description("Build for production").option("-c, --content <path>", "Content directory").action((options) => {
9689
- const contentDir = resolveContentDir(options.content);
9690
- loadCLIConfig(contentDir);
9906
+ import path6 from "path";
9907
+ import fs5 from "fs";
9908
+ var buildCommand = new Command("build").description("Build for production").action(() => {
9909
+ const scaffoldPath = path6.join(process.cwd(), ".chronicle");
9910
+ if (!fs5.existsSync(scaffoldPath)) {
9911
+ console.log(source_default.red("Error: .chronicle/ not found. Run"), source_default.cyan("chronicle init"), source_default.red("first."));
9912
+ process.exit(1);
9913
+ }
9914
+ let nextCli;
9915
+ try {
9916
+ nextCli = resolveNextCli();
9917
+ } catch {
9918
+ console.log(source_default.red("Error: Next.js CLI not found. Run"), source_default.cyan("chronicle init"), source_default.red("first."));
9919
+ process.exit(1);
9920
+ }
9691
9921
  console.log(source_default.cyan("Building for production..."));
9692
- console.log(source_default.gray(`Content: ${contentDir}`));
9693
- const child = spawn2(nextBin2, ["build"], {
9922
+ const child = spawn2(process.execPath, [nextCli, "build"], {
9694
9923
  stdio: "inherit",
9695
- cwd: PACKAGE_ROOT2,
9924
+ cwd: scaffoldPath,
9696
9925
  env: {
9697
9926
  ...process.env,
9698
- CHRONICLE_CONTENT_DIR: contentDir
9927
+ CHRONICLE_PROJECT_ROOT: process.cwd(),
9928
+ CHRONICLE_CONTENT_DIR: "./content"
9699
9929
  }
9700
9930
  });
9701
9931
  attachLifecycleHandlers(child);
@@ -9703,21 +9933,29 @@ var buildCommand = new Command("build").description("Build for production").opti
9703
9933
 
9704
9934
  // src/cli/commands/start.ts
9705
9935
  import { spawn as spawn3 } from "child_process";
9706
- import path5 from "path";
9707
- import { fileURLToPath as fileURLToPath3 } from "url";
9708
- var PACKAGE_ROOT3 = path5.resolve(path5.dirname(fileURLToPath3(import.meta.url)), "..", "..");
9709
- var nextBin3 = path5.join(PACKAGE_ROOT3, "node_modules", ".bin", process.platform === "win32" ? "next.cmd" : "next");
9710
- var startCommand = new Command("start").description("Start production server").option("-p, --port <port>", "Port number", "3000").option("-c, --content <path>", "Content directory").action((options) => {
9711
- const contentDir = resolveContentDir(options.content);
9712
- loadCLIConfig(contentDir);
9936
+ import path7 from "path";
9937
+ import fs6 from "fs";
9938
+ var startCommand = new Command("start").description("Start production server").option("-p, --port <port>", "Port number", "3000").action((options) => {
9939
+ const scaffoldPath = path7.join(process.cwd(), ".chronicle");
9940
+ if (!fs6.existsSync(scaffoldPath)) {
9941
+ console.log(source_default.red("Error: .chronicle/ not found. Run"), source_default.cyan("chronicle init"), source_default.red("first."));
9942
+ process.exit(1);
9943
+ }
9944
+ let nextCli;
9945
+ try {
9946
+ nextCli = resolveNextCli();
9947
+ } catch {
9948
+ console.log(source_default.red("Error: Next.js CLI not found. Run"), source_default.cyan("chronicle init"), source_default.red("first."));
9949
+ process.exit(1);
9950
+ }
9713
9951
  console.log(source_default.cyan("Starting production server..."));
9714
- console.log(source_default.gray(`Content: ${contentDir}`));
9715
- const child = spawn3(nextBin3, ["start", "-p", options.port], {
9952
+ const child = spawn3(process.execPath, [nextCli, "start", "-p", options.port], {
9716
9953
  stdio: "inherit",
9717
- cwd: PACKAGE_ROOT3,
9954
+ cwd: scaffoldPath,
9718
9955
  env: {
9719
9956
  ...process.env,
9720
- CHRONICLE_CONTENT_DIR: contentDir
9957
+ CHRONICLE_PROJECT_ROOT: process.cwd(),
9958
+ CHRONICLE_CONTENT_DIR: "./content"
9721
9959
  }
9722
9960
  });
9723
9961
  attachLifecycleHandlers(child);
@@ -9725,22 +9963,30 @@ var startCommand = new Command("start").description("Start production server").o
9725
9963
 
9726
9964
  // src/cli/commands/serve.ts
9727
9965
  import { spawn as spawn4 } from "child_process";
9728
- import path6 from "path";
9729
- import { fileURLToPath as fileURLToPath4 } from "url";
9730
- var PACKAGE_ROOT4 = path6.resolve(path6.dirname(fileURLToPath4(import.meta.url)), "..", "..");
9731
- var nextBin4 = path6.join(PACKAGE_ROOT4, "node_modules", ".bin", process.platform === "win32" ? "next.cmd" : "next");
9732
- var serveCommand = new Command("serve").description("Build and start production server").option("-p, --port <port>", "Port number", "3000").option("-c, --content <path>", "Content directory").action((options) => {
9733
- const contentDir = resolveContentDir(options.content);
9734
- loadCLIConfig(contentDir);
9966
+ import path8 from "path";
9967
+ import fs7 from "fs";
9968
+ var serveCommand = new Command("serve").description("Build and start production server").option("-p, --port <port>", "Port number", "3000").action((options) => {
9969
+ const scaffoldPath = path8.join(process.cwd(), ".chronicle");
9970
+ if (!fs7.existsSync(scaffoldPath)) {
9971
+ console.log(source_default.red("Error: .chronicle/ not found. Run"), source_default.cyan("chronicle init"), source_default.red("first."));
9972
+ process.exit(1);
9973
+ }
9974
+ let nextCli;
9975
+ try {
9976
+ nextCli = resolveNextCli();
9977
+ } catch {
9978
+ console.log(source_default.red("Error: Next.js CLI not found. Run"), source_default.cyan("chronicle init"), source_default.red("first."));
9979
+ process.exit(1);
9980
+ }
9735
9981
  const env2 = {
9736
9982
  ...process.env,
9737
- CHRONICLE_CONTENT_DIR: contentDir
9983
+ CHRONICLE_PROJECT_ROOT: process.cwd(),
9984
+ CHRONICLE_CONTENT_DIR: "./content"
9738
9985
  };
9739
9986
  console.log(source_default.cyan("Building for production..."));
9740
- console.log(source_default.gray(`Content: ${contentDir}`));
9741
- const buildChild = spawn4(nextBin4, ["build"], {
9987
+ const buildChild = spawn4(process.execPath, [nextCli, "build"], {
9742
9988
  stdio: "inherit",
9743
- cwd: PACKAGE_ROOT4,
9989
+ cwd: scaffoldPath,
9744
9990
  env: env2
9745
9991
  });
9746
9992
  process.once("SIGINT", () => buildChild.kill("SIGINT"));
@@ -9751,9 +9997,9 @@ var serveCommand = new Command("serve").description("Build and start production
9751
9997
  process.exit(code ?? 1);
9752
9998
  }
9753
9999
  console.log(source_default.cyan("Starting production server..."));
9754
- const startChild = spawn4(nextBin4, ["start", "-p", options.port], {
10000
+ const startChild = spawn4(process.execPath, [nextCli, "start", "-p", options.port], {
9755
10001
  stdio: "inherit",
9756
- cwd: PACKAGE_ROOT4,
10002
+ cwd: scaffoldPath,
9757
10003
  env: env2
9758
10004
  });
9759
10005
  attachLifecycleHandlers(startChild);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raystack/chronicle",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "Config-driven documentation framework",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -10,7 +10,8 @@
10
10
  "src",
11
11
  "templates",
12
12
  "next.config.mjs",
13
- "source.config.ts"
13
+ "source.config.ts",
14
+ "tsconfig.json"
14
15
  ],
15
16
  "bin": {
16
17
  "chronicle": "./bin/chronicle.js"
@@ -27,7 +28,6 @@
27
28
  "@types/react": "^19.2.10",
28
29
  "@types/react-dom": "^19.2.3",
29
30
  "@types/semver": "^7.7.1",
30
- "openapi-types": "^12.1.3",
31
31
  "semver": "^7.7.4",
32
32
  "typescript": "5.9.3"
33
33
  },
@@ -56,6 +56,7 @@
56
56
  "slugify": "^1.6.6",
57
57
  "unified": "^11.0.5",
58
58
  "unist-util-visit": "^5.1.0",
59
+ "openapi-types": "^12.1.3",
59
60
  "yaml": "^2.8.2",
60
61
  "zod": "^4.3.6"
61
62
  }
package/source.config.ts CHANGED
@@ -11,6 +11,7 @@ export const docs = defineDocs({
11
11
  docs: {
12
12
  schema: frontmatterSchema.extend({
13
13
  order: z.number().optional(),
14
+ lastModified: z.string().optional(),
14
15
  }),
15
16
  postprocess: {
16
17
  includeProcessedMarkdown: true,
@@ -1,3 +1,4 @@
1
+ import type { Metadata, ResolvingMetadata } from 'next'
1
2
  import { notFound } from 'next/navigation'
2
3
  import type { MDXContent } from 'mdx/types'
3
4
  import { loadConfig } from '@/lib/config'
@@ -16,6 +17,41 @@ interface PageData {
16
17
  toc: { title: string; url: string; depth: number }[]
17
18
  }
18
19
 
20
+ export async function generateMetadata(
21
+ { params }: PageProps,
22
+ parent: ResolvingMetadata,
23
+ ): Promise<Metadata> {
24
+ const { slug } = await params
25
+ const page = source.getPage(slug)
26
+ if (!page) return {}
27
+ const config = loadConfig()
28
+ const data = page.data as PageData
29
+ const parentMetadata = await parent
30
+
31
+ const metadata: Metadata = {
32
+ title: data.title,
33
+ description: data.description,
34
+ }
35
+
36
+ if (config.url) {
37
+ const ogParams = new URLSearchParams({ title: data.title })
38
+ if (data.description) ogParams.set('description', data.description)
39
+ metadata.openGraph = {
40
+ ...parentMetadata.openGraph,
41
+ title: data.title,
42
+ description: data.description,
43
+ images: [{ url: `/og?${ogParams.toString()}`, width: 1200, height: 630 }],
44
+ }
45
+ metadata.twitter = {
46
+ ...parentMetadata.twitter,
47
+ title: data.title,
48
+ description: data.description,
49
+ }
50
+ }
51
+
52
+ return metadata
53
+ }
54
+
19
55
  export default async function DocsPage({ params }: PageProps) {
20
56
  const { slug } = await params
21
57
  const config = loadConfig()
@@ -33,20 +69,33 @@ export default async function DocsPage({ params }: PageProps) {
33
69
 
34
70
  const tree = buildPageTree()
35
71
 
72
+ const pageUrl = config.url ? `${config.url}/${(slug ?? []).join('/')}` : undefined
73
+
36
74
  return (
37
- <Page
38
- page={{
39
- slug: slug ?? [],
40
- frontmatter: {
41
- title: data.title,
75
+ <>
76
+ <script type="application/ld+json">
77
+ {JSON.stringify({
78
+ '@context': 'https://schema.org',
79
+ '@type': 'Article',
80
+ headline: data.title,
42
81
  description: data.description,
43
- },
44
- content: <MDXBody components={mdxComponents} />,
45
- toc: data.toc ?? [],
46
- }}
47
- config={config}
48
- tree={tree}
49
- />
82
+ ...(pageUrl && { url: pageUrl }),
83
+ }, null, 2)}
84
+ </script>
85
+ <Page
86
+ page={{
87
+ slug: slug ?? [],
88
+ frontmatter: {
89
+ title: data.title,
90
+ description: data.description,
91
+ },
92
+ content: <MDXBody components={mdxComponents} />,
93
+ toc: data.toc ?? [],
94
+ }}
95
+ config={config}
96
+ tree={tree}
97
+ />
98
+ </>
50
99
  )
51
100
  }
52
101