Skip to content

Commit

Permalink
Feature to comment out a command
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Jul 21, 2023
1 parent 1dd9290 commit 261dd67
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
34 changes: 24 additions & 10 deletions README.md
Expand Up @@ -64,15 +64,7 @@ Example **package.json** scripts:
},
```

### 2. Debug a command
To manually run a single command, use `npx` from the terminal plus the `--only` flag.

For example, to run the third command in the `compile` group by itself:
```shell
$ npx run-scripts compile --only=3
```

### 3. CLI flags
### 2. CLI flags
Command-line flags:
| Flag | Description | Value |
| ------------ | ------------------------------------------------------ | ---------- |
Expand All @@ -82,7 +74,7 @@ Command-line flags:
| `--quiet` | Suppress informational messages. | N/A |
| `--verbose` | Add script group name to informational messages. | N/A |

### 4. Example CLI usage
### 3. Example CLI usage
Examples:
- `run-scripts clean compile`<br>
Execute the `clean` group of commands and then execute the `compile` group fo commands.
Expand All @@ -97,6 +89,28 @@ 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
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:
```json
"runScriptsConfig": {
"compile": [
"- tsc",
"tsc --force --verbose",
"lessc src/web-app/style.less build/web-app/style.css"
]
}
```

### 5. Debug a command
To manually run a single command, use `npx` from the terminal plus the `--only` flag.

For example, to run the third command in the `compile` group by itself:
```shell
$ npx run-scripts compile --only=3
```

## C) Application Code
Even though **run-scripts-util** is primarily intended for build scripts, the package can easily be used programmatically in ESM and TypeScript projects.

Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -70,6 +70,7 @@
"runScriptsConfig": {
"spec-a": [
"copy-folder bin spec/fixtures/target/a",
"- echo 'This command will be skipped.'",
"copy-file spec/fixtures/target/a/cli.js spec/fixtures/target/a/cli2.js",
"copy-folder .github/workflows spec/fixtures/target/a"
],
Expand Down Expand Up @@ -111,13 +112,13 @@
"devDependencies": {
"@types/fancy-log": "~2.0",
"@types/node": "~20.4",
"@typescript-eslint/eslint-plugin": "~6.0",
"@typescript-eslint/parser": "~6.0",
"@typescript-eslint/eslint-plugin": "~6.1",
"@typescript-eslint/parser": "~6.1",
"add-dist-header": "~1.1",
"assert-deep-strict-equal": "~1.1",
"copy-file-util": "~1.1",
"copy-folder-util": "~1.1",
"eslint": "~8.44",
"eslint": "~8.45",
"jshint": "~2.13",
"mocha": "~10.2",
"npm-run-all2": "~6.0",
Expand Down
12 changes: 9 additions & 3 deletions run-scripts.ts
Expand Up @@ -57,7 +57,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: string, step: number) => {
const execCommand = (step: number, command: string) => {
const startTime = Date.now();
if (!settings.quiet)
console.log();
Expand All @@ -70,9 +70,15 @@ const runScripts = {
throw Error(errorMessage() + '\nCommand: ' + command);
logger(...logItems, chalk.green('done'), chalk.white(`(${Date.now() - startTime}ms)`));
};
const active = (step: number) => settings.only === null || step === settings.only;
const skip = (step: number, command: string) => {
const inactive = step === settings.only;
const commentedOut = command.startsWith('-');
if (commentedOut)
logger(chalk.yellow('skipping'), arrow, command);
return inactive || commentedOut;
};
commands.forEach((command: string, index: number) =>
active(index + 1) && execCommand(command, index + 1));
!skip(index + 1, command) && execCommand(index + 1, command));
},

execParallel(group: string, options?: Options) {
Expand Down

0 comments on commit 261dd67

Please sign in to comment.