feat: add flag to customize package version during pre-release staging (#155)
This commit is contained in:
parent
d97d2a4f7b
commit
d394a9f39f
|
@ -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": {
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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": [
|
||||
|
|
|
@ -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": [
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue