@raystack/chronicle 0.1.0-canary.1f5227c
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/bin/chronicle.js +2 -0
- package/dist/cli/index.js +543 -0
- package/package.json +68 -0
- package/src/cli/__tests__/config.test.ts +25 -0
- package/src/cli/__tests__/scaffold.test.ts +10 -0
- package/src/cli/commands/build.ts +52 -0
- package/src/cli/commands/dev.ts +21 -0
- package/src/cli/commands/init.ts +154 -0
- package/src/cli/commands/serve.ts +55 -0
- package/src/cli/commands/start.ts +24 -0
- package/src/cli/index.ts +21 -0
- package/src/cli/utils/config.ts +43 -0
- package/src/cli/utils/index.ts +2 -0
- package/src/cli/utils/resolve.ts +6 -0
- package/src/cli/utils/scaffold.ts +20 -0
- package/src/components/api/code-snippets.module.css +7 -0
- package/src/components/api/code-snippets.tsx +76 -0
- package/src/components/api/endpoint-page.module.css +58 -0
- package/src/components/api/endpoint-page.tsx +283 -0
- package/src/components/api/field-row.module.css +126 -0
- package/src/components/api/field-row.tsx +204 -0
- package/src/components/api/field-section.module.css +24 -0
- package/src/components/api/field-section.tsx +100 -0
- package/src/components/api/index.ts +8 -0
- package/src/components/api/json-editor.module.css +9 -0
- package/src/components/api/json-editor.tsx +61 -0
- package/src/components/api/key-value-editor.module.css +13 -0
- package/src/components/api/key-value-editor.tsx +62 -0
- package/src/components/api/method-badge.module.css +4 -0
- package/src/components/api/method-badge.tsx +29 -0
- package/src/components/api/response-panel.module.css +8 -0
- package/src/components/api/response-panel.tsx +44 -0
- package/src/components/common/breadcrumb.tsx +3 -0
- package/src/components/common/button.tsx +3 -0
- package/src/components/common/callout.module.css +7 -0
- package/src/components/common/callout.tsx +27 -0
- package/src/components/common/code-block.tsx +3 -0
- package/src/components/common/dialog.tsx +3 -0
- package/src/components/common/index.ts +10 -0
- package/src/components/common/input-field.tsx +3 -0
- package/src/components/common/sidebar.tsx +3 -0
- package/src/components/common/switch.tsx +3 -0
- package/src/components/common/table.tsx +3 -0
- package/src/components/common/tabs.tsx +3 -0
- package/src/components/mdx/code.module.css +42 -0
- package/src/components/mdx/code.tsx +36 -0
- package/src/components/mdx/details.module.css +14 -0
- package/src/components/mdx/details.tsx +17 -0
- package/src/components/mdx/image.tsx +24 -0
- package/src/components/mdx/index.tsx +35 -0
- package/src/components/mdx/link.tsx +37 -0
- package/src/components/mdx/mermaid.module.css +9 -0
- package/src/components/mdx/mermaid.tsx +37 -0
- package/src/components/mdx/paragraph.module.css +8 -0
- package/src/components/mdx/paragraph.tsx +19 -0
- package/src/components/mdx/table.tsx +40 -0
- package/src/components/ui/breadcrumbs.tsx +72 -0
- package/src/components/ui/client-theme-switcher.tsx +18 -0
- package/src/components/ui/footer.module.css +27 -0
- package/src/components/ui/footer.tsx +31 -0
- package/src/components/ui/search.module.css +111 -0
- package/src/components/ui/search.tsx +174 -0
- package/src/lib/api-routes.ts +120 -0
- package/src/lib/config.ts +56 -0
- package/src/lib/head.tsx +45 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/openapi.ts +188 -0
- package/src/lib/page-context.tsx +95 -0
- package/src/lib/remark-unused-directives.ts +30 -0
- package/src/lib/schema.ts +99 -0
- package/src/lib/snippet-generators.ts +87 -0
- package/src/lib/source.ts +138 -0
- package/src/pages/ApiLayout.module.css +22 -0
- package/src/pages/ApiLayout.tsx +29 -0
- package/src/pages/ApiPage.tsx +68 -0
- package/src/pages/DocsLayout.tsx +18 -0
- package/src/pages/DocsPage.tsx +43 -0
- package/src/pages/NotFound.tsx +10 -0
- package/src/pages/__tests__/head.test.tsx +57 -0
- package/src/server/App.tsx +59 -0
- package/src/server/__tests__/entry-server.test.tsx +35 -0
- package/src/server/__tests__/handlers.test.ts +77 -0
- package/src/server/__tests__/og.test.ts +23 -0
- package/src/server/__tests__/router.test.ts +72 -0
- package/src/server/__tests__/vite-config.test.ts +25 -0
- package/src/server/dev.ts +156 -0
- package/src/server/entry-client.tsx +74 -0
- package/src/server/entry-prod.ts +127 -0
- package/src/server/entry-server.tsx +35 -0
- package/src/server/handlers/apis-proxy.ts +52 -0
- package/src/server/handlers/health.ts +3 -0
- package/src/server/handlers/llms.ts +58 -0
- package/src/server/handlers/og.ts +87 -0
- package/src/server/handlers/robots.ts +11 -0
- package/src/server/handlers/search.ts +140 -0
- package/src/server/handlers/sitemap.ts +39 -0
- package/src/server/handlers/specs.ts +9 -0
- package/src/server/index.html +12 -0
- package/src/server/prod.ts +18 -0
- package/src/server/router.ts +42 -0
- package/src/server/vite-config.ts +71 -0
- package/src/themes/default/Layout.module.css +81 -0
- package/src/themes/default/Layout.tsx +132 -0
- package/src/themes/default/Page.module.css +102 -0
- package/src/themes/default/Page.tsx +21 -0
- package/src/themes/default/Toc.module.css +48 -0
- package/src/themes/default/Toc.tsx +66 -0
- package/src/themes/default/font.ts +4 -0
- package/src/themes/default/index.ts +13 -0
- package/src/themes/paper/ChapterNav.module.css +71 -0
- package/src/themes/paper/ChapterNav.tsx +95 -0
- package/src/themes/paper/Layout.module.css +33 -0
- package/src/themes/paper/Layout.tsx +25 -0
- package/src/themes/paper/Page.module.css +174 -0
- package/src/themes/paper/Page.tsx +106 -0
- package/src/themes/paper/ReadingProgress.module.css +132 -0
- package/src/themes/paper/ReadingProgress.tsx +294 -0
- package/src/themes/paper/index.ts +8 -0
- package/src/themes/registry.ts +14 -0
- package/src/types/config.ts +80 -0
- package/src/types/content.ts +36 -0
- package/src/types/index.ts +3 -0
- package/src/types/theme.ts +22 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
import { resolveContentDir } from '@/cli/utils/config'
|
|
5
|
+
import { PACKAGE_ROOT } from '@/cli/utils/resolve'
|
|
6
|
+
|
|
7
|
+
export const buildCommand = new Command('build')
|
|
8
|
+
.description('Build for production')
|
|
9
|
+
.option('-c, --content <path>', 'Content directory')
|
|
10
|
+
.option('-o, --outDir <path>', 'Output directory', 'dist')
|
|
11
|
+
.action(async (options) => {
|
|
12
|
+
const contentDir = resolveContentDir(options.content)
|
|
13
|
+
const outDir = path.resolve(options.outDir)
|
|
14
|
+
|
|
15
|
+
process.env.CHRONICLE_PROJECT_ROOT = process.cwd()
|
|
16
|
+
process.env.CHRONICLE_CONTENT_DIR = contentDir
|
|
17
|
+
|
|
18
|
+
console.log(chalk.cyan('Building for production...'))
|
|
19
|
+
|
|
20
|
+
const { build } = await import('vite')
|
|
21
|
+
const { createViteConfig } = await import('@/server/vite-config')
|
|
22
|
+
|
|
23
|
+
const baseConfig = await createViteConfig({ root: PACKAGE_ROOT, contentDir })
|
|
24
|
+
|
|
25
|
+
// Build client bundle
|
|
26
|
+
console.log(chalk.gray('Building client...'))
|
|
27
|
+
await build({
|
|
28
|
+
...baseConfig,
|
|
29
|
+
build: {
|
|
30
|
+
outDir: path.join(outDir, 'client'),
|
|
31
|
+
ssrManifest: true,
|
|
32
|
+
rolldownOptions: {
|
|
33
|
+
input: path.resolve(PACKAGE_ROOT, 'src/server/index.html'),
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// Build server bundle (noExternal: true to bundle all deps for portability)
|
|
39
|
+
console.log(chalk.gray('Building server...'))
|
|
40
|
+
await build({
|
|
41
|
+
...baseConfig,
|
|
42
|
+
ssr: {
|
|
43
|
+
noExternal: true,
|
|
44
|
+
},
|
|
45
|
+
build: {
|
|
46
|
+
outDir: path.join(outDir, 'server'),
|
|
47
|
+
ssr: path.resolve(PACKAGE_ROOT, 'src/server/entry-prod.ts'),
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
console.log(chalk.green('Build complete →'), outDir)
|
|
52
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
import { resolveContentDir } from '@/cli/utils/config'
|
|
4
|
+
import { PACKAGE_ROOT } from '@/cli/utils/resolve'
|
|
5
|
+
|
|
6
|
+
export const devCommand = new Command('dev')
|
|
7
|
+
.description('Start development server')
|
|
8
|
+
.option('-p, --port <port>', 'Port number', '3000')
|
|
9
|
+
.option('-c, --content <path>', 'Content directory')
|
|
10
|
+
.action(async (options) => {
|
|
11
|
+
const contentDir = resolveContentDir(options.content)
|
|
12
|
+
const port = parseInt(options.port, 10)
|
|
13
|
+
|
|
14
|
+
process.env.CHRONICLE_PROJECT_ROOT = process.cwd()
|
|
15
|
+
process.env.CHRONICLE_CONTENT_DIR = contentDir
|
|
16
|
+
|
|
17
|
+
console.log(chalk.cyan('Starting dev server...'))
|
|
18
|
+
|
|
19
|
+
const { startDevServer } = await import('@/server/dev')
|
|
20
|
+
await startDevServer({ port, root: PACKAGE_ROOT, contentDir })
|
|
21
|
+
})
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { execSync } from 'child_process'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import chalk from 'chalk'
|
|
6
|
+
import { stringify } from 'yaml'
|
|
7
|
+
import type { ChronicleConfig } from '@/types'
|
|
8
|
+
import { detectPackageManager, getChronicleVersion } from '@/cli/utils/scaffold'
|
|
9
|
+
|
|
10
|
+
function createConfig(): ChronicleConfig {
|
|
11
|
+
return {
|
|
12
|
+
title: 'My Documentation',
|
|
13
|
+
description: 'Documentation powered by Chronicle',
|
|
14
|
+
theme: { name: 'default' },
|
|
15
|
+
search: { enabled: true, placeholder: 'Search documentation...' },
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function createPackageJson(name: string): Record<string, unknown> {
|
|
20
|
+
return {
|
|
21
|
+
name,
|
|
22
|
+
private: true,
|
|
23
|
+
type: 'module',
|
|
24
|
+
scripts: {
|
|
25
|
+
dev: 'chronicle dev',
|
|
26
|
+
build: 'chronicle build',
|
|
27
|
+
start: 'chronicle start',
|
|
28
|
+
},
|
|
29
|
+
dependencies: {
|
|
30
|
+
'@raystack/chronicle': `^${getChronicleVersion()}`,
|
|
31
|
+
},
|
|
32
|
+
devDependencies: {
|
|
33
|
+
'@raystack/tools-config': '0.56.0',
|
|
34
|
+
'openapi-types': '^12.1.3',
|
|
35
|
+
typescript: '5.9.3',
|
|
36
|
+
'@types/react': '^19.2.10',
|
|
37
|
+
'@types/node': '^25.1.0',
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const sampleMdx = `---
|
|
43
|
+
title: Welcome
|
|
44
|
+
description: Getting started with your documentation
|
|
45
|
+
order: 1
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
# Welcome
|
|
49
|
+
|
|
50
|
+
This is your documentation home page.
|
|
51
|
+
`
|
|
52
|
+
|
|
53
|
+
export const initCommand = new Command('init')
|
|
54
|
+
.description('Initialize a new Chronicle project')
|
|
55
|
+
.option('-c, --content <path>', 'Content directory name', 'content')
|
|
56
|
+
.action((options) => {
|
|
57
|
+
const projectDir = process.cwd()
|
|
58
|
+
const dirName = path.basename(projectDir) || 'docs'
|
|
59
|
+
const contentDir = path.join(projectDir, options.content)
|
|
60
|
+
|
|
61
|
+
// Create content directory
|
|
62
|
+
if (!fs.existsSync(contentDir)) {
|
|
63
|
+
fs.mkdirSync(contentDir, { recursive: true })
|
|
64
|
+
console.log(chalk.green('\u2713'), 'Created', contentDir)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Create or update package.json
|
|
68
|
+
const packageJsonPath = path.join(projectDir, 'package.json')
|
|
69
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
70
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(createPackageJson(dirName), null, 2) + '\n')
|
|
71
|
+
console.log(chalk.green('\u2713'), 'Created', packageJsonPath)
|
|
72
|
+
} else {
|
|
73
|
+
const existing = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
|
|
74
|
+
const template = createPackageJson(dirName)
|
|
75
|
+
let updated = false
|
|
76
|
+
|
|
77
|
+
if (existing.type !== 'module') {
|
|
78
|
+
existing.type = 'module'
|
|
79
|
+
updated = true
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!existing.scripts) existing.scripts = {}
|
|
83
|
+
for (const [key, value] of Object.entries(template.scripts as Record<string, string>)) {
|
|
84
|
+
if (!existing.scripts[key]) {
|
|
85
|
+
existing.scripts[key] = value
|
|
86
|
+
updated = true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!existing.dependencies) existing.dependencies = {}
|
|
91
|
+
for (const [key, value] of Object.entries(template.dependencies as Record<string, string>)) {
|
|
92
|
+
if (!existing.dependencies[key]) {
|
|
93
|
+
existing.dependencies[key] = value
|
|
94
|
+
updated = true
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!existing.devDependencies) existing.devDependencies = {}
|
|
99
|
+
for (const [key, value] of Object.entries(template.devDependencies as Record<string, string>)) {
|
|
100
|
+
if (!existing.devDependencies[key]) {
|
|
101
|
+
existing.devDependencies[key] = value
|
|
102
|
+
updated = true
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (updated) {
|
|
107
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(existing, null, 2) + '\n')
|
|
108
|
+
console.log(chalk.green('\u2713'), 'Updated', packageJsonPath)
|
|
109
|
+
} else {
|
|
110
|
+
console.log(chalk.yellow('\u26a0'), packageJsonPath, 'already has all required entries')
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Create chronicle.yaml
|
|
115
|
+
const configPath = path.join(projectDir, 'chronicle.yaml')
|
|
116
|
+
if (!fs.existsSync(configPath)) {
|
|
117
|
+
fs.writeFileSync(configPath, stringify(createConfig()))
|
|
118
|
+
console.log(chalk.green('\u2713'), 'Created', configPath)
|
|
119
|
+
} else {
|
|
120
|
+
console.log(chalk.yellow('\u26a0'), configPath, 'already exists')
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Create sample index.mdx
|
|
124
|
+
const contentFiles = fs.readdirSync(contentDir)
|
|
125
|
+
if (contentFiles.length === 0) {
|
|
126
|
+
const indexPath = path.join(contentDir, 'index.mdx')
|
|
127
|
+
fs.writeFileSync(indexPath, sampleMdx)
|
|
128
|
+
console.log(chalk.green('\u2713'), 'Created', indexPath)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Update .gitignore
|
|
132
|
+
const gitignorePath = path.join(projectDir, '.gitignore')
|
|
133
|
+
const gitignoreEntries = ['node_modules', 'dist']
|
|
134
|
+
if (fs.existsSync(gitignorePath)) {
|
|
135
|
+
const existing = fs.readFileSync(gitignorePath, 'utf-8')
|
|
136
|
+
const missing = gitignoreEntries.filter(e => !existing.includes(e))
|
|
137
|
+
if (missing.length > 0) {
|
|
138
|
+
fs.appendFileSync(gitignorePath, `\n${missing.join('\n')}\n`)
|
|
139
|
+
console.log(chalk.green('\u2713'), 'Added', missing.join(', '), 'to .gitignore')
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
fs.writeFileSync(gitignorePath, `${gitignoreEntries.join('\n')}\n`)
|
|
143
|
+
console.log(chalk.green('\u2713'), 'Created .gitignore')
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Install dependencies
|
|
147
|
+
const pm = detectPackageManager()
|
|
148
|
+
console.log(chalk.cyan(`\nInstalling dependencies with ${pm}...`))
|
|
149
|
+
execSync(`${pm} install`, { cwd: projectDir, stdio: 'inherit' })
|
|
150
|
+
|
|
151
|
+
const runCmd = pm === 'npm' ? 'npx' : pm === 'bun' ? 'bunx' : `${pm} dlx`
|
|
152
|
+
console.log(chalk.green('\n\u2713 Chronicle initialized!'))
|
|
153
|
+
console.log('\nRun', chalk.cyan(`${runCmd} chronicle dev`), 'to start development server')
|
|
154
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
import { resolveContentDir } from '@/cli/utils/config'
|
|
5
|
+
import { PACKAGE_ROOT } from '@/cli/utils/resolve'
|
|
6
|
+
|
|
7
|
+
export const serveCommand = new Command('serve')
|
|
8
|
+
.description('Build and start production server')
|
|
9
|
+
.option('-p, --port <port>', 'Port number', '3000')
|
|
10
|
+
.option('-c, --content <path>', 'Content directory')
|
|
11
|
+
.option('-o, --outDir <path>', 'Output directory', 'dist')
|
|
12
|
+
.action(async (options) => {
|
|
13
|
+
const contentDir = resolveContentDir(options.content)
|
|
14
|
+
const port = parseInt(options.port, 10)
|
|
15
|
+
const outDir = path.resolve(options.outDir)
|
|
16
|
+
|
|
17
|
+
process.env.CHRONICLE_PROJECT_ROOT = process.cwd()
|
|
18
|
+
process.env.CHRONICLE_CONTENT_DIR = contentDir
|
|
19
|
+
|
|
20
|
+
// Build
|
|
21
|
+
console.log(chalk.cyan('Building for production...'))
|
|
22
|
+
|
|
23
|
+
const { build } = await import('vite')
|
|
24
|
+
const { createViteConfig } = await import('@/server/vite-config')
|
|
25
|
+
|
|
26
|
+
const baseConfig = await createViteConfig({ root: PACKAGE_ROOT, contentDir })
|
|
27
|
+
|
|
28
|
+
await build({
|
|
29
|
+
...baseConfig,
|
|
30
|
+
build: {
|
|
31
|
+
outDir: path.join(outDir, 'client'),
|
|
32
|
+
ssrManifest: true,
|
|
33
|
+
rolldownOptions: {
|
|
34
|
+
input: path.resolve(PACKAGE_ROOT, 'src/server/index.html'),
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
await build({
|
|
40
|
+
...baseConfig,
|
|
41
|
+
ssr: {
|
|
42
|
+
noExternal: true,
|
|
43
|
+
},
|
|
44
|
+
build: {
|
|
45
|
+
outDir: path.join(outDir, 'server'),
|
|
46
|
+
ssr: path.resolve(PACKAGE_ROOT, 'src/server/entry-prod.ts'),
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
// Start
|
|
51
|
+
console.log(chalk.cyan('Starting production server...'))
|
|
52
|
+
|
|
53
|
+
const { startProdServer } = await import('@/server/prod')
|
|
54
|
+
await startProdServer({ port, root: PACKAGE_ROOT, distDir: outDir })
|
|
55
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
import { resolveContentDir } from '@/cli/utils/config'
|
|
5
|
+
import { PACKAGE_ROOT } from '@/cli/utils/resolve'
|
|
6
|
+
|
|
7
|
+
export const startCommand = new Command('start')
|
|
8
|
+
.description('Start production server')
|
|
9
|
+
.option('-p, --port <port>', 'Port number', '3000')
|
|
10
|
+
.option('-c, --content <path>', 'Content directory')
|
|
11
|
+
.option('-d, --dist <path>', 'Dist directory', 'dist')
|
|
12
|
+
.action(async (options) => {
|
|
13
|
+
const contentDir = resolveContentDir(options.content)
|
|
14
|
+
const port = parseInt(options.port, 10)
|
|
15
|
+
const distDir = path.resolve(options.dist)
|
|
16
|
+
|
|
17
|
+
process.env.CHRONICLE_PROJECT_ROOT = process.cwd()
|
|
18
|
+
process.env.CHRONICLE_CONTENT_DIR = contentDir
|
|
19
|
+
|
|
20
|
+
console.log(chalk.cyan('Starting production server...'))
|
|
21
|
+
|
|
22
|
+
const { startProdServer } = await import('@/server/prod')
|
|
23
|
+
await startProdServer({ port, root: PACKAGE_ROOT, distDir })
|
|
24
|
+
})
|
package/src/cli/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { initCommand } from './commands/init'
|
|
3
|
+
import { devCommand } from './commands/dev'
|
|
4
|
+
import { buildCommand } from './commands/build'
|
|
5
|
+
import { startCommand } from './commands/start'
|
|
6
|
+
import { serveCommand } from './commands/serve'
|
|
7
|
+
|
|
8
|
+
const program = new Command()
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.name('chronicle')
|
|
12
|
+
.description('Config-driven documentation framework')
|
|
13
|
+
.version('0.1.0')
|
|
14
|
+
|
|
15
|
+
program.addCommand(initCommand)
|
|
16
|
+
program.addCommand(devCommand)
|
|
17
|
+
program.addCommand(buildCommand)
|
|
18
|
+
program.addCommand(startCommand)
|
|
19
|
+
program.addCommand(serveCommand)
|
|
20
|
+
|
|
21
|
+
program.parse()
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { parse } from 'yaml'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
import type { ChronicleConfig } from '@/types'
|
|
6
|
+
|
|
7
|
+
export interface CLIConfig {
|
|
8
|
+
config: ChronicleConfig
|
|
9
|
+
configPath: string
|
|
10
|
+
contentDir: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function resolveContentDir(contentFlag?: string): string {
|
|
14
|
+
if (contentFlag) return path.resolve(contentFlag)
|
|
15
|
+
if (process.env.CHRONICLE_CONTENT_DIR) return path.resolve(process.env.CHRONICLE_CONTENT_DIR)
|
|
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
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function loadCLIConfig(contentDir: string): CLIConfig {
|
|
28
|
+
const configPath = resolveConfigPath(contentDir)
|
|
29
|
+
|
|
30
|
+
if (!configPath) {
|
|
31
|
+
console.log(chalk.red(`Error: chronicle.yaml not found in '${process.cwd()}' or '${contentDir}'`))
|
|
32
|
+
console.log(chalk.gray(`Run 'chronicle init' to create one`))
|
|
33
|
+
process.exit(1)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const config = parse(fs.readFileSync(configPath, 'utf-8')) as ChronicleConfig
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
config,
|
|
40
|
+
configPath,
|
|
41
|
+
contentDir,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -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,20 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { PACKAGE_ROOT } from './resolve'
|
|
4
|
+
|
|
5
|
+
export function detectPackageManager(): string {
|
|
6
|
+
if (process.env.npm_config_user_agent) {
|
|
7
|
+
return process.env.npm_config_user_agent.split('/')[0]
|
|
8
|
+
}
|
|
9
|
+
const cwd = process.cwd()
|
|
10
|
+
if (fs.existsSync(path.join(cwd, 'bun.lock')) || fs.existsSync(path.join(cwd, 'bun.lockb'))) return 'bun'
|
|
11
|
+
if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))) return 'pnpm'
|
|
12
|
+
if (fs.existsSync(path.join(cwd, 'yarn.lock'))) return 'yarn'
|
|
13
|
+
return 'npm'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getChronicleVersion(): string {
|
|
17
|
+
const pkgPath = path.join(PACKAGE_ROOT, 'package.json')
|
|
18
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
|
19
|
+
return pkg.version
|
|
20
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { CodeBlock } from "@raystack/apsara";
|
|
5
|
+
import {
|
|
6
|
+
generateCurl,
|
|
7
|
+
generatePython,
|
|
8
|
+
generateGo,
|
|
9
|
+
generateTypeScript,
|
|
10
|
+
} from "@/lib/snippet-generators";
|
|
11
|
+
import styles from "./code-snippets.module.css";
|
|
12
|
+
|
|
13
|
+
interface CodeSnippetsProps {
|
|
14
|
+
method: string;
|
|
15
|
+
url: string;
|
|
16
|
+
headers: Record<string, string>;
|
|
17
|
+
body?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const languages = [
|
|
21
|
+
{ value: "curl", label: "cURL", lang: "curl", generate: generateCurl },
|
|
22
|
+
{
|
|
23
|
+
value: "python",
|
|
24
|
+
label: "Python",
|
|
25
|
+
lang: "python",
|
|
26
|
+
generate: generatePython,
|
|
27
|
+
},
|
|
28
|
+
{ value: "go", label: "Go", lang: "go", generate: generateGo },
|
|
29
|
+
{
|
|
30
|
+
value: "typescript",
|
|
31
|
+
label: "TypeScript",
|
|
32
|
+
lang: "typescript",
|
|
33
|
+
generate: generateTypeScript,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
export function CodeSnippets({
|
|
38
|
+
method,
|
|
39
|
+
url,
|
|
40
|
+
headers,
|
|
41
|
+
body,
|
|
42
|
+
}: CodeSnippetsProps) {
|
|
43
|
+
const opts = { method, url, headers, body };
|
|
44
|
+
const [selected, setSelected] = useState("curl");
|
|
45
|
+
const current = languages.find((l) => l.value === selected) ?? languages[0];
|
|
46
|
+
|
|
47
|
+
const code = useMemo(
|
|
48
|
+
() => current.generate(opts),
|
|
49
|
+
[selected, method, url, headers, body],
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<CodeBlock
|
|
54
|
+
value={selected}
|
|
55
|
+
onValueChange={setSelected}
|
|
56
|
+
className={styles.snippets}
|
|
57
|
+
>
|
|
58
|
+
<CodeBlock.Header>
|
|
59
|
+
<CodeBlock.LanguageSelect>
|
|
60
|
+
<CodeBlock.LanguageSelectTrigger />
|
|
61
|
+
<CodeBlock.LanguageSelectContent>
|
|
62
|
+
{languages.map((l) => (
|
|
63
|
+
<CodeBlock.LanguageSelectItem key={l.value} value={l.value}>
|
|
64
|
+
{l.label}
|
|
65
|
+
</CodeBlock.LanguageSelectItem>
|
|
66
|
+
))}
|
|
67
|
+
</CodeBlock.LanguageSelectContent>
|
|
68
|
+
</CodeBlock.LanguageSelect>
|
|
69
|
+
<CodeBlock.CopyButton />
|
|
70
|
+
</CodeBlock.Header>
|
|
71
|
+
<CodeBlock.Content>
|
|
72
|
+
<CodeBlock.Code language={current.lang}>{code}</CodeBlock.Code>
|
|
73
|
+
</CodeBlock.Content>
|
|
74
|
+
</CodeBlock>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
.layout {
|
|
2
|
+
display: grid;
|
|
3
|
+
grid-template-columns: 1fr 1fr;
|
|
4
|
+
gap: var(--rs-space-9);
|
|
5
|
+
padding: var(--rs-space-7);
|
|
6
|
+
max-width: 1400px;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.left {
|
|
10
|
+
gap: var(--rs-space-7);
|
|
11
|
+
min-width: 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.right {
|
|
15
|
+
gap: var(--rs-space-5);
|
|
16
|
+
min-width: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.title {
|
|
20
|
+
margin: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.description {
|
|
24
|
+
color: var(--rs-color-foreground-base-secondary);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.methodPath {
|
|
28
|
+
gap: var(--rs-space-3);
|
|
29
|
+
padding: var(--rs-space-4) var(--rs-space-5);
|
|
30
|
+
border: 1px solid var(--rs-color-border-base-primary);
|
|
31
|
+
border-radius: 8px;
|
|
32
|
+
background: var(--rs-color-background-base-secondary);
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.path {
|
|
37
|
+
font-family: monospace;
|
|
38
|
+
flex: 1;
|
|
39
|
+
min-width: 0;
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
text-overflow: ellipsis;
|
|
42
|
+
white-space: nowrap;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.tryButton {
|
|
46
|
+
margin-left: auto;
|
|
47
|
+
flex-shrink: 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@media (max-width: 900px) {
|
|
51
|
+
.layout {
|
|
52
|
+
grid-template-columns: 1fr;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.right {
|
|
56
|
+
position: static;
|
|
57
|
+
}
|
|
58
|
+
}
|