-
Notifications
You must be signed in to change notification settings - Fork 198
CAMEL-23781: Generate an offline documentation bundle (camel-docs-offline.zip) #1666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||||||||||||||||||||
| const fs = require('fs'); | ||||||||||||||||||||||
| const path = require('path'); | ||||||||||||||||||||||
| const { execFileSync } = require('child_process'); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const PUBLIC_DIR = 'public'; | ||||||||||||||||||||||
| const BUNDLE_NAME = 'camel-docs-offline.zip'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Generates an offline documentation bundle: a single .zip archive of all generated Markdown (.md) | ||||||||||||||||||||||
| * files plus /llms.txt, preserving the website directory structure. It lets agents (and humans) | ||||||||||||||||||||||
| * with no or restricted internet access read the Camel docs locally - download, unzip (e.g. into | ||||||||||||||||||||||
| * /tmp) and read the Markdown from there. See CAMEL-23781. | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * Must run after the .md files have been generated (see generate-markdown task). Uses the system | ||||||||||||||||||||||
| * `zip` tool, so no extra dependency is required. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| function generateOfflineBundle() { | ||||||||||||||||||||||
| const bundlePath = path.join(PUBLIC_DIR, BUNDLE_NAME); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (!fs.existsSync(PUBLIC_DIR)) { | ||||||||||||||||||||||
| console.error(`Cannot generate ${BUNDLE_NAME}: '${PUBLIC_DIR}' directory not found`); | ||||||||||||||||||||||
| return; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // remove any stale bundle so it is never zipped into itself | ||||||||||||||||||||||
| if (fs.existsSync(bundlePath)) { | ||||||||||||||||||||||
| fs.unlinkSync(bundlePath); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| // run from public/ so paths stay relative to the site root; include only .md files and llms.txt | ||||||||||||||||||||||
| execFileSync('zip', ['-r', '-q', BUNDLE_NAME, '.', '-i', '*.md', 'llms.txt'], { | ||||||||||||||||||||||
| cwd: PUBLIC_DIR, | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This requires the system Consider adding a pre-check:
Suggested change
|
||||||||||||||||||||||
| stdio: 'inherit' | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const sizeMb = (fs.statSync(bundlePath).size / (1024 * 1024)).toFixed(1); | ||||||||||||||||||||||
| console.log(`Generated /${BUNDLE_NAME} (${sizeMb} MB)`); | ||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||
| console.error(`Failed to generate ${BUNDLE_NAME}:`, error.message); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| module.exports = { | ||||||||||||||||||||||
| generateOfflineBundle | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This runs on every build (wired into
generate-markdown). For a large doc set, zipping thousands of .md files adds processing time even for local dev builds where the bundle isn't needed. Consider gating it behind an environment variable (e.g.CAMEL_ENV=production) or making it a separate gulp task.