diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-09-01 14:48:45 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-09-01 14:48:45 +0300 |
| commit | 8a6d697308162874a236c84aac0b0f8c7ac01f83 (patch) | |
| tree | ed7dc7e8c6f50d66bde721fae78576aede929f66 /website/scripts/docs-preview.mjs | |
| parent | b54a78aa510b87d1e3b56c619b72eaeb59e4a2a1 (diff) | |
refactor: separate website presentation from runtime
Diffstat (limited to 'website/scripts/docs-preview.mjs')
| -rw-r--r-- | website/scripts/docs-preview.mjs | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/website/scripts/docs-preview.mjs b/website/scripts/docs-preview.mjs deleted file mode 100644 index c0de1fcd..00000000 --- a/website/scripts/docs-preview.mjs +++ /dev/null @@ -1,75 +0,0 @@ -import { readFile } from 'node:fs/promises'; -import { dirname, resolve } from 'node:path'; -import { fileURLToPath, pathToFileURL } from 'node:url'; -import { - compareGitTree, - createGit, - extractGitTree, - gitPathExists, - resolveCommit, -} from './docs-snapshot.mjs'; - -const websiteDir = dirname(fileURLToPath(import.meta.url)); -const repoRoot = process.env.HERDR_DOCS_REPO_ROOT - ? resolve(process.env.HERDR_DOCS_REPO_ROOT) - : resolve(websiteDir, '../..'); -const git = createGit(repoRoot); -const sourceRoot = 'docs/next/website'; -const snapshotRoot = resolve(repoRoot, 'docs/preview/website'); -const manifestPath = resolve(repoRoot, 'website/preview.json'); -const fullShaPattern = /^[0-9a-f]{40}$/; - -export async function snapshotPreview(ref) { - const commit = resolveCommit(git, ref); - if (!gitPathExists(git, commit, `${sourceRoot}/src/content/docs`)) { - throw new Error(`${commit} does not contain staged website documentation`); - } - if (!gitPathExists(git, commit, `${sourceRoot}/src/data/config-reference.json`)) { - throw new Error(`${commit} does not contain the staged config reference`); - } - await extractGitTree(git, commit, sourceRoot, snapshotRoot); - process.stdout.write(`snapshotted preview documentation from ${commit}\n`); -} - -export async function checkPreview() { - const manifest = JSON.parse(await readFile(manifestPath, 'utf8')); - if (manifest.schema_version !== 1 || manifest.channel !== 'preview') { - throw new Error(`${manifestPath} has an unsupported schema`); - } - if (typeof manifest.commit !== 'string' || !fullShaPattern.test(manifest.commit)) { - throw new Error(`${manifestPath} must contain a full preview commit SHA`); - } - const build = manifest.builds?.[manifest.build_id]; - if (!build || build.commit !== manifest.commit) { - throw new Error(`${manifestPath} active build does not match its preview commit`); - } - const expectedTag = `preview-${manifest.build_id}`; - if (build.tag !== expectedTag) { - throw new Error(`${manifestPath} active build tag does not match ${expectedTag}`); - } - if (!gitPathExists(git, manifest.commit, `${sourceRoot}/src/content/docs`)) { - throw new Error(`${manifest.commit} does not contain staged website documentation`); - } - if (!gitPathExists(git, manifest.commit, `${sourceRoot}/src/data/config-reference.json`)) { - throw new Error(`${manifest.commit} does not contain the staged config reference`); - } - await compareGitTree(git, manifest.commit, sourceRoot, snapshotRoot); - process.stdout.write(`validated preview documentation snapshot ${manifest.commit}\n`); -} - -async function main() { - const [command, value] = process.argv.slice(2); - if (command === 'snapshot' && value) { - await snapshotPreview(value); - return; - } - if (command === 'check' && !value) { - await checkPreview(); - return; - } - throw new Error('usage: node website/scripts/docs-preview.mjs check | snapshot <commit>'); -} - -if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { - await main(); -} |
