This commit is contained in:
AI Christianson 2025-03-05 07:43:18 -05:00
parent 0b621b6008
commit 07a5900b59
4 changed files with 99 additions and 3 deletions

View File

@ -4,15 +4,17 @@
"private": true,
"scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start",
"build": "docusaurus build",
"start": "node scripts/version.js && docusaurus start",
"generate-version": "node scripts/version.js",
"build": "npm run generate-version && docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"typecheck": "tsc"
"typecheck": "tsc",
"version-json": "node scripts/version.js"
},
"dependencies": {
"@docusaurus/core": "3.7.0",

31
docs/scripts/README.md Normal file
View File

@ -0,0 +1,31 @@
# Docusaurus Scripts
This directory contains utility scripts for the Docusaurus documentation site.
## version.js
This script reads the version from `../../ra_aid/__version__.py` and creates a `version.json` file in the Docusaurus `static/` directory, which will be included in the built site.
### Usage
The script is automatically run as part of the build and start processes via npm scripts defined in `package.json`, but can also be run manually:
```bash
# From docs directory
npm run version-json
# Or directly
node scripts/version.js
```
### Output
The script creates a `static/version.json` file with the following format:
```json
{
"version": "x.y.z"
}
```
This file will be available at `/version.json` in the built site, allowing client-side version checks.

62
docs/scripts/version.js Executable file
View File

@ -0,0 +1,62 @@
#!/usr/bin/env node
/**
* Script to read version from ra_aid/__version__.py and create version.json
* in the Docusaurus static directory.
*/
const fs = require('fs');
const path = require('path');
// Paths
const versionFilePath = path.resolve(__dirname, '../../ra_aid/__version__.py');
const outputPath = path.resolve(__dirname, '../static/version.json');
/**
* Extract version string from the __version__.py file
* @param {string} content - The file content
* @returns {string|null} - Extracted version or null if not found
*/
function extractVersion(content) {
const regex = /__version__\s*=\s*["']([^"']+)["']/;
const match = content.match(regex);
return match ? match[1] : null;
}
// Main function to create version.json
function createVersionJson() {
try {
// Read version file
console.log(`Reading version from ${versionFilePath}...`);
const versionFileContent = fs.readFileSync(versionFilePath, 'utf8');
// Extract version
const version = extractVersion(versionFileContent);
if (!version) {
console.error('Failed to extract version from file');
process.exit(1);
}
console.log(`Extracted version: ${version}`);
// Create version JSON
const versionJson = JSON.stringify({ version }, null, 2);
// Ensure static directory exists
const staticDir = path.dirname(outputPath);
if (!fs.existsSync(staticDir)) {
console.log(`Creating directory: ${staticDir}`);
fs.mkdirSync(staticDir, { recursive: true });
}
// Write JSON file
fs.writeFileSync(outputPath, versionJson);
console.log(`Version JSON written to ${outputPath}`);
} catch (error) {
console.error(`Error creating version.json: ${error.message}`);
process.exit(1);
}
}
// Execute the main function
createVersionJson();

1
docs/static/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
version.json