72 lines
2.0 KiB
JavaScript
Executable File
72 lines
2.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Version synchronization script for ailog
|
|
* Syncs version from Cargo.toml to all package.json files
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Read version from Cargo.toml
|
|
function getCargoVersion() {
|
|
const cargoPath = path.join(__dirname, '../Cargo.toml');
|
|
const cargoContent = fs.readFileSync(cargoPath, 'utf8');
|
|
const versionMatch = cargoContent.match(/^version\s*=\s*"([^"]+)"/m);
|
|
|
|
if (!versionMatch) {
|
|
throw new Error('Could not find version in Cargo.toml');
|
|
}
|
|
|
|
return versionMatch[1];
|
|
}
|
|
|
|
// Update package.json version
|
|
function updatePackageVersion(packagePath, version) {
|
|
if (!fs.existsSync(packagePath)) {
|
|
console.warn(`Package.json not found: ${packagePath}`);
|
|
return false;
|
|
}
|
|
|
|
const packageData = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
|
const oldVersion = packageData.version;
|
|
packageData.version = version;
|
|
|
|
fs.writeFileSync(packagePath, JSON.stringify(packageData, null, 2) + '\n');
|
|
console.log(`Updated ${path.relative(process.cwd(), packagePath)}: ${oldVersion} → ${version}`);
|
|
return true;
|
|
}
|
|
|
|
// Main function
|
|
function main() {
|
|
try {
|
|
const version = getCargoVersion();
|
|
console.log(`Cargo.toml version: ${version}`);
|
|
|
|
// List of package.json files to update
|
|
const packageFiles = [
|
|
path.join(__dirname, '../oauth/package.json'),
|
|
path.join(__dirname, '../pds/package.json')
|
|
];
|
|
|
|
let updatedCount = 0;
|
|
for (const packageFile of packageFiles) {
|
|
if (updatePackageVersion(packageFile, version)) {
|
|
updatedCount++;
|
|
}
|
|
}
|
|
|
|
console.log(`✅ Successfully updated ${updatedCount} package.json files`);
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error syncing versions:', error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Run if called directly
|
|
if (require.main === module) {
|
|
main();
|
|
}
|
|
|
|
module.exports = { getCargoVersion, updatePackageVersion }; |