From d18e266e300b5361e829cb98e377c08e97944401 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Fri, 22 Nov 2024 00:56:21 +0100 Subject: [PATCH] Updated script run --- run-scripts.ts | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/run-scripts.ts b/run-scripts.ts index cb8d038..0151276 100644 --- a/run-scripts.ts +++ b/run-scripts.ts @@ -2,11 +2,11 @@ import { execSync } from 'child_process'; import data from './package.json'; /** - * Array of script names. - * - * @var {string[]} + * Script commands to be executed. + * + * @var {string} */ -const scripts: string[] = []; +let scripts = ''; /** * Excluded tests for the script execution. @@ -25,16 +25,21 @@ const excludedTests: string[] = [ // Loop through package scripts and filter out non-test scripts and excluded tests. for (const key in data.scripts) { if (key.startsWith('test:') && ! excludedTests.includes(key)) { - scripts.push(key); + scripts += `npm run ${key} && ` } } -// Loop through and run scripts sequentially. -scripts.forEach(script => { - try { - console.log(`Running: ${script}`); - execSync(`npm run ${script}`, { stdio: 'inherit' }); - } catch (error) { - console.error(`Error running ${script}:`, error.message); - } -}); \ No newline at end of file +const char = '&&'; + +const escapedChar = char.replace(/[.*+?^${}()|[\]\\ ]/g, '\\$&'); +const regex = new RegExp(`${escapedChar}\\s*$`); +scripts = scripts.replace(regex, ''); + + +// Run scripts sequentially. +try { + console.log(`Running: ${scripts}`); + execSync(scripts, { stdio: 'inherit' }); +} catch (error) { + console.error(error.message); +} \ No newline at end of file