feat: add flag to customize package version during pre-release staging (#155)

This commit is contained in:
Brandon Keiji 2025-04-24 20:02:49 +00:00 committed by GitHub
parent d97d2a4f7b
commit d394a9f39f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 15 deletions

3
package-lock.json generated
View File

@ -21,7 +21,8 @@
"lodash": "^4.17.21",
"prettier": "^3.5.3",
"react-devtools-core": "^4.28.5",
"typescript-eslint": "^8.30.1"
"typescript-eslint": "^8.30.1",
"yargs": "^17.7.2"
}
},
"node_modules/@alcalzone/ansi-tokenize": {

View File

@ -18,7 +18,7 @@
"format": "prettier --write .",
"preflight": "npm run format --workspaces --if-present && npm run lint --workspaces --if-present && npm run test --workspaces --if-present",
"auth": "npx google-artifactregistry-auth",
"stage": "npm run stage:version --workspaces && npm run stage:deps --workspaces"
"prerelease:dev": "npm run prerelease:version --workspaces && npm run prerelease:deps --workspaces"
},
"devDependencies": {
"eslint": "^9.24.0",
@ -31,6 +31,7 @@
"lodash": "^4.17.21",
"prettier": "^3.5.3",
"react-devtools-core": "^4.28.5",
"typescript-eslint": "^8.30.1"
"typescript-eslint": "^8.30.1",
"yargs": "^17.7.2"
}
}

View File

@ -15,8 +15,8 @@
"lint": "eslint . --ext .ts,.tsx",
"format": "prettier --write .",
"test": "vitest run",
"stage:version": "node ../../scripts/bind_package_version.js",
"stage:deps": "node ../../scripts/bind_package_dependencies.js",
"prerelease:version": "node ../../scripts/bind_package_version.js",
"prerelease:deps": "node ../../scripts/bind_package_dependencies.js",
"prepack": "npm run build"
},
"files": [

View File

@ -11,8 +11,8 @@
"lint": "eslint . --ext .ts,.tsx",
"format": "prettier --write .",
"test": "vitest run",
"stage:version": "node ../../scripts/bind_package_version.js",
"stage:deps": "node ../../scripts/bind_package_dependencies.js",
"prerelease:version": "node ../../scripts/bind_package_version.js",
"prerelease:deps": "node ../../scripts/bind_package_dependencies.js",
"prepack": "npm run build"
},
"files": [

View File

@ -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');