From e14c569aa40675774f5155ed7f546a4330c948cf Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 2 Jul 2024 11:38:21 +0200 Subject: [PATCH] Add run-affected script --- scripts/run-affected.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 scripts/run-affected.js diff --git a/scripts/run-affected.js b/scripts/run-affected.js new file mode 100755 index 0000000000..051c61f114 --- /dev/null +++ b/scripts/run-affected.js @@ -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}...`) +}