-
Notifications
You must be signed in to change notification settings - Fork 1
Fetch docs without git submodules #3
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
base: main
Are you sure you want to change the base?
Changes from all commits
4deb2d6
d4ce9c2
53c7d5d
4c2b11c
f543f5e
ee5404e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,11 @@ | ||
| # The Zane Website | ||
|
|
||
| The documentation is shallow-cloned from [`zane-lang/docs`](https://github.com/zane-lang/docs) | ||
| before starting the development server or building the site. To refresh it manually, run: | ||
|
|
||
| ```sh | ||
| npm run sync:docs | ||
| ``` | ||
|
|
||
| Set `ZANE_DOCS_REF` to clone a branch or tag other than `main`. The clone's `.git` | ||
| directory is removed after fetching, and the downloaded documentation is ignored by Git. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { execFile } from 'node:child_process'; | ||
| import { access, mkdtemp, mkdir, rename, rm } from 'node:fs/promises'; | ||
| import { dirname, join } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { promisify } from 'node:util'; | ||
|
|
||
| const execFileAsync = promisify(execFile); | ||
|
|
||
| const repository = 'https://github.com/zane-lang/docs.git'; | ||
| const ref = process.env.ZANE_DOCS_REF || 'main'; | ||
| const root = join(dirname(fileURLToPath(import.meta.url)), '..'); | ||
| const contentDirectory = join(root, 'src/content'); | ||
| const destination = join(contentDirectory, 'docs'); | ||
|
|
||
| if (process.argv.includes('--skip-if-exists')) { | ||
| try { | ||
| await access(destination); | ||
| console.log('Docs already exist, skipping download.'); | ||
| process.exit(0); | ||
| } catch {} | ||
| } | ||
|
|
||
| await mkdir(contentDirectory, { recursive: true }); | ||
| const workDirectory = await mkdtemp(join(contentDirectory, '.docs-')); | ||
| const checkout = join(workDirectory, 'checkout'); | ||
|
|
||
| try { | ||
| await execFileAsync( | ||
| 'git', | ||
| ['clone', '--depth=1', '--branch', ref, '--single-branch', repository, checkout], | ||
| { timeout: 30_000 }, | ||
| ); | ||
|
|
||
| await rm(join(checkout, '.git'), { recursive: true, force: true }); | ||
| await rm(destination, { recursive: true, force: true }); | ||
| await rename(checkout, destination); | ||
|
Comment on lines
+35
to
+36
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. If To make this operation more robust and prevent data loss on failure, you can rename the existing const backup = join(contentDirectory, '.docs-old');
try {
await rename(destination, backup);
} catch {}
try {
await rename(checkout, destination);
} catch (error) {
try {
await rename(backup, destination);
} catch {}
throw error;
} finally {
await rm(backup, { recursive: true, force: true });
} |
||
| console.log(`Cloned zane-lang/docs@${ref} to src/content/docs`); | ||
| } catch (error) { | ||
| const stderr = typeof error?.stderr === 'string' ? error.stderr.trim() : ''; | ||
| throw new Error(stderr || error?.message || 'Failed to clone documentation', { cause: error }); | ||
| } finally { | ||
| await rm(workDirectory, { recursive: true, force: true }); | ||
| } | ||
|
Comment on lines
+41
to
+43
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. If an error occurs during Wrapping the cleanup in a } finally {
try {
await rm(workDirectory, { recursive: true, force: true });
} catch {}
} |
||
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.
Running
npm run buildcurrently forces a redownload of the documentation every time becauseprebuilddoes not use the--skip-if-existsflag. This prevents offline builds and slows down local production testing.Since production environments (like Vercel or CI) always start with a clean workspace where
src/content/docsdoes not exist, they will still fetch the docs automatically even with--skip-if-exists.Consider adding
--skip-if-existstoprebuildto allow offline builds and speed up local builds.