Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions common/scripts/bump.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
const fs = require('fs')
const path = require('path')
const execSync = require('child_process').execSync
const repo = '@hcengineering'

const packages = {}
const pathes = {}
const jsons = {}
const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim()

function fillPackages (config) {
for (const package of config.projects) {
if (!package.name.startsWith(repo)) continue
for (const project of config.projects) {
const packageName = project.name ?? project.packageName
if (typeof packageName !== 'string' || !packageName.startsWith(repo)) continue
const projectPath = project.path ?? project.projectFolder ?? path.relative(repoRoot, project.fullPath ?? '')
if (typeof projectPath !== 'string' || projectPath.length === 0) continue
const fullProjectPath = path.resolve(repoRoot, projectPath)

packages[packageName] = {
version: project.version,
path: fullProjectPath
}
pathes[fullProjectPath] = packageName

packages[package.name] = {
version: package.version,
path: package.path
const file = path.join(fullProjectPath, 'package.json')
if (!fs.existsSync(file)) {
console.log('skip, package.json not found:', file)
continue
}
pathes[package.path] = package.name

const file = package.path + '/package.json'
const raw = fs.readFileSync(file)
jsons[package.name] = JSON.parse(raw)
const raw = fs.readFileSync(file)
jsons[packageName] = JSON.parse(raw)
}
}

function bumpPackage (name, newVersion) {
const json = jsons[name]

if (json === undefined) return
json.version = newVersion
if (typeof json.dependencies === 'object') {
for (const [dependency] of Object.entries(json.dependencies)) {
const depTypes = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']
for (const depType of depTypes) {
if (typeof json[depType] !== 'object') continue
for (const [dependency, currentVersion] of Object.entries(json[depType])) {
if (packages[dependency] !== undefined) {
json.dependencies[dependency] = `^${newVersion}`
json[depType][dependency] = String(currentVersion).startsWith('workspace:')
? `workspace:^${newVersion}`
: `^${newVersion}`
}
}
}
Expand All @@ -44,7 +60,7 @@ function publish (name) {
const package = packages[name]
try {
console.log('publishing', name)
execSync(`cd ${package.path} && npm publish && cd ../..`, { encoding: 'utf-8' })
execSync('npm publish', { encoding: 'utf-8', cwd: package.path })
} catch (err) {
console.log(err)
}
Expand All @@ -54,7 +70,7 @@ function fix (name) {
const package = packages[name]
try {
console.log('fixing', name)
execSync(`cd ${package.path} && npm pkg fix && cd ../..`, { encoding: 'utf-8' })
execSync('npm pkg fix', { encoding: 'utf-8', cwd: package.path })
} catch (err) {
console.log(err)
}
Expand Down Expand Up @@ -89,7 +105,8 @@ function main () {

for (const packageName of packageNames) {
const package = packages[packageName]
const file = package.path + '/package.json'
if (jsons[packageName] === undefined) continue
const file = path.join(package.path, 'package.json')
const res = JSON.stringify(jsons[packageName], undefined, 2)
fs.writeFileSync(file, res + '\n')
}
Expand Down
Loading