Skip to content

Commit

Permalink
Updated script run
Browse files Browse the repository at this point in the history
  • Loading branch information
jeawhanlee committed Nov 21, 2024
1 parent a1ae3b5 commit d18e266
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions run-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
});
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);
}

0 comments on commit d18e266

Please sign in to comment.