@clevercanyon/madrun
Advanced tools
Comparing version 1.0.26 to 1.0.27
295
dist/cli.js
@@ -1,16 +0,71 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import { dirname } from "desm"; | ||
import chalk, { supportsColor } from "chalk"; | ||
import yargs from "yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
import { findUpSync } from "find-up"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import { findUpSync, findUp } from "find-up"; | ||
import * as se from "shescape"; | ||
import _ꓺomit from "lodash/omit.js"; | ||
import spawn from "spawn-please"; | ||
import coloredBox from "boxen"; | ||
import spawnPlease from "spawn-please"; | ||
import { execSync } from "node:child_process"; | ||
import coloredBox from "boxen"; | ||
const { error: err$1 } = console; | ||
const echo = process.stdout.write.bind(process.stdout); | ||
const configFilesGlob = ".madrun.{js|cjs|mjs}"; | ||
const propagateUserEnvVars = () => { | ||
process.env.NPM_TOKEN = process.env.USER_NPM_TOKEN || ""; | ||
process.env.GH_TOKEN = process.env.USER_GITHUB_TOKEN || ""; | ||
process.env.GITHUB_TOKEN = process.env.USER_GITHUB_TOKEN || ""; | ||
process.env.CLOUDFLARE_API_TOKEN = process.env.USER_CLOUDFLARE_TOKEN || ""; | ||
}; | ||
const escRegExp = (str) => { | ||
return str.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"); | ||
}; | ||
const exec = async (cmd, opts = {}) => { | ||
return (execSync(cmd, { | ||
cwd: process.cwd(), | ||
shell: "bash", | ||
stdio: "inherit", | ||
env: { | ||
...process.env, | ||
PARENT_IS_TTY: process.stdout.isTTY || // | ||
process.env.PARENT_IS_TTY ? "true" : "false" | ||
}, | ||
...opts | ||
}) || Buffer.from("")).toString(); | ||
}; | ||
const spawn = async (cmd, args = [], opts = {}) => { | ||
if ("shell" in opts ? opts.shell : "bash") { | ||
cmd = se.quote(cmd), args = se.quoteAll(args); | ||
} | ||
return await spawnPlease(cmd, args, { | ||
cwd: process.cwd(), | ||
shell: "bash", | ||
stdio: "inherit", | ||
env: { | ||
...process.env, | ||
PARENT_IS_TTY: process.stdout.isTTY || // | ||
process.env.PARENT_IS_TTY ? "true" : "false" | ||
}, | ||
// Output handlers do not run when `stdio: 'inherit'` or `quiet: true`. | ||
stdout: opts.quiet ? null : (buffer) => echo(chalk.white(buffer.toString())), | ||
stderr: opts.quiet ? null : (buffer) => echo(chalk.gray(buffer.toString())), | ||
..._ꓺomit(opts, ["quiet"]) | ||
}); | ||
}; | ||
const error = async (title, text) => { | ||
if (!process.stdout.isTTY || !supportsColor || !supportsColor?.has16m) { | ||
return chalk.red(text); | ||
} | ||
return "\n" + coloredBox(chalk.bold.red(text), { | ||
margin: 0, | ||
padding: 0.75, | ||
textAlignment: "left", | ||
dimBorder: false, | ||
borderStyle: "round", | ||
borderColor: "#551819", | ||
backgroundColor: "", | ||
titleAlignment: "left", | ||
title: chalk.bold.redBright("⚑ " + title) | ||
}); | ||
}; | ||
const { log } = console; | ||
const configFiles = [".madrun.js", ".madrun.cjs", ".madrun.mjs"]; | ||
@@ -20,3 +75,3 @@ const regexAllCMDArgPartsValues = new RegExp("\\$\\{{1}@\\}{1}|\\{{2}@\\}{2}", "gu"); | ||
const regexpRemainingCMDArgValues = new RegExp("\\$\\{{1}\\s*(?:|[^}]+\\|)(?:[0-9]+|-{1,2}[^|}]+)(?:|\\|[^}]+)\\s*\\}{1}", "gu"); | ||
const omitFromNamedCMDArgs = ["$0", "_", "madrunHelp", "madrun-help", "madrunVersion", "madrun-version", "madrunDebug", "madrun-debug"]; | ||
const omitFromNamedCMDArgs = ["$0", "_", "madrunHelp", "madrunVersion", "madrunDebug"]; | ||
class Run { | ||
@@ -37,13 +92,16 @@ /** | ||
this.configFile = findUpSync(configFiles); | ||
if (!this.configFile) { | ||
throw new Error("`" + configFilesGlob + "` not found!"); | ||
if (this.configFile) { | ||
this.cwd = path.dirname(this.configFile); | ||
} else { | ||
this.cwd = process.cwd(); | ||
this.configFile = "default"; | ||
} | ||
this.cwd = path.dirname(this.configFile); | ||
if (this.args.madrunDebug) { | ||
err$1(chalk.black("> cwd:") + " " + chalk.gray(this.cwd)); | ||
err$1(chalk.black("> args:") + " " + chalk.gray(JSON.stringify(this.args, null, 4))); | ||
err$1(chalk.black("> ---")); | ||
err$1(chalk.black("> cmdName:") + " " + chalk.gray(this.cmdName)); | ||
err$1(chalk.black("> cmdArgs:") + " " + chalk.gray(JSON.stringify(this.cmdArgs, null, 4))); | ||
err$1(chalk.black("> ---")); | ||
log(chalk.black("> cwd:") + " " + chalk.gray(this.cwd)); | ||
log(chalk.black("> configFile:") + " " + chalk.gray(this.configFile)); | ||
log(chalk.black("> args:") + " " + chalk.gray(JSON.stringify(this.args, null, 4))); | ||
log(chalk.black("> ---")); | ||
log(chalk.black("> cmdName:") + " " + chalk.gray(this.cmdName)); | ||
log(chalk.black("> cmdArgs:") + " " + chalk.gray(JSON.stringify(this.cmdArgs, null, 4))); | ||
log(chalk.black("> ---")); | ||
} | ||
@@ -58,11 +116,41 @@ } | ||
for (const cmdData of cmdConfigData.cmds) { | ||
const cmd = await this.populateCMD(cmdData.env, cmdData.cmd); | ||
if (this.args.madrunDebug) { | ||
err$1(chalk.black("> rawEnv:") + " " + chalk.gray(JSON.stringify(cmdData.env, null, 4))); | ||
err$1(chalk.black("> rawCMD:") + " " + chalk.gray(cmdData.cmd)); | ||
err$1(chalk.black("> rawOpts:") + " " + chalk.gray(JSON.stringify(cmdData.opts, null, 4))); | ||
err$1(chalk.black("> cmd:") + " " + chalk.gray(cmd)); | ||
err$1(chalk.black("> ---")); | ||
if (typeof cmdData.cmd === "function") { | ||
if (this.args.madrunDebug) { | ||
log(chalk.black("> rawEnv:") + " " + chalk.gray(JSON.stringify(cmdData.env, null, 4))); | ||
log(chalk.black("> rawCMD:") + " " + chalk.gray("[function]")); | ||
log(chalk.black("> rawOpts:") + " " + chalk.gray(JSON.stringify(cmdData.opts, null, 4))); | ||
log(chalk.black("> ---")); | ||
} | ||
const ctxUtils = { | ||
cwd: this.cwd, | ||
// CWD. | ||
se, | ||
// Shell escape|quote. | ||
chalk, | ||
// Chalk string colorizer. | ||
env: cmdData.env, | ||
// Env vars for CMD. | ||
opts: cmdData.opts, | ||
// Options for CMD. | ||
exec, | ||
// Exec utility. | ||
spawn, | ||
// Spawn utility. | ||
findUp, | ||
// findUp utility. | ||
configFiles | ||
// Config files array. | ||
}; | ||
await cmdData.cmd(this.cmdArgs, ctxUtils); | ||
} else { | ||
const cmd = await this.populateCMD(cmdData.env, cmdData.cmd); | ||
if (this.args.madrunDebug) { | ||
log(chalk.black("> rawEnv:") + " " + chalk.gray(JSON.stringify(cmdData.env, null, 4))); | ||
log(chalk.black("> rawCMD:") + " " + chalk.gray(cmdData.cmd)); | ||
log(chalk.black("> rawOpts:") + " " + chalk.gray(JSON.stringify(cmdData.opts, null, 4))); | ||
log(chalk.black("> cmd:") + " " + chalk.gray(cmd)); | ||
log(chalk.black("> ---")); | ||
} | ||
await exec(cmd, { cwd: this.cwd, ...cmdData.opts }); | ||
} | ||
await this.exec(cmd, cmdData.opts); | ||
} | ||
@@ -74,5 +162,5 @@ } | ||
async maybeInstallNodeModules() { | ||
const pkgFile2 = path.resolve(this.cwd, "./package.json"); | ||
const pkgFile = path.resolve(this.cwd, "./package.json"); | ||
const nodeModulesDir = path.resolve(this.cwd, "./node_modules"); | ||
if (!fs.existsSync(pkgFile2) || fs.existsSync(nodeModulesDir)) { | ||
if (!fs.existsSync(pkgFile) || fs.existsSync(nodeModulesDir)) { | ||
return; | ||
@@ -83,57 +171,8 @@ } | ||
if (this.args.madrunDebug) { | ||
err$1(chalk.black("> Auto-installing node modules.")); | ||
err$1(chalk.black("> ---")); | ||
log(chalk.black("> Auto-installing node modules.")); | ||
log(chalk.black("> ---")); | ||
} | ||
await this.spawn("npm", fs.existsSync(pkgLockFile) || fs.existsSync(npmShrinkwrapFile) ? ["ci"] : ["install"]); | ||
await spawn("npm", fs.existsSync(pkgLockFile) || fs.existsSync(npmShrinkwrapFile) ? ["ci"] : ["install"], { cwd: this.cwd }); | ||
} | ||
/** | ||
* Executes command line operation. | ||
* | ||
* @param cmd CMD + any args, or shell script to run. | ||
* @param opts Any additional execSync options. | ||
* | ||
* @returns Empty string when `stdio: 'inherit'` (default). Stdout when `stdio: 'pipe'`. | ||
*/ | ||
async exec(cmd, opts = {}) { | ||
return (execSync(cmd, { | ||
cwd: this.cwd, | ||
shell: "bash", | ||
stdio: "inherit", | ||
env: { | ||
...process.env, | ||
PARENT_IS_TTY: process.stdout.isTTY || // | ||
process.env.PARENT_IS_TTY ? "true" : "false" | ||
}, | ||
...opts | ||
}) || Buffer.from("")).toString(); | ||
} | ||
/** | ||
* Spawns command line operation. | ||
* | ||
* @param cmd CMD name or path. | ||
* @param args Any CMD arguments. | ||
* @param opts Any additional spawn options. | ||
* | ||
* @returns Empty string when `stdio: 'inherit'` (default). Stdout when `stdio: 'pipe'`. | ||
*/ | ||
async spawn(cmd, args = [], opts = {}) { | ||
if ("shell" in opts ? opts.shell : "bash") { | ||
cmd = se.quote(cmd), args = se.quoteAll(args); | ||
} | ||
return await spawn(cmd, args, { | ||
cwd: this.cwd, | ||
shell: "bash", | ||
stdio: "inherit", | ||
env: { | ||
...process.env, | ||
PARENT_IS_TTY: process.stdout.isTTY || // | ||
process.env.PARENT_IS_TTY ? "true" : "false" | ||
}, | ||
// Output handlers do not run when `stdio: 'inherit'` or `quiet: true`. | ||
stdout: opts.quiet ? null : (buffer) => echo(chalk.white(buffer.toString())), | ||
stderr: opts.quiet ? null : (buffer) => echo(chalk.gray(buffer.toString())), | ||
..._ꓺomit(opts, ["quiet"]) | ||
}); | ||
} | ||
/** | ||
* Parses config file. | ||
@@ -144,4 +183,9 @@ * | ||
async config() { | ||
let config = null; | ||
const configFile = this.configFile; | ||
const config = (await import(configFile)).default; | ||
if ("default" === this.configFile) { | ||
config = (await import("./default.js")).default; | ||
} else { | ||
config = (await import(configFile)).default; | ||
} | ||
if (typeof config !== "object") { | ||
@@ -155,3 +199,3 @@ throw new Error("`" + path.basename(configFile) + "` config failure."); | ||
* | ||
* @returns CMD config function. | ||
* @returns CMD config function; else `null` if CMD is unavailable. | ||
*/ | ||
@@ -161,2 +205,5 @@ async cmdConfigFn() { | ||
let configFn = config[this.cmdName] || null; | ||
if (null === configFn && this.cmdName.startsWith("on::")) { | ||
return null; | ||
} | ||
if (typeof configFn === "string") { | ||
@@ -168,3 +215,3 @@ configFn = async () => configFn; | ||
if (typeof cmd !== "string") { | ||
throw new Error("`" + this.cmdName + "` command is not available."); | ||
throw new Error("`" + this.cmdName + "` command has an invalid data type."); | ||
} | ||
@@ -174,7 +221,11 @@ return cmd; | ||
} | ||
if (null === configFn) { | ||
throw new Error("`" + this.cmdName + "` command is unavailable."); | ||
} | ||
if (typeof configFn !== "function") { | ||
throw new Error("`" + this.cmdName + "` command is not available."); | ||
throw new Error("`" + this.cmdName + "` command has an invalid data type."); | ||
} | ||
if (configFn.constructor.name !== "AsyncFunction") { | ||
configFn = async (...args) => configFn(...args); | ||
const configFnSync = configFn.bind({}); | ||
configFn = async (...args) => configFnSync(...args); | ||
} | ||
@@ -198,5 +249,11 @@ return configFn; | ||
const configFn = await this.cmdConfigFn(); | ||
if (null === configFn && this.cmdName.startsWith("on::")) { | ||
return { env: {}, cmds: [], opts: {} }; | ||
} else if (null === configFn) { | ||
throw new Error("`" + this.cmdName + "` command is unavailable."); | ||
} | ||
let configFnRtn = await configFn(this.cmdArgs, ctxUtils); | ||
configFnRtn = configFnRtn instanceof Array ? { cmds: configFnRtn } : configFnRtn; | ||
configFnRtn = typeof configFnRtn === "function" ? { cmds: [configFnRtn] } : configFnRtn; | ||
configFnRtn = typeof configFnRtn === "string" ? { cmds: "" === configFnRtn ? [] : [configFnRtn] } : configFnRtn; | ||
configFnRtn = configFnRtn instanceof Array ? { cmds: configFnRtn } : configFnRtn; | ||
if (typeof configFnRtn !== "object") { | ||
@@ -206,2 +263,3 @@ throw new Error("`" + this.cmdName + "` command config has an invalid data type."); | ||
configFnRtn = Object.assign({ env: {}, cmds: [], opts: {} }, configFnRtn); | ||
configFnRtn.cmds = typeof configFnRtn.cmds === "function" ? [configFnRtn.cmds] : configFnRtn.cmds; | ||
configFnRtn.cmds = typeof configFnRtn.cmds === "string" ? "" === configFnRtn.cmds ? [] : [configFnRtn.cmds] : configFnRtn.cmds; | ||
@@ -220,2 +278,3 @@ if (typeof configFnRtn.env !== "object") { | ||
cmdData = typeof cmdData === "string" ? { cmd: cmdData } : cmdData; | ||
cmdData = typeof cmdData === "function" ? { cmd: cmdData } : cmdData; | ||
if (typeof cmdData !== "object") { | ||
@@ -229,5 +288,9 @@ throw new Error("`" + this.cmdName + "` command config contains a CMD with an invalid data type."); | ||
} | ||
if (typeof cmdData.cmd !== "string" || !cmdData.cmd) { | ||
if (typeof cmdData.cmd !== "string" && typeof cmdData.cmd !== "function" || !cmdData.cmd) { | ||
throw new Error("`" + this.cmdName + "` command config contains a CMD with invalid data for its derived `cmd` property."); | ||
} | ||
if (typeof cmdData.cmd === "function" && cmdData.cmd.constructor.name !== "AsyncFunction") { | ||
const cmdFnSync = cmdData.cmd.bind({}); | ||
cmdData.cmd = async (...args) => cmdFnSync(...args); | ||
} | ||
if (typeof cmdData.opts !== "object") { | ||
@@ -276,3 +339,3 @@ throw new Error("`" + this.cmdName + "` command config contains a CMD with invalid data for its derived `opts` property."); | ||
const pos = String(i + 1); | ||
const escREPos = this.escRegExp(pos); | ||
const escREPos = escRegExp(pos); | ||
const argValue = se.quote(String(v)); | ||
@@ -284,6 +347,9 @@ const regExpArgParts = new RegExp("\\{{2}\\s*(?:|[^}]+\\|)" + escREPos + "(?:|\\|[^}]+)\\s*\\}{2}", "gu"); | ||
for (const [n, v] of Object.entries(_ꓺomit(this.cmdArgs, omitFromNamedCMDArgs))) { | ||
if (typeof v === "boolean" && false === v) { | ||
continue; | ||
} | ||
const prefix = "-".repeat(1 === n.length ? 1 : 2); | ||
const escREName = this.escRegExp(prefix + n); | ||
const argParts = se.quote(prefix + n) + (true === v ? "" : " " + se.quote(String(v))); | ||
const argValue = true === v ? "" : se.quote(String(v)); | ||
const escREName = escRegExp(prefix + n); | ||
const argValue = typeof v === "boolean" ? "" : se.quote(String(v)); | ||
const argParts = se.quote(prefix + n) + (argValue.length ? " " + argValue : ""); | ||
cmd = cmd.replace(new RegExp("\\{{2}\\s*(?:|[^}]+\\|)" + escREName + "(?:|\\|[^}]+)\\s*\\}{2}", "gu"), argParts); | ||
@@ -298,6 +364,9 @@ cmd = cmd.replace(new RegExp("\\$\\{{1}\\s*(?:|[^}]+\\|)" + escREName + "(?:|\\|[^}]+)\\s*\\}{1}", "gu"), argValue); | ||
for (const [n, v] of Object.entries(_ꓺomit(this.cmdArgs, omitFromNamedCMDArgs))) { | ||
if (typeof v === "boolean" && false === v) { | ||
continue; | ||
} | ||
const prefix = "-".repeat(1 === n.length ? 1 : 2); | ||
const name = prefix + n; | ||
args.push(name); | ||
true === v ? null : args.push(String(v)); | ||
typeof v === "boolean" ? null : args.push(String(v)); | ||
} | ||
@@ -309,37 +378,13 @@ return se.quoteAll(args).join(" "); | ||
} | ||
/** | ||
* Escapes a string for use in a regular expression. | ||
* | ||
* @returns Escaped string for use in a regular expression. | ||
*/ | ||
escRegExp(str) { | ||
return str.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"); | ||
} | ||
} | ||
const error = async (title, text) => { | ||
if (!process.stdout.isTTY || !supportsColor || !supportsColor?.has16m) { | ||
return chalk.red(text); | ||
} | ||
return "\n" + coloredBox(chalk.bold.red(text), { | ||
margin: 0, | ||
padding: 0.75, | ||
textAlignment: "left", | ||
dimBorder: false, | ||
borderStyle: "round", | ||
borderColor: "#551819", | ||
backgroundColor: "", | ||
titleAlignment: "left", | ||
title: chalk.bold.redBright("⚑ " + title) | ||
}); | ||
}; | ||
const __dirname = dirname(import.meta.url); | ||
const projDir = path.resolve(__dirname, ".."); | ||
const pkgFile = path.resolve(projDir, "./package.json"); | ||
const pkg = JSON.parse(fs.readFileSync(pkgFile).toString()); | ||
if (typeof pkg !== "object") { | ||
throw new Error("Failed to parse `./package.json`."); | ||
} | ||
propagateUserEnvVars(); | ||
const { error: err } = console; | ||
void (async () => { | ||
await yargs(hideBin(process.argv)).command({ | ||
await yargs(hideBin(process.argv)).parserConfiguration({ | ||
"dot-notation": false, | ||
"strip-aliased": true, | ||
"strip-dashed": true, | ||
"greedy-arrays": true, | ||
"boolean-negation": false | ||
}).command({ | ||
command: ["$0"], | ||
@@ -368,3 +413,3 @@ describe: "Runs one or more commands configured by a mad JS file; in sequence.", | ||
process.exit(1); | ||
}).help("madrunHelp").version("madrunVersion", pkg.version).parse(); | ||
}).help("madrunHelp").version("madrunVersion", "1.0.27").parse(); | ||
})(); |
@@ -5,4 +5,13 @@ { | ||
"src": "cli.ts", | ||
"isEntry": true | ||
"isEntry": true, | ||
"dynamicImports": [ | ||
"default.ts" | ||
] | ||
}, | ||
"default.ts": { | ||
"file": "default.cjs", | ||
"src": "default.ts", | ||
"isEntry": true, | ||
"isDynamicEntry": true | ||
}, | ||
"index.ts": { | ||
@@ -9,0 +18,0 @@ "file": "index.cjs", |
{ | ||
"resources/cli/utilities.ts": [], | ||
"resources/cli/cmds/run.ts": [], | ||
"resources/cli/utilities.ts": [], | ||
"cli.ts": [], | ||
"default.ts": [], | ||
"index.ts": [] | ||
} |
@@ -6,5 +6,8 @@ #!/usr/bin/env node | ||
/// <reference types="@types/yargs" /> | ||
import { findUp } from 'find-up'; | ||
import chalk from 'chalk'; | ||
import * as se from 'shescape'; | ||
import * as u from '../utilities.js'; | ||
import type { Arguments as YargsꓺArgs } from 'yargs'; | ||
declare const configFiles: string[]; | ||
/** | ||
@@ -14,5 +17,5 @@ * Interfaces. | ||
export type Args = YargsꓺArgs<{ | ||
madrunDebug: boolean; | ||
madrunHelp: boolean; | ||
madrunVersion: boolean; | ||
madrunDebug: boolean; | ||
}>; | ||
@@ -26,8 +29,8 @@ export interface Env { | ||
export interface Config { | ||
[x: string]: string | string[] | CMDConfigFn; | ||
[x: string]: string | string[] | CMDConfigFn | CMDConfigFnSync; | ||
} | ||
export type CMDConfigFn = (cmdArgs: CMDConfigFnCMDArgs, ctxUtils: CMDConfigFnCTXUtils) => Promise<CMDConfigFnRtns>; | ||
export type CMDConfigFnSync = (cmdArgs: CMDConfigFnCMDArgs, ctxUtils: CMDConfigFnCTXUtils) => CMDConfigFnRtns; | ||
export type CMDConfigFnCMDArgs = Omit<YargsꓺArgs<Args>, '$0'>; | ||
export interface CMDConfigFnCTXUtils { | ||
export type CMDConfigFn = (cmdArgs: CMDConfigFnCMDArgs, ctxUtils: CMDConfigFnCtxUtils) => Promise<CMDConfigFnRtns>; | ||
export type CMDConfigFnSync = (cmdArgs: CMDConfigFnCMDArgs, ctxUtils: CMDConfigFnCtxUtils) => CMDConfigFnRtns; | ||
export type CMDConfigFnCMDArgs = Omit<Args, '$0' | 'madrunHelp' | 'madrunVersion' | 'madrunDebug'>; | ||
export interface CMDConfigFnCtxUtils { | ||
cwd: string; | ||
@@ -37,3 +40,3 @@ se: typeof se; | ||
} | ||
export type CMDConfigFnRtns = string | string[] | { | ||
export type CMDConfigFnRtns = string | CMDFn | CMDFnSync | Array<string | CMDFn | CMDFnSync> | { | ||
env?: Env; | ||
@@ -43,7 +46,21 @@ cmds: CMDConfigFnRtnObjCMDs; | ||
}; | ||
export type CMDConfigFnRtnObjCMDs = string | Array<string | { | ||
export type CMDConfigFnRtnObjCMDs = string | CMDFn | CMDFnSync | Array<string | CMDFn | CMDFnSync | { | ||
env?: Env; | ||
cmd: string; | ||
cmd: string | CMDFn | CMDFnSync; | ||
opts?: Opts; | ||
}>; | ||
export type CMDFn = (cmdArgs: CMDFnArgs, ctxUtils: CMDFnCtxUtils) => Promise<void>; | ||
export type CMDFnSync = (cmdArgs: CMDFnArgs, ctxUtils: CMDFnCtxUtils) => void; | ||
export type CMDFnArgs = Omit<Args, '$0' | 'madrunHelp' | 'madrunVersion' | 'madrunDebug'>; | ||
export interface CMDFnCtxUtils { | ||
cwd: string; | ||
se: typeof se; | ||
chalk: typeof chalk; | ||
env: Env; | ||
opts: Opts; | ||
exec: typeof u.exec; | ||
spawn: typeof u.spawn; | ||
findUp: typeof findUp; | ||
configFiles: typeof configFiles; | ||
} | ||
export interface CMDConfigData { | ||
@@ -53,3 +70,3 @@ env: Env; | ||
env: Env; | ||
cmd: string; | ||
cmd: string | CMDFn; | ||
opts: Opts; | ||
@@ -96,25 +113,2 @@ }>; | ||
/** | ||
* Executes command line operation. | ||
* | ||
* @param cmd CMD + any args, or shell script to run. | ||
* @param opts Any additional execSync options. | ||
* | ||
* @returns Empty string when `stdio: 'inherit'` (default). Stdout when `stdio: 'pipe'`. | ||
*/ | ||
protected exec(cmd: string, opts?: { | ||
[x: string]: unknown; | ||
}): Promise<string>; | ||
/** | ||
* Spawns command line operation. | ||
* | ||
* @param cmd CMD name or path. | ||
* @param args Any CMD arguments. | ||
* @param opts Any additional spawn options. | ||
* | ||
* @returns Empty string when `stdio: 'inherit'` (default). Stdout when `stdio: 'pipe'`. | ||
*/ | ||
protected spawn(cmd: string, args?: string[], opts?: { | ||
[x: string]: unknown; | ||
}): Promise<string>; | ||
/** | ||
* Parses config file. | ||
@@ -128,5 +122,5 @@ * | ||
* | ||
* @returns CMD config function. | ||
* @returns CMD config function; else `null` if CMD is unavailable. | ||
*/ | ||
protected cmdConfigFn(): Promise<CMDConfigFn>; | ||
protected cmdConfigFn(): Promise<CMDConfigFn | null>; | ||
/** | ||
@@ -163,8 +157,3 @@ * Gets config data for current `cmdName`. | ||
protected populateCMDReplacementCodes(cmd: string): Promise<string>; | ||
/** | ||
* Escapes a string for use in a regular expression. | ||
* | ||
* @returns Escaped string for use in a regular expression. | ||
*/ | ||
protected escRegExp(str: string): string; | ||
} | ||
export {}; |
@@ -6,2 +6,35 @@ #!/usr/bin/env node | ||
/** | ||
* Propagates user environment variables. | ||
*/ | ||
export declare const propagateUserEnvVars: () => void; | ||
/** | ||
* Escapes a string for use in a regular expression. | ||
* | ||
* @returns Escaped string for use in a regular expression. | ||
*/ | ||
export declare const escRegExp: (str: string) => string; | ||
/** | ||
* Executes command line operation. | ||
* | ||
* @param cmd CMD + any args, or shell script to run. | ||
* @param opts Any additional execSync options. | ||
* | ||
* @returns Empty string when `stdio: 'inherit'` (default). Stdout when `stdio: 'pipe'`. | ||
*/ | ||
export declare const exec: (cmd: string, opts?: { | ||
[x: string]: unknown; | ||
}) => Promise<string>; | ||
/** | ||
* Spawns command line operation. | ||
* | ||
* @param cmd CMD name or path. | ||
* @param args Any CMD arguments. | ||
* @param opts Any additional spawn options. | ||
* | ||
* @returns Empty string when `stdio: 'inherit'` (default). Stdout when `stdio: 'pipe'`. | ||
*/ | ||
export declare const spawn: (cmd: string, args?: string[], opts?: { | ||
[x: string]: unknown; | ||
}) => Promise<string>; | ||
/** | ||
* Outputs CLI error. | ||
@@ -8,0 +41,0 @@ * |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "1.0.26", | ||
"version": "1.0.27", | ||
"license": "GPL-3.0-or-later", | ||
@@ -37,2 +37,7 @@ "name": "@clevercanyon/madrun", | ||
"types": "./dist/types/cli.d.ts" | ||
}, | ||
"./default": { | ||
"import": "./dist/default.js", | ||
"require": "./dist/default.cjs", | ||
"types": "./dist/types/default.d.ts" | ||
} | ||
@@ -57,4 +62,4 @@ }, | ||
"lodash": "^4.17.21", | ||
"shescape": "npm:@clevercanyon/shescape.fork@^1.6.6", | ||
"spawn-please": "npm:@clevercanyon/spawn-please.fork@^2.0.4", | ||
"shescape": "npm:@clevercanyon/shescape.fork@^1.6.7", | ||
"spawn-please": "npm:@clevercanyon/spawn-please.fork@^2.0.5", | ||
"yargs": "^17.6.2" | ||
@@ -61,0 +66,0 @@ }, |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 7 instances in 1 package
80618
18
1174
25