From e7438d6ffb728ba767d3a4727cc1532dcd68715c Mon Sep 17 00:00:00 2001 From: Jayan Ratna Date: Mon, 9 Sep 2024 13:55:15 +1200 Subject: [PATCH 1/3] feat: Auto update the SDK version --- package.json | 3 ++- scripts/update-version.js | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 scripts/update-version.js diff --git a/package.json b/package.json index cba9cc1..2340e6e 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "test": "jest", "lint": "biome lint --error-on-warnings ./src", "format": "biome format --write ./src", + "update-version": "node scripts/update-version.js", "prepublishOnly": "npm run build" }, "devDependencies": { @@ -55,6 +56,6 @@ "node": ">=18" }, "volta": { - "node": "20.12.2" + "node": "20.16.0" } } diff --git a/scripts/update-version.js b/scripts/update-version.js new file mode 100644 index 0000000..93e8391 --- /dev/null +++ b/scripts/update-version.js @@ -0,0 +1,54 @@ +#!/usr/bin/env node + +const fs = require('node:fs') +const path = require('node:path') + +const packageJsonPath = path.join(__dirname, '..', 'package.json') + +// Get the current version from package.json +function getPackageJsonVersion() { + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) + return packageJson.version +} + +// Bump the version based on the given version type +function bumpVersion(currentVersion, type) { + const versionParts = currentVersion.split('.').map(Number) + + switch (type) { + case '--major': + versionParts[0]++ + versionParts[1] = 0 + versionParts[2] = 0 + break + case '--minor': + versionParts[1]++ + versionParts[2] = 0 + break + case '--patch': + versionParts[2]++ + break + default: + throw new Error('Invalid argument. Use --major, --minor, or --patch') + } + + return versionParts.join('.') +} + +// The main function +function main() { + const args = process.argv.slice(2) + if (args.length !== 1) { + console.error( + 'Please provide exactly one argument: --major, --minor, or --patch' + ) + process.exit(1) + } + + const currentVersion = getPackageJsonVersion() + const newVersion = bumpVersion(currentVersion, args[0]) + + console.log(currentVersion, newVersion) +} + +main() From c98d1dad7b6c4599ba6627f213a1a9ed08320df7 Mon Sep 17 00:00:00 2001 From: Jayan Ratna Date: Mon, 9 Sep 2024 14:30:06 +1200 Subject: [PATCH 2/3] add additional logic --- scripts/update-version.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/update-version.js b/scripts/update-version.js index 93e8391..a246283 100644 --- a/scripts/update-version.js +++ b/scripts/update-version.js @@ -4,6 +4,7 @@ const fs = require('node:fs') const path = require('node:path') const packageJsonPath = path.join(__dirname, '..', 'package.json') +const blutuiPath = path.join(__dirname, '..', 'src', 'blutui.ts') // Get the current version from package.json function getPackageJsonVersion() { @@ -35,6 +36,26 @@ function bumpVersion(currentVersion, type) { return versionParts.join('.') } +// Update the package.json version +function updatePackageJsonVersion(newVersion) { + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) + packageJson.version = newVersion + fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`) +} + +// Update VERSION constant in blutui.ts +function updateBlutuiVersion(newVersion) { + let blutuiContent = fs.readFileSync(blutuiPath, 'utf-8') + const versionRegex = /const VERSION = '([0-9]+\.[0-9]+\.[0-9]+)'/ + + blutuiContent = blutuiContent.replace( + versionRegex, + `const VERSION = '${newVersion}'` + ) + + fs.writeFileSync(blutuiPath, blutuiContent) +} + // The main function function main() { const args = process.argv.slice(2) @@ -48,7 +69,10 @@ function main() { const currentVersion = getPackageJsonVersion() const newVersion = bumpVersion(currentVersion, args[0]) - console.log(currentVersion, newVersion) + updatePackageJsonVersion(newVersion) + updateBlutuiVersion(newVersion) + + console.log(`Version updated to ${newVersion}`) } main() From 9eba981598f41b3f3a6084447022a7820f8f45e3 Mon Sep 17 00:00:00 2001 From: Jayan Ratna <30396013+jayan-blutui@users.noreply.github.com> Date: Wed, 11 Sep 2024 09:08:38 +1200 Subject: [PATCH 3/3] Update scripts/update-version.js Co-authored-by: Michael Liu <162056370+chengfang-blutui@users.noreply.github.com> --- scripts/update-version.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update-version.js b/scripts/update-version.js index a246283..6856fc1 100644 --- a/scripts/update-version.js +++ b/scripts/update-version.js @@ -72,7 +72,7 @@ function main() { updatePackageJsonVersion(newVersion) updateBlutuiVersion(newVersion) - console.log(`Version updated to ${newVersion}`) + console.log(`Version updated from ${$currentVersion} to ${newVersion}`) } main()