diff --git a/README.md b/README.md index eb74875..ed582a8 100644 --- a/README.md +++ b/README.md @@ -89,15 +89,15 @@ Examples: Execute all the `lint` commands in parallel and after all the commands are finished execute the `watch` commands in parallel. -### 5. Skip a command +### 4. Skip a command To _comment out_ a command prepend a dash (`-`) to the command. -In the example below, the first `tsc` command will be skipped while the `tsc --force --verbose` command will be executed: +In the example below, the first `tsc` command will be skipped while the `tsc --verbose` command will be executed: ```json "runScriptsConfig": { "compile": [ "- tsc", - "tsc --force --verbose", + "tsc --verbose", "lessc src/web-app/style.less build/web-app/style.css" ] } diff --git a/dist/run-scripts.d.ts b/dist/run-scripts.d.ts index b05fb08..c82020f 100644 --- a/dist/run-scripts.d.ts +++ b/dist/run-scripts.d.ts @@ -1,4 +1,4 @@ -//! run-scripts-util v1.2.0 ~~ https://github.com/center-key/run-scripts-util ~~ MIT License +//! run-scripts-util v1.2.1 ~~ https://github.com/center-key/run-scripts-util ~~ MIT License export type Settings = { only: number | null; diff --git a/dist/run-scripts.js b/dist/run-scripts.js index 84d1f90..8801cae 100644 --- a/dist/run-scripts.js +++ b/dist/run-scripts.js @@ -1,4 +1,4 @@ -//! run-scripts-util v1.2.0 ~~ https://github.com/center-key/run-scripts-util ~~ MIT License +//! run-scripts-util v1.2.1 ~~ https://github.com/center-key/run-scripts-util ~~ MIT License import { spawn, spawnSync } from 'node:child_process'; import chalk from 'chalk'; @@ -19,7 +19,7 @@ const runScripts = { const logger = createLogger(settings); if (!Array.isArray(commands) || commands.some(command => typeof command !== 'string')) throw Error('[run-scripts-util] Cannot find commands: ' + group); - const execCommand = (command, step) => { + const execCommand = (step, command) => { const startTime = Date.now(); if (!settings.quiet) console.log(); @@ -31,8 +31,14 @@ const runScripts = { throw Error(errorMessage() + '\nCommand: ' + command); logger(...logItems, chalk.green('done'), chalk.white(`(${Date.now() - startTime}ms)`)); }; - const active = (step) => settings.only === null || step === settings.only; - commands.forEach((command, index) => active(index + 1) && execCommand(command, index + 1)); + const skip = (step, command) => { + const inactive = step === settings.only; + const commentedOut = command.startsWith('-'); + if (commentedOut) + logger(chalk.yellow('skipping'), arrow, command); + return inactive || commentedOut; + }; + commands.forEach((command, index) => !skip(index + 1, command) && execCommand(index + 1, command)); }, execParallel(group, options) { const defaults = { diff --git a/package.json b/package.json index d4ae781..a78918b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "run-scripts-util", - "version": "1.2.0", + "version": "1.2.1", "description": "Organize npm scripts into named groups of easy to manage commands (CLI tool designed for use in npm scripts)", "license": "MIT", "type": "module",