2023-02-20 11:08:55 +03:00
|
|
|
const fs = require('fs')
|
|
|
|
const execSync = require('child_process').execSync
|
|
|
|
const repo = '@hcengineering'
|
|
|
|
|
|
|
|
const packages = {}
|
|
|
|
const pathes = {}
|
|
|
|
const jsons = {}
|
|
|
|
|
|
|
|
function fillPackages (config) {
|
|
|
|
for (const package of config.projects) {
|
2024-10-01 14:03:26 +03:00
|
|
|
if (!package.name.startsWith(repo)) continue
|
|
|
|
|
2023-02-20 11:08:55 +03:00
|
|
|
packages[package.name] = {
|
|
|
|
version: package.version,
|
2024-10-01 14:03:26 +03:00
|
|
|
path: package.path
|
2023-02-20 11:08:55 +03:00
|
|
|
}
|
|
|
|
pathes[package.path] = package.name
|
|
|
|
|
2024-10-01 14:03:26 +03:00
|
|
|
const file = package.path + '/package.json'
|
|
|
|
const raw = fs.readFileSync(file)
|
|
|
|
jsons[package.name] = JSON.parse(raw)
|
2023-02-20 11:08:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 14:03:26 +03:00
|
|
|
function bumpPackage (name, newVersion) {
|
|
|
|
const json = jsons[name]
|
|
|
|
|
|
|
|
json.version = newVersion
|
|
|
|
if (typeof json.dependencies === 'object') {
|
|
|
|
for (const [dependency] of Object.entries(json.dependencies)) {
|
|
|
|
if (packages[dependency] !== undefined) {
|
|
|
|
json.dependencies[dependency] = `^${newVersion}`
|
2023-02-20 11:08:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 14:03:26 +03:00
|
|
|
function shouldPublish (name) {
|
|
|
|
const json = jsons[name]
|
|
|
|
return json !== undefined && json.repository !== undefined
|
2023-02-20 11:08:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function publish (name) {
|
|
|
|
const package = packages[name]
|
2023-02-21 10:25:01 +03:00
|
|
|
try {
|
2024-10-01 14:03:26 +03:00
|
|
|
console.log('publishing', name)
|
2023-02-21 10:25:01 +03:00
|
|
|
execSync(`cd ${package.path} && npm publish && cd ../..`, { encoding: 'utf-8' })
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
2023-02-20 11:08:55 +03:00
|
|
|
}
|
|
|
|
|
2024-11-07 18:08:02 +03:00
|
|
|
function fix (name) {
|
|
|
|
const package = packages[name]
|
|
|
|
try {
|
|
|
|
console.log('fixing', name)
|
|
|
|
execSync(`cd ${package.path} && npm pkg fix && cd ../..`, { encoding: 'utf-8' })
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 11:08:55 +03:00
|
|
|
function main () {
|
|
|
|
const args = process.argv
|
|
|
|
|
2024-11-07 18:08:02 +03:00
|
|
|
const doFix = args.includes('--fix')
|
2024-10-02 13:58:46 +03:00
|
|
|
const doPublish = args.includes('--publish')
|
|
|
|
|
|
|
|
const version = args.reverse().shift()
|
2024-10-01 14:03:26 +03:00
|
|
|
if (version === undefined || version === '') {
|
2024-10-02 13:58:46 +03:00
|
|
|
console.log('usage: node bump.js [--publish] <version>')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if( !/^(\d+\.)?(\d+\.)?(\*|\d+)$/.test(version)) {
|
|
|
|
console.log('Invalid <version>', version, ' should be xx.xx.xx')
|
2024-10-01 14:03:26 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('bump version ...', version)
|
|
|
|
|
2023-02-21 10:25:01 +03:00
|
|
|
const config = JSON.parse(execSync('rush list -p --json', { encoding: 'utf-8' }))
|
2023-02-20 11:08:55 +03:00
|
|
|
|
|
|
|
fillPackages(config)
|
|
|
|
|
2024-10-01 14:03:26 +03:00
|
|
|
const packageNames = Object.keys(packages)
|
|
|
|
for (const packageName of packageNames) {
|
|
|
|
bumpPackage(packageName, version)
|
2023-02-20 11:08:55 +03:00
|
|
|
}
|
|
|
|
|
2024-10-01 14:03:26 +03:00
|
|
|
for (const packageName of packageNames) {
|
2023-02-20 11:08:55 +03:00
|
|
|
const package = packages[packageName]
|
|
|
|
const file = package.path + '/package.json'
|
|
|
|
const res = JSON.stringify(jsons[packageName], undefined, 2)
|
|
|
|
fs.writeFileSync(file, res + '\n')
|
|
|
|
}
|
2024-11-07 18:08:02 +03:00
|
|
|
if (doFix) {
|
|
|
|
for (const packageName of packageNames) {
|
|
|
|
if (shouldPublish(packageName)) {
|
|
|
|
fix(packageName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (doPublish) {
|
2024-10-02 13:58:46 +03:00
|
|
|
for (const packageName of packageNames) {
|
|
|
|
if (shouldPublish(packageName)) {
|
|
|
|
publish(packageName)
|
|
|
|
}
|
2023-02-20 11:08:55 +03:00
|
|
|
}
|
|
|
|
}
|
2024-10-01 14:03:26 +03:00
|
|
|
|
|
|
|
console.log('... done')
|
2023-02-20 11:08:55 +03:00
|
|
|
}
|
|
|
|
|
2024-10-01 14:03:26 +03:00
|
|
|
main ()
|