@raystack/chronicle 0.1.2 → 0.2.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 +335 -81
- package/package.json +7 -4
- package/source.config.ts +8 -1
- package/src/app/llms-full.txt/route.ts +18 -0
- package/src/app/llms.txt/route.ts +15 -0
- package/src/cli/commands/build.ts +20 -13
- package/src/cli/commands/dev.ts +19 -12
- package/src/cli/commands/init.ts +114 -9
- package/src/cli/commands/serve.ts +21 -14
- package/src/cli/commands/start.ts +19 -12
- package/src/cli/utils/config.ts +12 -4
- package/src/cli/utils/index.ts +1 -0
- package/src/cli/utils/resolve.ts +6 -0
- package/src/cli/utils/scaffold.ts +137 -0
- package/src/components/ui/search.module.css +7 -0
- package/src/components/ui/search.tsx +7 -3
- package/src/lib/config.ts +22 -3
- package/src/lib/get-llm-text.ts +10 -0
- package/src/lib/remark-unused-directives.ts +15 -16
- package/src/lib/source.ts +4 -3
- package/src/types/config.ts +5 -0
- package/tsconfig.json +30 -0
package/src/cli/commands/dev.ts
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
import { Command } from 'commander'
|
|
2
2
|
import { spawn } from 'child_process'
|
|
3
3
|
import path from 'path'
|
|
4
|
+
import fs from 'fs'
|
|
4
5
|
import chalk from 'chalk'
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
declare const PACKAGE_ROOT: string
|
|
8
|
-
|
|
9
|
-
const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next')
|
|
6
|
+
import { attachLifecycleHandlers, resolveNextCli } from '@/cli/utils'
|
|
10
7
|
|
|
11
8
|
export const devCommand = new Command('dev')
|
|
12
9
|
.description('Start development server')
|
|
13
10
|
.option('-p, --port <port>', 'Port number', '3000')
|
|
14
|
-
.option('-c, --content <path>', 'Content directory')
|
|
15
11
|
.action((options) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
12
|
+
const scaffoldPath = path.join(process.cwd(), '.chronicle')
|
|
13
|
+
if (!fs.existsSync(scaffoldPath)) {
|
|
14
|
+
console.log(chalk.red('Error: .chronicle/ not found. Run'), chalk.cyan('chronicle init'), chalk.red('first.'))
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let nextCli: string
|
|
19
|
+
try {
|
|
20
|
+
nextCli = resolveNextCli()
|
|
21
|
+
} catch {
|
|
22
|
+
console.log(chalk.red('Error: Next.js CLI not found. Run'), chalk.cyan('chronicle init'), chalk.red('first.'))
|
|
23
|
+
process.exit(1)
|
|
24
|
+
}
|
|
18
25
|
|
|
19
26
|
console.log(chalk.cyan('Starting dev server...'))
|
|
20
|
-
console.log(chalk.gray(`Content: ${contentDir}`))
|
|
21
27
|
|
|
22
|
-
const child = spawn(
|
|
28
|
+
const child = spawn(process.execPath, [nextCli, 'dev', '-p', options.port], {
|
|
23
29
|
stdio: 'inherit',
|
|
24
|
-
cwd:
|
|
30
|
+
cwd: scaffoldPath,
|
|
25
31
|
env: {
|
|
26
32
|
...process.env,
|
|
27
|
-
|
|
33
|
+
CHRONICLE_PROJECT_ROOT: process.cwd(),
|
|
34
|
+
CHRONICLE_CONTENT_DIR: './content',
|
|
28
35
|
},
|
|
29
36
|
})
|
|
30
37
|
|
package/src/cli/commands/init.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Command } from 'commander'
|
|
2
|
+
import { execSync } from 'child_process'
|
|
2
3
|
import fs from 'fs'
|
|
3
4
|
import path from 'path'
|
|
4
5
|
import chalk from 'chalk'
|
|
5
6
|
import { stringify } from 'yaml'
|
|
6
7
|
import type { ChronicleConfig } from '@/types'
|
|
8
|
+
import { loadCLIConfig, scaffoldDir, detectPackageManager, getChronicleVersion } from '@/cli/utils'
|
|
9
|
+
|
|
7
10
|
|
|
8
11
|
function createConfig(): ChronicleConfig {
|
|
9
12
|
return {
|
|
@@ -14,6 +17,29 @@ function createConfig(): ChronicleConfig {
|
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
|
|
20
|
+
function createPackageJson(name: string): Record<string, unknown> {
|
|
21
|
+
return {
|
|
22
|
+
name,
|
|
23
|
+
private: true,
|
|
24
|
+
type: 'module',
|
|
25
|
+
scripts: {
|
|
26
|
+
dev: 'chronicle dev',
|
|
27
|
+
build: 'chronicle build',
|
|
28
|
+
start: 'chronicle start',
|
|
29
|
+
},
|
|
30
|
+
dependencies: {
|
|
31
|
+
'@raystack/chronicle': `^${getChronicleVersion()}`,
|
|
32
|
+
},
|
|
33
|
+
devDependencies: {
|
|
34
|
+
'@raystack/tools-config': '0.56.0',
|
|
35
|
+
'openapi-types': '^12.1.3',
|
|
36
|
+
typescript: '5.9.3',
|
|
37
|
+
'@types/react': '^19.2.10',
|
|
38
|
+
'@types/node': '^25.1.0',
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
17
43
|
const sampleMdx = `---
|
|
18
44
|
title: Welcome
|
|
19
45
|
description: Getting started with your documentation
|
|
@@ -27,18 +53,71 @@ This is your documentation home page.
|
|
|
27
53
|
|
|
28
54
|
export const initCommand = new Command('init')
|
|
29
55
|
.description('Initialize a new Chronicle project')
|
|
30
|
-
.option('-
|
|
56
|
+
.option('-c, --content <path>', 'Content directory name', 'content')
|
|
31
57
|
.action((options) => {
|
|
32
|
-
const
|
|
58
|
+
const projectDir = process.cwd()
|
|
59
|
+
const dirName = path.basename(projectDir) || 'docs'
|
|
60
|
+
const contentDir = path.join(projectDir, options.content)
|
|
33
61
|
|
|
34
|
-
// Create content directory
|
|
62
|
+
// Create content directory if it doesn't exist
|
|
35
63
|
if (!fs.existsSync(contentDir)) {
|
|
36
64
|
fs.mkdirSync(contentDir, { recursive: true })
|
|
37
65
|
console.log(chalk.green('✓'), 'Created', contentDir)
|
|
38
66
|
}
|
|
39
67
|
|
|
40
|
-
// Create
|
|
41
|
-
const
|
|
68
|
+
// Create or update package.json in project root
|
|
69
|
+
const packageJsonPath = path.join(projectDir, 'package.json')
|
|
70
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
71
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(createPackageJson(dirName), null, 2) + '\n')
|
|
72
|
+
console.log(chalk.green('✓'), 'Created', packageJsonPath)
|
|
73
|
+
} else {
|
|
74
|
+
const existing = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
|
|
75
|
+
const template = createPackageJson(dirName)
|
|
76
|
+
let updated = false
|
|
77
|
+
|
|
78
|
+
// Set type to module
|
|
79
|
+
if (existing.type !== 'module') {
|
|
80
|
+
existing.type = 'module'
|
|
81
|
+
updated = true
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Merge missing scripts
|
|
85
|
+
if (!existing.scripts) existing.scripts = {}
|
|
86
|
+
for (const [key, value] of Object.entries(template.scripts as Record<string, string>)) {
|
|
87
|
+
if (!existing.scripts[key]) {
|
|
88
|
+
existing.scripts[key] = value
|
|
89
|
+
updated = true
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Merge missing dependencies
|
|
94
|
+
if (!existing.dependencies) existing.dependencies = {}
|
|
95
|
+
for (const [key, value] of Object.entries(template.dependencies as Record<string, string>)) {
|
|
96
|
+
if (!existing.dependencies[key]) {
|
|
97
|
+
existing.dependencies[key] = value
|
|
98
|
+
updated = true
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Merge missing devDependencies
|
|
103
|
+
if (!existing.devDependencies) existing.devDependencies = {}
|
|
104
|
+
for (const [key, value] of Object.entries(template.devDependencies as Record<string, string>)) {
|
|
105
|
+
if (!existing.devDependencies[key]) {
|
|
106
|
+
existing.devDependencies[key] = value
|
|
107
|
+
updated = true
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (updated) {
|
|
112
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(existing, null, 2) + '\n')
|
|
113
|
+
console.log(chalk.green('✓'), 'Updated', packageJsonPath, 'with missing scripts/deps')
|
|
114
|
+
} else {
|
|
115
|
+
console.log(chalk.yellow('⚠'), packageJsonPath, 'already has all required entries')
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Create chronicle.yaml in project root
|
|
120
|
+
const configPath = path.join(projectDir, 'chronicle.yaml')
|
|
42
121
|
if (!fs.existsSync(configPath)) {
|
|
43
122
|
fs.writeFileSync(configPath, stringify(createConfig()))
|
|
44
123
|
console.log(chalk.green('✓'), 'Created', configPath)
|
|
@@ -46,13 +125,39 @@ export const initCommand = new Command('init')
|
|
|
46
125
|
console.log(chalk.yellow('⚠'), configPath, 'already exists')
|
|
47
126
|
}
|
|
48
127
|
|
|
49
|
-
// Create sample index.mdx
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
128
|
+
// Create sample index.mdx only if content dir is empty
|
|
129
|
+
const contentFiles = fs.readdirSync(contentDir)
|
|
130
|
+
if (contentFiles.length === 0) {
|
|
131
|
+
const indexPath = path.join(contentDir, 'index.mdx')
|
|
52
132
|
fs.writeFileSync(indexPath, sampleMdx)
|
|
53
133
|
console.log(chalk.green('✓'), 'Created', indexPath)
|
|
54
134
|
}
|
|
55
135
|
|
|
136
|
+
// Add entries to .gitignore
|
|
137
|
+
const gitignorePath = path.join(projectDir, '.gitignore')
|
|
138
|
+
const gitignoreEntries = ['.chronicle', 'node_modules', '.next']
|
|
139
|
+
if (fs.existsSync(gitignorePath)) {
|
|
140
|
+
const existing = fs.readFileSync(gitignorePath, 'utf-8')
|
|
141
|
+
const missing = gitignoreEntries.filter(e => !existing.includes(e))
|
|
142
|
+
if (missing.length > 0) {
|
|
143
|
+
fs.appendFileSync(gitignorePath, `\n${missing.join('\n')}\n`)
|
|
144
|
+
console.log(chalk.green('✓'), 'Added', missing.join(', '), 'to .gitignore')
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
fs.writeFileSync(gitignorePath, `${gitignoreEntries.join('\n')}\n`)
|
|
148
|
+
console.log(chalk.green('✓'), 'Created .gitignore')
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Install dependencies
|
|
152
|
+
const pm = detectPackageManager()
|
|
153
|
+
console.log(chalk.cyan(`\nInstalling dependencies with ${pm}...`))
|
|
154
|
+
execSync(`${pm} install`, { cwd: projectDir, stdio: 'inherit' })
|
|
155
|
+
|
|
156
|
+
// Scaffold .chronicle/ directory
|
|
157
|
+
loadCLIConfig(contentDir)
|
|
158
|
+
scaffoldDir(contentDir)
|
|
159
|
+
|
|
160
|
+
const runCmd = pm === 'npm' ? 'npx' : pm === 'bun' ? 'bunx' : `${pm} dlx`
|
|
56
161
|
console.log(chalk.green('\n✓ Chronicle initialized!'))
|
|
57
|
-
console.log('\nRun', chalk.cyan(
|
|
162
|
+
console.log('\nRun', chalk.cyan(`${runCmd} chronicle dev`), 'to start development server')
|
|
58
163
|
})
|
|
@@ -1,32 +1,39 @@
|
|
|
1
1
|
import { Command } from 'commander'
|
|
2
2
|
import { spawn } from 'child_process'
|
|
3
3
|
import path from 'path'
|
|
4
|
+
import fs from 'fs'
|
|
4
5
|
import chalk from 'chalk'
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
declare const PACKAGE_ROOT: string
|
|
8
|
-
|
|
9
|
-
const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next')
|
|
6
|
+
import { attachLifecycleHandlers, resolveNextCli } from '@/cli/utils'
|
|
10
7
|
|
|
11
8
|
export const serveCommand = new Command('serve')
|
|
12
9
|
.description('Build and start production server')
|
|
13
10
|
.option('-p, --port <port>', 'Port number', '3000')
|
|
14
|
-
.option('-c, --content <path>', 'Content directory')
|
|
15
11
|
.action((options) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
12
|
+
const scaffoldPath = path.join(process.cwd(), '.chronicle')
|
|
13
|
+
if (!fs.existsSync(scaffoldPath)) {
|
|
14
|
+
console.log(chalk.red('Error: .chronicle/ not found. Run'), chalk.cyan('chronicle init'), chalk.red('first.'))
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let nextCli: string
|
|
19
|
+
try {
|
|
20
|
+
nextCli = resolveNextCli()
|
|
21
|
+
} catch {
|
|
22
|
+
console.log(chalk.red('Error: Next.js CLI not found. Run'), chalk.cyan('chronicle init'), chalk.red('first.'))
|
|
23
|
+
process.exit(1)
|
|
24
|
+
}
|
|
18
25
|
|
|
19
26
|
const env = {
|
|
20
27
|
...process.env,
|
|
21
|
-
|
|
28
|
+
CHRONICLE_PROJECT_ROOT: process.cwd(),
|
|
29
|
+
CHRONICLE_CONTENT_DIR: './content',
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
console.log(chalk.cyan('Building for production...'))
|
|
25
|
-
console.log(chalk.gray(`Content: ${contentDir}`))
|
|
26
33
|
|
|
27
|
-
const buildChild = spawn(
|
|
34
|
+
const buildChild = spawn(process.execPath, [nextCli, 'build'], {
|
|
28
35
|
stdio: 'inherit',
|
|
29
|
-
cwd:
|
|
36
|
+
cwd: scaffoldPath,
|
|
30
37
|
env,
|
|
31
38
|
})
|
|
32
39
|
|
|
@@ -41,9 +48,9 @@ export const serveCommand = new Command('serve')
|
|
|
41
48
|
|
|
42
49
|
console.log(chalk.cyan('Starting production server...'))
|
|
43
50
|
|
|
44
|
-
const startChild = spawn(
|
|
51
|
+
const startChild = spawn(process.execPath, [nextCli, 'start', '-p', options.port], {
|
|
45
52
|
stdio: 'inherit',
|
|
46
|
-
cwd:
|
|
53
|
+
cwd: scaffoldPath,
|
|
47
54
|
env,
|
|
48
55
|
})
|
|
49
56
|
|
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
import { Command } from 'commander'
|
|
2
2
|
import { spawn } from 'child_process'
|
|
3
3
|
import path from 'path'
|
|
4
|
+
import fs from 'fs'
|
|
4
5
|
import chalk from 'chalk'
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
declare const PACKAGE_ROOT: string
|
|
8
|
-
|
|
9
|
-
const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next')
|
|
6
|
+
import { attachLifecycleHandlers, resolveNextCli } from '@/cli/utils'
|
|
10
7
|
|
|
11
8
|
export const startCommand = new Command('start')
|
|
12
9
|
.description('Start production server')
|
|
13
10
|
.option('-p, --port <port>', 'Port number', '3000')
|
|
14
|
-
.option('-c, --content <path>', 'Content directory')
|
|
15
11
|
.action((options) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
12
|
+
const scaffoldPath = path.join(process.cwd(), '.chronicle')
|
|
13
|
+
if (!fs.existsSync(scaffoldPath)) {
|
|
14
|
+
console.log(chalk.red('Error: .chronicle/ not found. Run'), chalk.cyan('chronicle init'), chalk.red('first.'))
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let nextCli: string
|
|
19
|
+
try {
|
|
20
|
+
nextCli = resolveNextCli()
|
|
21
|
+
} catch {
|
|
22
|
+
console.log(chalk.red('Error: Next.js CLI not found. Run'), chalk.cyan('chronicle init'), chalk.red('first.'))
|
|
23
|
+
process.exit(1)
|
|
24
|
+
}
|
|
18
25
|
|
|
19
26
|
console.log(chalk.cyan('Starting production server...'))
|
|
20
|
-
console.log(chalk.gray(`Content: ${contentDir}`))
|
|
21
27
|
|
|
22
|
-
const child = spawn(
|
|
28
|
+
const child = spawn(process.execPath, [nextCli, 'start', '-p', options.port], {
|
|
23
29
|
stdio: 'inherit',
|
|
24
|
-
cwd:
|
|
30
|
+
cwd: scaffoldPath,
|
|
25
31
|
env: {
|
|
26
32
|
...process.env,
|
|
27
|
-
|
|
33
|
+
CHRONICLE_PROJECT_ROOT: process.cwd(),
|
|
34
|
+
CHRONICLE_CONTENT_DIR: './content',
|
|
28
35
|
},
|
|
29
36
|
})
|
|
30
37
|
|
package/src/cli/utils/config.ts
CHANGED
|
@@ -13,14 +13,22 @@ export interface CLIConfig {
|
|
|
13
13
|
export function resolveContentDir(contentFlag?: string): string {
|
|
14
14
|
if (contentFlag) return path.resolve(contentFlag)
|
|
15
15
|
if (process.env.CHRONICLE_CONTENT_DIR) return path.resolve(process.env.CHRONICLE_CONTENT_DIR)
|
|
16
|
-
return
|
|
16
|
+
return path.resolve('content')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function resolveConfigPath(contentDir: string): string | null {
|
|
20
|
+
const cwdPath = path.join(process.cwd(), 'chronicle.yaml')
|
|
21
|
+
if (fs.existsSync(cwdPath)) return cwdPath
|
|
22
|
+
const contentPath = path.join(contentDir, 'chronicle.yaml')
|
|
23
|
+
if (fs.existsSync(contentPath)) return contentPath
|
|
24
|
+
return null
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
export function loadCLIConfig(contentDir: string): CLIConfig {
|
|
20
|
-
const configPath =
|
|
28
|
+
const configPath = resolveConfigPath(contentDir)
|
|
21
29
|
|
|
22
|
-
if (!
|
|
23
|
-
console.log(chalk.red(
|
|
30
|
+
if (!configPath) {
|
|
31
|
+
console.log(chalk.red(`Error: chronicle.yaml not found in '${process.cwd()}' or '${contentDir}'`))
|
|
24
32
|
console.log(chalk.gray(`Run 'chronicle init' to create one`))
|
|
25
33
|
process.exit(1)
|
|
26
34
|
}
|
package/src/cli/utils/index.ts
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import { fileURLToPath } from 'url'
|
|
3
|
+
|
|
4
|
+
// After bundling: dist/cli/index.js → ../.. = package root
|
|
5
|
+
// After install: node_modules/@raystack/chronicle/dist/cli/index.js → ../.. = package root
|
|
6
|
+
export const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..')
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { execSync } from 'child_process'
|
|
2
|
+
import { createRequire } from 'module'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import chalk from 'chalk'
|
|
6
|
+
import { PACKAGE_ROOT } from './resolve'
|
|
7
|
+
|
|
8
|
+
const COPY_FILES = ['src', 'source.config.ts', 'tsconfig.json']
|
|
9
|
+
|
|
10
|
+
function copyRecursive(src: string, dest: string) {
|
|
11
|
+
const stat = fs.statSync(src)
|
|
12
|
+
if (stat.isDirectory()) {
|
|
13
|
+
fs.mkdirSync(dest, { recursive: true })
|
|
14
|
+
for (const entry of fs.readdirSync(src)) {
|
|
15
|
+
copyRecursive(path.join(src, entry), path.join(dest, entry))
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
fs.copyFileSync(src, dest)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function ensureRemoved(targetPath: string) {
|
|
23
|
+
try {
|
|
24
|
+
fs.lstatSync(targetPath)
|
|
25
|
+
fs.rmSync(targetPath, { recursive: true, force: true })
|
|
26
|
+
} catch {
|
|
27
|
+
// nothing exists, proceed
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function detectPackageManager(): string {
|
|
32
|
+
if (process.env.npm_config_user_agent) {
|
|
33
|
+
return process.env.npm_config_user_agent.split('/')[0]
|
|
34
|
+
}
|
|
35
|
+
const cwd = process.cwd()
|
|
36
|
+
if (fs.existsSync(path.join(cwd, 'bun.lock')) || fs.existsSync(path.join(cwd, 'bun.lockb'))) return 'bun'
|
|
37
|
+
if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))) return 'pnpm'
|
|
38
|
+
if (fs.existsSync(path.join(cwd, 'yarn.lock'))) return 'yarn'
|
|
39
|
+
return 'npm'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function generateNextConfig(scaffoldPath: string) {
|
|
43
|
+
const config = `import { createMDX } from 'fumadocs-mdx/next'
|
|
44
|
+
|
|
45
|
+
const withMDX = createMDX()
|
|
46
|
+
|
|
47
|
+
/** @type {import('next').NextConfig} */
|
|
48
|
+
const nextConfig = {
|
|
49
|
+
reactStrictMode: true,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default withMDX(nextConfig)
|
|
53
|
+
`
|
|
54
|
+
fs.writeFileSync(path.join(scaffoldPath, 'next.config.mjs'), config)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function createPackageJson(): Record<string, unknown> {
|
|
58
|
+
return {
|
|
59
|
+
name: 'chronicle-docs',
|
|
60
|
+
private: true,
|
|
61
|
+
dependencies: {
|
|
62
|
+
'@raystack/chronicle': `^${getChronicleVersion()}`,
|
|
63
|
+
},
|
|
64
|
+
devDependencies: {
|
|
65
|
+
'@raystack/tools-config': '0.56.0',
|
|
66
|
+
'openapi-types': '^12.1.3',
|
|
67
|
+
typescript: '5.9.3',
|
|
68
|
+
'@types/react': '^19.2.10',
|
|
69
|
+
'@types/node': '^25.1.0',
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function ensureDeps() {
|
|
75
|
+
const cwd = process.cwd()
|
|
76
|
+
const cwdPkgJson = path.join(cwd, 'package.json')
|
|
77
|
+
const cwdNodeModules = path.join(cwd, 'node_modules')
|
|
78
|
+
|
|
79
|
+
if (fs.existsSync(cwdPkgJson) && fs.existsSync(cwdNodeModules)) {
|
|
80
|
+
// Case 1: existing project with deps installed
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Case 2: no package.json — create in cwd and install
|
|
85
|
+
if (!fs.existsSync(cwdPkgJson)) {
|
|
86
|
+
fs.writeFileSync(cwdPkgJson, JSON.stringify(createPackageJson(), null, 2) + '\n')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!fs.existsSync(cwdNodeModules)) {
|
|
90
|
+
const pm = detectPackageManager()
|
|
91
|
+
console.log(chalk.cyan(`Installing dependencies with ${pm}...`))
|
|
92
|
+
execSync(`${pm} install`, { cwd, stdio: 'inherit' })
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function getChronicleVersion(): string {
|
|
97
|
+
const pkgPath = path.join(PACKAGE_ROOT, 'package.json')
|
|
98
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
|
99
|
+
return pkg.version
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function resolveNextCli(): string {
|
|
103
|
+
const chronicleRequire = createRequire(path.join(PACKAGE_ROOT, 'package.json'))
|
|
104
|
+
return chronicleRequire.resolve('next/dist/bin/next')
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function scaffoldDir(contentDir: string): string {
|
|
108
|
+
const scaffoldPath = path.join(process.cwd(), '.chronicle')
|
|
109
|
+
|
|
110
|
+
// Create .chronicle/ if not exists
|
|
111
|
+
if (!fs.existsSync(scaffoldPath)) {
|
|
112
|
+
fs.mkdirSync(scaffoldPath, { recursive: true })
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Copy package files
|
|
116
|
+
for (const name of COPY_FILES) {
|
|
117
|
+
const src = path.join(PACKAGE_ROOT, name)
|
|
118
|
+
const dest = path.join(scaffoldPath, name)
|
|
119
|
+
ensureRemoved(dest)
|
|
120
|
+
copyRecursive(src, dest)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Generate next.config.mjs
|
|
124
|
+
generateNextConfig(scaffoldPath)
|
|
125
|
+
|
|
126
|
+
// Symlink content dir
|
|
127
|
+
const contentLink = path.join(scaffoldPath, 'content')
|
|
128
|
+
ensureRemoved(contentLink)
|
|
129
|
+
fs.symlinkSync(path.resolve(contentDir), contentLink)
|
|
130
|
+
|
|
131
|
+
// Ensure dependencies are available
|
|
132
|
+
ensureDeps()
|
|
133
|
+
|
|
134
|
+
console.log(chalk.gray(`Scaffold: ${scaffoldPath}`))
|
|
135
|
+
|
|
136
|
+
return scaffoldPath
|
|
137
|
+
}
|
|
@@ -102,3 +102,10 @@
|
|
|
102
102
|
.item[data-selected="true"] .icon {
|
|
103
103
|
color: var(--rs-color-foreground-accent-primary-hover);
|
|
104
104
|
}
|
|
105
|
+
|
|
106
|
+
.pageText :global(mark),
|
|
107
|
+
.headingText :global(mark) {
|
|
108
|
+
background: transparent;
|
|
109
|
+
color: var(--rs-color-foreground-accent-primary);
|
|
110
|
+
font-weight: 600;
|
|
111
|
+
}
|
|
@@ -111,7 +111,7 @@ export function Search({ className }: SearchProps) {
|
|
|
111
111
|
<div className={styles.itemContent}>
|
|
112
112
|
{getResultIcon(result)}
|
|
113
113
|
<Text className={styles.pageText}>
|
|
114
|
-
{stripMethod(result.content)}
|
|
114
|
+
<HighlightedText html={stripMethod(result.content)} />
|
|
115
115
|
</Text>
|
|
116
116
|
</div>
|
|
117
117
|
</Command.Item>
|
|
@@ -132,7 +132,7 @@ export function Search({ className }: SearchProps) {
|
|
|
132
132
|
{result.type === "heading" ? (
|
|
133
133
|
<>
|
|
134
134
|
<Text className={styles.headingText}>
|
|
135
|
-
{stripMethod(result.content)}
|
|
135
|
+
<HighlightedText html={stripMethod(result.content)} />
|
|
136
136
|
</Text>
|
|
137
137
|
<Text className={styles.separator}>-</Text>
|
|
138
138
|
<Text className={styles.pageText}>
|
|
@@ -141,7 +141,7 @@ export function Search({ className }: SearchProps) {
|
|
|
141
141
|
</>
|
|
142
142
|
) : (
|
|
143
143
|
<Text className={styles.pageText}>
|
|
144
|
-
{stripMethod(result.content)}
|
|
144
|
+
<HighlightedText html={stripMethod(result.content)} />
|
|
145
145
|
</Text>
|
|
146
146
|
)}
|
|
147
147
|
</div>
|
|
@@ -178,6 +178,10 @@ function stripMethod(content: string): string {
|
|
|
178
178
|
return API_METHODS.has(first) ? content.slice(first.length + 1) : content;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
function HighlightedText({ html, className }: { html: string; className?: string }) {
|
|
182
|
+
return <span className={className} dangerouslySetInnerHTML={{ __html: html }} />;
|
|
183
|
+
}
|
|
184
|
+
|
|
181
185
|
function getResultIcon(result: SortedResult): React.ReactNode {
|
|
182
186
|
if (!result.url.startsWith("/apis/")) {
|
|
183
187
|
return result.type === "page" ? (
|
package/src/lib/config.ts
CHANGED
|
@@ -11,11 +11,29 @@ const defaultConfig: ChronicleConfig = {
|
|
|
11
11
|
search: { enabled: true, placeholder: 'Search...' },
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
function resolveConfigPath(): string | null {
|
|
15
|
+
// Check project root via env var
|
|
16
|
+
const projectRoot = process.env.CHRONICLE_PROJECT_ROOT
|
|
17
|
+
if (projectRoot) {
|
|
18
|
+
const rootPath = path.join(projectRoot, CONFIG_FILE)
|
|
19
|
+
if (fs.existsSync(rootPath)) return rootPath
|
|
20
|
+
}
|
|
21
|
+
// Check cwd
|
|
22
|
+
const cwdPath = path.join(process.cwd(), CONFIG_FILE)
|
|
23
|
+
if (fs.existsSync(cwdPath)) return cwdPath
|
|
24
|
+
// Check content dir
|
|
25
|
+
const contentDir = process.env.CHRONICLE_CONTENT_DIR
|
|
26
|
+
if (contentDir) {
|
|
27
|
+
const contentPath = path.join(contentDir, CONFIG_FILE)
|
|
28
|
+
if (fs.existsSync(contentPath)) return contentPath
|
|
29
|
+
}
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
|
|
14
33
|
export function loadConfig(): ChronicleConfig {
|
|
15
|
-
const
|
|
16
|
-
const configPath = path.join(dir, CONFIG_FILE)
|
|
34
|
+
const configPath = resolveConfigPath()
|
|
17
35
|
|
|
18
|
-
if (!
|
|
36
|
+
if (!configPath) {
|
|
19
37
|
return defaultConfig
|
|
20
38
|
}
|
|
21
39
|
|
|
@@ -32,5 +50,6 @@ export function loadConfig(): ChronicleConfig {
|
|
|
32
50
|
search: { ...defaultConfig.search, ...userConfig.search },
|
|
33
51
|
footer: userConfig.footer,
|
|
34
52
|
api: userConfig.api,
|
|
53
|
+
llms: { enabled: false, ...userConfig.llms },
|
|
35
54
|
}
|
|
36
55
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { source } from '@/lib/source'
|
|
2
|
+
import type { InferPageType } from 'fumadocs-core/source'
|
|
3
|
+
|
|
4
|
+
export async function getLLMText(page: InferPageType<typeof source>) {
|
|
5
|
+
const processed = await page.data.getText('processed')
|
|
6
|
+
|
|
7
|
+
return `# ${page.data.title} (${page.url})
|
|
8
|
+
|
|
9
|
+
${processed}`
|
|
10
|
+
}
|
|
@@ -2,26 +2,25 @@ import { visit } from 'unist-util-visit'
|
|
|
2
2
|
import type { Plugin } from 'unified'
|
|
3
3
|
import type { Node } from 'unist'
|
|
4
4
|
|
|
5
|
-
interface DirectiveNode extends Node {
|
|
6
|
-
name?: string
|
|
7
|
-
attributes?: Record<string, string>
|
|
8
|
-
children?: Node[]
|
|
9
|
-
data?: unknown
|
|
10
|
-
[key: string]: unknown
|
|
11
|
-
}
|
|
12
|
-
|
|
13
5
|
const remarkUnusedDirectives: Plugin = () => {
|
|
14
6
|
return (tree) => {
|
|
15
|
-
visit(tree, ['textDirective'], (node
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
visit(tree, ['textDirective'], (node) => {
|
|
8
|
+
const directive = node as Node & {
|
|
9
|
+
name?: string
|
|
10
|
+
attributes?: Record<string, string>
|
|
11
|
+
children?: Node[]
|
|
12
|
+
value?: string
|
|
13
|
+
[key: string]: unknown
|
|
14
|
+
}
|
|
15
|
+
if (!directive.data) {
|
|
16
|
+
const hasAttributes = directive.attributes && Object.keys(directive.attributes).length > 0
|
|
17
|
+
const hasChildren = directive.children && directive.children.length > 0
|
|
19
18
|
if (!hasAttributes && !hasChildren) {
|
|
20
|
-
const name =
|
|
19
|
+
const name = directive.name
|
|
21
20
|
if (!name) return
|
|
22
|
-
Object.keys(
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
Object.keys(directive).forEach((key) => delete directive[key])
|
|
22
|
+
directive.type = 'text'
|
|
23
|
+
directive.value = `:${name}`
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
})
|
package/src/lib/source.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { docs } from '
|
|
1
|
+
import { docs } from '@/.source/server'
|
|
2
2
|
import { loader } from 'fumadocs-core/source'
|
|
3
3
|
import type { PageTree, PageTreeItem, Frontmatter } from '@/types'
|
|
4
4
|
|
|
@@ -51,11 +51,12 @@ export function buildPageTree(): PageTree {
|
|
|
51
51
|
const folderItems: PageTreeItem[] = []
|
|
52
52
|
folders.forEach((items, folder) => {
|
|
53
53
|
const sorted = sortByOrder(items)
|
|
54
|
-
const indexPage =
|
|
54
|
+
const indexPage = items.find(item => item.url === `/${folder}`)
|
|
55
|
+
const folderOrder = indexPage?.order ?? sorted[0]?.order
|
|
55
56
|
folderItems.push({
|
|
56
57
|
type: 'folder',
|
|
57
58
|
name: folder.charAt(0).toUpperCase() + folder.slice(1),
|
|
58
|
-
order:
|
|
59
|
+
order: folderOrder,
|
|
59
60
|
children: sorted,
|
|
60
61
|
})
|
|
61
62
|
})
|