diff options
Diffstat (limited to 'scripts/bind_package_version.js')
| -rw-r--r-- | scripts/bind_package_version.js | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/scripts/bind_package_version.js b/scripts/bind_package_version.js index 51df72ce..b0e56f2f 100644 --- a/scripts/bind_package_version.js +++ b/scripts/bind_package_version.js @@ -6,6 +6,9 @@ import fs from 'node:fs'; import path from 'node:path'; +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; +import { execSync } from 'node:child_process'; // Assuming script is run from a package directory (e.g., packages/cli) const packageDir = process.cwd(); @@ -17,16 +20,32 @@ function getBaseVersion() { const rootPackage = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8')); let baseVersion = rootPackage.version; - // Append nightly suffix - const today = new Date(); - const yyyy = today.getFullYear(); - const mm = String(today.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed - const dd = String(today.getDate()).padStart(2, '0'); - const nightlySuffix = `-nightly-${yyyy}${mm}${dd}`; - return `${baseVersion}${nightlySuffix}`; + // Get latest commit hash + const commitHash = execSync('git rev-parse --short HEAD', { + encoding: 'utf8', + }).trim(); + + // Append dev suffix with commit hash + const devSuffix = `-dev-${commitHash}.0`; + return `${baseVersion}${devSuffix}`; +} + +const argv = yargs(hideBin(process.argv)) + .option('pkg-version', { + type: 'string', + description: 'Set the package version', + }) + .parse(); + +const newVersion = argv['pkg-version'] ?? getBaseVersion(); +if (argv['pkg-version']) { + console.log(`Using provided package version (--pkg-version): ${newVersion}`); +} else { + console.log( + `Using base version with dev suffix and commit hash: ${newVersion}`, + ); } -const newVersion = getBaseVersion(); console.log(`Setting package version to: ${newVersion}`); const packageJsonPath = path.join(packageDir, 'package.json'); |
