budibase/scripts/syncProPackage.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-04-21 18:44:11 +02:00
const fs = require("fs")
const path = require("path")
const { execSync } = require("child_process")
2023-04-21 18:52:05 +02:00
let version = "0.0.1"
2023-04-21 18:54:12 +02:00
const localPro = fs.existsSync("packages/pro/packages")
2023-04-21 18:52:05 +02:00
if (!localPro) {
const branchName = execSync("git rev-parse --abbrev-ref HEAD")
.toString()
.trim()
if (branchName === "master") {
version = "latest"
} else {
version = "develop"
}
2023-04-21 18:44:11 +02:00
}
// Get the list of workspaces with mismatched dependencies
const output = execSync("yarn --silent workspaces info --json", {
encoding: "utf-8",
})
const data = JSON.parse(output)
// Loop through each workspace and update the dependencies
Object.keys(data).forEach(workspace => {
// Loop through each dependency and update its version in package.json
const packageJsonPath = path.join(data[workspace].location, "package.json")
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"))
let hasChanges = false
if (packageJson.dependencies["@budibase/pro"]) {
packageJson.dependencies["@budibase/pro"] = version
hasChanges = true
}
// Write changes to package.json if there are any
if (hasChanges) {
fs.writeFileSync(
packageJsonPath,
JSON.stringify(packageJson, null, 2) + "\n"
)
}
})