@flemist/run-script

Use JavaScript instead npm scripts


Keywords
npm, run, script, scripts, cli, execute, run-script, javascript, js, parallel, sequential, helpers, utils, tools, shell, ci
License
CC0-1.0
Install
npm install @flemist/run-script@2.0.0

Documentation

Build Status

Description

Run

run-script "console.log(123)"
run-script --config .run-script-rc.js "console.log(123)"
run-script "require(./scripts.js).run({ option1: true, option2: true })"

Script helpers

const {run, singleCall, singleProcess} = require('../helpers/helpers')

// singleCall - Create function that skip all executions except first
const buildMjs = singleCall(() => {
    // run - execute command line
	const {out, err, both} = await run(`babel src -x .js -x .ts`, {
        // see: IRunOptions
        returnOutputs: true,
    })
})

// singleProcess - Create function that wait unlit previous execution is completed before the next one
const build = singleProcess(async appConfigType => {
	await Promise.all([
		common.build(),
		buildMjs(appConfigType),
		buildJs(appConfigType),
	])
})

export interface IRunOptions {
	env?: ProcessEnv,
	cwd? : string,
	timeout?: number,
	notAutoKill?: boolean, // don't auto kill all process tree after error
	stdin?: undefined | null | 'pipe' | 'ipc' | 'ignore' | 'inherit' | Stream,
	shell?: boolean,
	prepareProcess?: (proc: ChildProcess) => void,
	dontSearchErrors?: boolean,
	dontShowOutputs?: boolean,
    returnOutputs?: boolean,
}

See examples here

Config

Default config path is ./.run-script-rc.js

Config type:

type TextPredicate = (text: string, next: TextPredicate) => boolean
type ErrorSearch = (text: string, next: ErrorSearch) => string | void | null | false

type IGlobalConfig = {
	logFilter?: TextPredicate,
	stdOutSearchError?: ErrorSearch,
	stdErrIsError?: TextPredicate,
}

See the config example here

License

CC0-1.0