diff --git a/.gitignore b/.gitignore index 49ceb21..ef02775 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,7 @@ pnpm-debug.log* # macOS-specific files .DS_Store .vercel + +# downloaded documentation +src/content/docs/ +src/content/.docs-*/ diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 5575b6a..0000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "src/content/docs"] - path = src/content/docs - url = https://github.com/zane-lang/docs - branch = main diff --git a/README.md b/README.md index 36e84f3..eb34683 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/justfile b/justfile index d9fd74d..67441d9 100644 --- a/justfile +++ b/justfile @@ -1,5 +1,5 @@ -submodules: - git submodule update --remote --recursive --force +docs: + npm run sync:docs dev: npm run dev @@ -8,7 +8,7 @@ ship: #!/usr/bin/env bash read -p "Are you sure you want to deploy to production? [y/N] " confirm if [[ "$confirm" =~ ^[Yy]$ ]]; then - just submodules && vercel --prod + vercel --prod else echo "Deployment cancelled." fi diff --git a/package.json b/package.json index a777fd3..590eeca 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,12 @@ "type": "module", "version": "0.0.1", "scripts": { + "sync:docs": "node scripts/fetch-docs.mjs", + "predev": "node scripts/fetch-docs.mjs --skip-if-exists", "dev": "astro dev", + "prestart": "node scripts/fetch-docs.mjs --skip-if-exists", "start": "astro dev", + "prebuild": "node scripts/fetch-docs.mjs", "build": "astro build", "preview": "astro preview", "astro": "astro" diff --git a/scripts/fetch-docs.mjs b/scripts/fetch-docs.mjs new file mode 100644 index 0000000..b3ef866 --- /dev/null +++ b/scripts/fetch-docs.mjs @@ -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); + 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 }); +} diff --git a/src/content/docs b/src/content/docs deleted file mode 160000 index 3074f50..0000000 --- a/src/content/docs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3074f5023e45b3db411bb0fddcdb427094916181