-
Notifications
You must be signed in to change notification settings - Fork 0
Publish synced llms files as static assets #134
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,64 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { execFile } from "node:child_process"; | ||
| import fs from "node:fs/promises"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
| import test from "node:test"; | ||
| import { promisify } from "node:util"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const execFileAsync = promisify(execFile); | ||
| const __filename = fileURLToPath(import.meta.url); | ||
| const workspaceRoot = path.resolve(path.dirname(__filename), ".."); | ||
|
|
||
| async function withTempDir(callback) { | ||
| const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "sync-docs-test-")); | ||
| try { | ||
| return await callback(tmpDir); | ||
| } finally { | ||
| await fs.rm(tmpDir, { recursive: true, force: true }); | ||
| } | ||
| } | ||
|
|
||
| async function writeFakeUpstream(upstreamRoot) { | ||
| await fs.mkdir(path.join(upstreamRoot, "docs"), { recursive: true }); | ||
| await fs.writeFile( | ||
| path.join(upstreamRoot, "docs", "README.md"), | ||
| "# React on Rails Docs\n", | ||
| "utf8" | ||
| ); | ||
| await fs.writeFile(path.join(upstreamRoot, "llms.txt"), "llms index\n", "utf8"); | ||
| await fs.writeFile(path.join(upstreamRoot, "llms-full.txt"), "oss full\n", "utf8"); | ||
| await fs.writeFile(path.join(upstreamRoot, "llms-full-pro.txt"), "pro full\n", "utf8"); | ||
| } | ||
|
|
||
| test("sync docs stages root llms files for static publishing", async () => { | ||
| await withTempDir(async (tmpDir) => { | ||
| const upstreamRoot = path.join(tmpDir, "react_on_rails"); | ||
| await writeFakeUpstream(upstreamRoot); | ||
|
|
||
| const upstreamContent = path.join(workspaceRoot, "content", "upstream"); | ||
| await fs.rm(upstreamContent, { recursive: true, force: true }); | ||
|
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 deletes |
||
|
|
||
| await execFileAsync(process.execPath, [path.join(workspaceRoot, "scripts", "sync-docs.mjs")], { | ||
| cwd: workspaceRoot, | ||
| env: { | ||
| ...process.env, | ||
| REACT_ON_RAILS_REPO: upstreamRoot, | ||
| }, | ||
| }); | ||
|
|
||
| assert.equal( | ||
| await fs.readFile(path.join(upstreamContent, "static", "llms.txt"), "utf8"), | ||
| "llms index\n" | ||
| ); | ||
| assert.equal( | ||
| await fs.readFile(path.join(upstreamContent, "static", "llms-full.txt"), "utf8"), | ||
| "oss full\n" | ||
| ); | ||
| assert.equal( | ||
| await fs.readFile(path.join(upstreamContent, "static", "llms-full-pro.txt"), "utf8"), | ||
| "pro full\n" | ||
| ); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const syncedStaticFiles = ["llms.txt", "llms-full.txt", "llms-full-pro.txt"]; |
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.
When
content/upstream/staticis missing one of the syncedllms*.txtfiles, this removes the existing Docusaurus static file before the missing-source check skips the copy. A standaloneprepare:docsrun or a partial sync can silently drop a previously generated endpoint from the site build and make/llms-full-pro.txtor the other static paths return 404.