diff --git a/package-lock.json b/package-lock.json index 81489a0..dd5b044 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@flybywiresim/igniter", - "version": "1.2.3", + "version": "1.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@flybywiresim/igniter", - "version": "1.2.3", + "version": "1.3.0", "bin": { "igniter": "dist/binary.mjs" }, diff --git a/package.json b/package.json index c7cdc72..fcb3a95 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@flybywiresim/igniter", - "version": "1.2.3", + "version": "1.3.0", "types": "dist/index.d.ts", "description": "An intelligent task runner written in Typescript.", "repository": { diff --git a/readme.md b/readme.md index 82e8ab5..641aedb 100644 --- a/readme.md +++ b/readme.md @@ -10,17 +10,21 @@ npx igniter --help Usage: igniter [options] Options: - -V, --version output the version number - -c, --config set the configuration file name (default: - "igniter.config.mjs") - -j, --num-workers set the maximum number of workers to use - (default: Number.MAX_SAFE_INTEGER) - -r, --regex regular expression used to filter tasks - -i, --invert if true, regex will be used to reject tasks - --no-cache do not skip tasks, even if hash matches cache - --no-tty do not show updating output, just show a single - render - -d, --dry-run skip all tasks to show configuration - --debug stop when an exception is thrown and show trace - -h, --help display help for command + -V, --version output the version number + -c, --config Set the configuration file name (default: + "igniter.config.mjs") + -j, --num-workers Set the maximum number of workers to use + (default: Number.MAX_SAFE_INTEGER) + -r, --regex Regular expression used to filter tasks. When + multiple regex arguments are supplied, only + tasks that match all of the arguments will be + run + -i, --invert If true, the preceeding regex argument will be + used to reject tasks instead + --no-cache Do not skip tasks, even if hash matches cache + --no-tty Do not show updating output, just show a single + render + -d, --dry-run Skip all tasks to show configuration + --debug Stop when an exception is thrown and show trace + -h, --help display help for command ``` diff --git a/src/Binary.ts b/src/Binary.ts index d85e3fe..0d7d5e6 100644 --- a/src/Binary.ts +++ b/src/Binary.ts @@ -1,20 +1,38 @@ import { Command } from 'commander'; import { Pool } from 'task-pool'; import { findConfigPath, loadConfigTask } from './Helpers'; -import { Context } from './Library/Contracts/Context'; +import { Context, FilterRegex } from './Library/Contracts/Context'; import { version } from '../package.json'; import Renderer from './Renderer'; import Cache from './Cache'; +const allRegex: FilterRegex[] = []; + +function addRegex(regex: string): FilterRegex[] { + allRegex.push({ + regex: RegExp(regex), + invert: false, + }); + return allRegex; +} + +function addRegexInvert(): void { + if (allRegex.length === 0) { + throw new Error('Cannot invert the last regex when there are no regex args!'); + } + allRegex[allRegex.length - 1].invert = true; +} + const binary = (new Command()).version(version) - .option('-c, --config ', 'set the configuration file name', 'igniter.config.mjs') - .option('-j, --num-workers ', 'set the maximum number of workers to use', `${Number.MAX_SAFE_INTEGER}`) - .option('-r, --regex ', 'regular expression used to filter tasks') - .option('-i, --invert', 'if true, regex will be used to reject tasks') - .option('--no-cache', 'do not skip tasks, even if hash matches cache') - .option('--no-tty', 'do not show updating output, just show a single render') - .option('-d, --dry-run', 'skip all tasks to show configuration') - .option('--debug', 'stop when an exception is thrown and show trace') + .option('-c, --config ', 'Set the configuration file name', 'igniter.config.mjs') + .option('-j, --num-workers ', 'Set the maximum number of workers to use', `${Number.MAX_SAFE_INTEGER}`) + .option('-r, --regex ', 'Regular expression used to filter tasks. When multiple regex arguments are supplied,' + + ' only tasks that match all of the arguments will be run', addRegex) + .option('-i, --invert', 'If true, the preceeding regex argument will be used to reject tasks instead', addRegexInvert) + .option('--no-cache', 'Do not skip tasks, even if hash matches cache') + .option('--no-tty', 'Do not show updating output, just show a single render') + .option('-d, --dry-run', 'Skip all tasks to show configuration') + .option('--debug', 'Stop when an exception is thrown and show trace') .parse(process.argv); const options = binary.opts(); @@ -24,8 +42,7 @@ const context: Context = { debug: options.debug, configPath: await findConfigPath(options.config), dryRun: options.dryRun, - filterRegex: options.regex ? RegExp(options.regex) : undefined, - invertRegex: options.invert, + filterRegex: options.regex, taskPool: new Pool({ limit: options.numWorkers, timeout: 120000 }), }; diff --git a/src/Library/Contracts/Context.ts b/src/Library/Contracts/Context.ts index c00d9b1..d6d2ef5 100644 --- a/src/Library/Contracts/Context.ts +++ b/src/Library/Contracts/Context.ts @@ -1,12 +1,16 @@ import { Pool } from 'task-pool'; import { Cache } from './Cache'; +export interface FilterRegex { + regex: RegExp, + invert: boolean, +} + export interface Context { debug: boolean, configPath: string, dryRun: boolean, - filterRegex: RegExp|undefined, - invertRegex: boolean, + filterRegex: FilterRegex[], cache?: Cache, taskPool: Pool, } diff --git a/src/Library/Tasks/GenericTask.ts b/src/Library/Tasks/GenericTask.ts index 4155a2d..22fd293 100644 --- a/src/Library/Tasks/GenericTask.ts +++ b/src/Library/Tasks/GenericTask.ts @@ -68,10 +68,10 @@ export default class GenericTask implements Task { } protected shouldSkipRegex(taskKey: string) { - if (this.context.dryRun) return true; - if (this.context.filterRegex === undefined) return this.context.invertRegex; - const regexMatches = this.context.filterRegex.test(taskKey); - return this.context.invertRegex ? regexMatches : !regexMatches; + if (this.context.dryRun) { + return true; + } + return !this.context.filterRegex.every((r) => (r.regex.test(taskKey) ? !r.invert : r.invert)); } protected shouldSkipCache(taskKey: string) {