|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import fs from 'node:fs'; |
|
|
import path from 'node:path'; |
|
|
|
|
|
|
|
|
const packageDir = process.cwd(); |
|
|
const rootDir = path.join(packageDir, '..', '..'); |
|
|
|
|
|
function getRepoVersion() { |
|
|
|
|
|
const rootPackageJsonPath = path.join(rootDir, 'package.json'); |
|
|
const rootPackage = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8')); |
|
|
return rootPackage.version; |
|
|
} |
|
|
|
|
|
const newVersion = getRepoVersion(); |
|
|
console.log(`Setting package version to: ${newVersion}`); |
|
|
|
|
|
const packageJsonPath = path.join(packageDir, 'package.json'); |
|
|
|
|
|
if (fs.existsSync(packageJsonPath)) { |
|
|
console.log(`Updating version for ${packageJsonPath}`); |
|
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); |
|
|
packageJson.version = newVersion; |
|
|
fs.writeFileSync( |
|
|
packageJsonPath, |
|
|
JSON.stringify(packageJson, null, 2) + '\n', |
|
|
'utf8', |
|
|
); |
|
|
} else { |
|
|
console.error( |
|
|
`Error: package.json not found in the current directory: ${packageJsonPath}`, |
|
|
); |
|
|
process.exit(1); |
|
|
} |
|
|
|
|
|
console.log('Done.'); |
|
|
|