refactor: simplify installer package version sync script and add comments

This commit is contained in:
MIPAN 2025-07-17 22:29:15 +08:00 committed by GitHub
parent 0089110e3c
commit b632a4d288
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 21 deletions

View File

@ -5,27 +5,26 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
function prepare(pluginConfig, context) { // This function runs during the "prepare" step of semantic-release
const { nextRelease, logger } = context; function prepare(_, { nextRelease, logger }) {
// Define the path to the installer package.json file
const file = path.join(process.cwd(), 'tools/installer/package.json');
// Path to installer package.json // If the file does not exist, skip syncing and log a message
const installerPackagePath = path.join(process.cwd(), 'tools', 'installer', 'package.json'); if (!fs.existsSync(file)) return logger.log('Installer package.json not found, skipping');
if (!fs.existsSync(installerPackagePath)) { // Read and parse the package.json file
logger.log('Installer package.json not found, skipping sync'); const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
return;
}
// Read installer package.json // Update the version field with the next release version
const installerPackage = JSON.parse(fs.readFileSync(installerPackagePath, 'utf8')); pkg.version = nextRelease.version;
// Update version // Write the updated JSON back to the file
installerPackage.version = nextRelease.version; fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + '\n');
// Write back
fs.writeFileSync(installerPackagePath, JSON.stringify(installerPackage, null, 2) + '\n');
// Log success message
logger.log(`Synced installer package.json to version ${nextRelease.version}`); logger.log(`Synced installer package.json to version ${nextRelease.version}`);
} }
// Export the prepare function so semantic-release can use it
module.exports = { prepare }; module.exports = { prepare };