From dabc7d9b8ebe9dcc139cdc7c7235ddb5159d8641 Mon Sep 17 00:00:00 2001 From: Zalmoxisus Date: Fri, 7 Dec 2018 18:59:40 +0200 Subject: [PATCH] Run tests in packages --- package.json | 2 ++ scripts/run-in-packages.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 scripts/run-in-packages.js diff --git a/package.json b/package.json index eb15ce72..d9743699 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,8 @@ "lerna": "3.4.2" }, "scripts": { + "lint": "node ./scripts/run-in-packages npm run lint", + "test": "node ./scripts/run-in-packages npm run test" }, "workspaces": [ "packages/*" diff --git a/scripts/run-in-packages.js b/scripts/run-in-packages.js new file mode 100644 index 00000000..c675dca3 --- /dev/null +++ b/scripts/run-in-packages.js @@ -0,0 +1,21 @@ +const path = require("path"); +const { readdirSync, statSync } = require('fs'); +const { execSync } = require("child_process"); + +const execArgs = { stdio: "inherit", env: process.env }; +const command = process.argv.slice(2).join(' '); + +const getDirectories = srcPath => readdirSync(srcPath) + .filter(file => statSync(path.join(srcPath, file)).isDirectory()); + +if (!command) { + console.error('No command specified.') +} else { + const cwd = process.cwd(); + getDirectories('packages').forEach(packageName => { + console.log(packageName, path.resolve(__dirname, "../packages/" + packageName)); + process.chdir(path.resolve(__dirname, "../packages/" + packageName)); + execSync(command, execArgs); + }); + process.chdir(cwd); +}