Files
jetbrains-cc-gui/webview/scripts/extract-version.mjs
zkpaiminmin 96ec9b89cc docs: translate Chinese comments and JSDoc to English across 14 files
Standardize code documentation language to English for better international
collaboration, covering ai-bridge services, Java backend, webview scripts,
and frontend utilities.
2026-03-17 19:16:38 +08:00

56 lines
1.7 KiB
JavaScript

#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// Get the current directory
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Get the project root directory (the parent of webview)
const projectRoot = path.resolve(__dirname, '../..');
const buildGradlePath = path.join(projectRoot, 'build.gradle');
// Read the build.gradle file
const buildGradleContent = fs.readFileSync(buildGradlePath, 'utf8');
// Extract the version number
// Look for a line like: version = '0.1.0-beta3'
let versionMatch = buildGradleContent.match(/^version\s*=\s*'(.+)'$/m);
if (!versionMatch) {
// If the regex above fails, try a fallback approach
const lines = buildGradleContent.split('\n');
const versionLine = lines.find(line => line.trim().startsWith('version ='));
if (versionLine) {
const match = versionLine.match(/version\s*=\s*'(.+)'/);
if (match) {
versionMatch = match;
}
}
}
if (!versionMatch) {
console.error('Error: Could not find version in build.gradle');
process.exit(1);
}
const version = versionMatch[1];
console.log(`Found version: ${version}`);
// Create the version file for the webview
const versionDir = path.join(__dirname, '../src/version');
if (!fs.existsSync(versionDir)) {
fs.mkdirSync(versionDir, { recursive: true });
}
const versionFilePath = path.join(versionDir, 'version.ts');
const versionFileContent = `// Auto-generated version file
// This file is automatically generated during the build process
// Do not edit manually
export const APP_VERSION = '${version}';
`;
fs.writeFileSync(versionFilePath, versionFileContent);
console.log(`Version file created at: ${versionFilePath}`);