Add run-affected script

This commit is contained in:
Adria Navarro 2024-07-02 11:38:21 +02:00
parent dd70f0b72b
commit e14c569aa4
1 changed files with 29 additions and 0 deletions

29
scripts/run-affected.js Executable file
View File

@ -0,0 +1,29 @@
const { execSync } = require("child_process")
const argv = require("yargs").demandOption([
"task",
"since",
"package-name",
]).argv
const { task, since, packageName } = argv
const affectedPackages = execSync(
`yarn --silent lerna ls --since=${since} --json`,
{
encoding: "utf-8",
}
)
const packages = JSON.parse(affectedPackages)
const isAffected = packages.some(pkg => pkg.name === packageName)
if (isAffected) {
console.log(`${packageName} is affected. Running ${task}...`)
execSync(`yarn ${task} --scope=${packageName}`, {
stdio: "inherit",
})
} else {
console.log(`${packageName} is not affected. Skipping ${task}...`)
}