From b632a4d288c12f5bd91d2803c3a38c0f1f4cd429 Mon Sep 17 00:00:00 2001 From: MIPAN Date: Thu, 17 Jul 2025 22:29:15 +0800 Subject: [PATCH] refactor: simplify installer package version sync script and add comments --- tools/semantic-release-sync-installer.js | 41 ++++++++++++------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/tools/semantic-release-sync-installer.js b/tools/semantic-release-sync-installer.js index 3a5f3e6b..0a980005 100644 --- a/tools/semantic-release-sync-installer.js +++ b/tools/semantic-release-sync-installer.js @@ -5,27 +5,26 @@ const fs = require('fs'); const path = require('path'); -function prepare(pluginConfig, context) { - const { nextRelease, logger } = context; - - // Path to installer package.json - const installerPackagePath = path.join(process.cwd(), 'tools', 'installer', 'package.json'); - - if (!fs.existsSync(installerPackagePath)) { - logger.log('Installer package.json not found, skipping sync'); - return; - } - - // Read installer package.json - const installerPackage = JSON.parse(fs.readFileSync(installerPackagePath, 'utf8')); - - // Update version - installerPackage.version = nextRelease.version; - - // Write back - fs.writeFileSync(installerPackagePath, JSON.stringify(installerPackage, null, 2) + '\n'); - +// This function runs during the "prepare" step of semantic-release +function prepare(_, { nextRelease, logger }) { + // Define the path to the installer package.json file + const file = path.join(process.cwd(), 'tools/installer/package.json'); + + // If the file does not exist, skip syncing and log a message + if (!fs.existsSync(file)) return logger.log('Installer package.json not found, skipping'); + + // Read and parse the package.json file + const pkg = JSON.parse(fs.readFileSync(file, 'utf8')); + + // Update the version field with the next release version + pkg.version = nextRelease.version; + + // Write the updated JSON back to the file + fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + '\n'); + + // Log success message logger.log(`Synced installer package.json to version ${nextRelease.version}`); } -module.exports = { prepare }; \ No newline at end of file +// Export the prepare function so semantic-release can use it +module.exports = { prepare };