@clevercanyon/madrun
Advanced tools
Comparing version 1.0.13 to 1.0.14
46
cli.js
@@ -7,2 +7,4 @@ #!/usr/bin/env node | ||
import _ꓺomit from 'lodash/omit.js'; | ||
import fs from 'node:fs'; | ||
@@ -14,3 +16,4 @@ import path from 'node:path'; | ||
import * as se from 'shescape'; | ||
import _ꓺomit from 'lodash/omit.js'; | ||
import spawn from 'spawn-please'; | ||
import { execSync } from 'node:child_process'; | ||
@@ -22,6 +25,4 @@ import coloredBox from 'boxen'; | ||
import { hideBin } from 'yargs/helpers'; | ||
import { execSync } from 'node:child_process'; | ||
const __dirname = dirname(import.meta.url); | ||
const pkgFile = path.resolve(__dirname, './package.json'); | ||
@@ -112,7 +113,7 @@ const pkg = JSON.parse(fs.readFileSync(pkgFile).toString()); | ||
} | ||
await this.exec(fs.existsSync(pkgLockFile) || fs.existsSync(npmShrinkwrapFile) ? 'npm ci' : 'npm install'); | ||
await this.spawn('npm', fs.existsSync(pkgLockFile) || fs.existsSync(npmShrinkwrapFile) ? ['ci'] : ['install']); | ||
} | ||
/** | ||
* Executes command line operation(s). | ||
* Executes command line operation. | ||
* | ||
@@ -122,9 +123,38 @@ * @param {string} cmd CMD + any args. | ||
* | ||
* @returns {Promise<string>} Command output. | ||
* @returns {Promise<string>} Empty string when `stdio: 'inherit'` (default). Stdout when `stdio: 'pipe'`. | ||
*/ | ||
async exec(cmd, opts = {}) { | ||
return execSync(cmd, { | ||
return ( | ||
execSync(cmd, { | ||
cwd: this.cwd, | ||
shell: 'bash', | ||
stdio: 'inherit', | ||
encoding: 'utf-8', | ||
env: { | ||
...process.env, | ||
PARENT_IS_TTY: | ||
process.stdout.isTTY || // | ||
process.env.PARENT_IS_TTY | ||
? true | ||
: false, | ||
}, | ||
...opts, | ||
}) || '' | ||
); | ||
} | ||
/** | ||
* Spawns command line operation. | ||
* | ||
* @param {string} cmd CMD. | ||
* @param {string[]} args Arguments. | ||
* @param {object} opts Any additional options. | ||
* | ||
* @returns {Promise<string>} Empty string when `stdio: 'inherit'` (default). Stdout when `stdio: 'pipe'`. | ||
*/ | ||
async spawn(cmd, args = [], opts = {}) { | ||
return await spawn(cmd, args, { | ||
cwd: this.cwd, | ||
stdio: [0, 1, 2], | ||
shell: 'bash', | ||
stdio: 'inherit', | ||
env: { | ||
@@ -131,0 +161,0 @@ ...process.env, |
@@ -7,3 +7,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"name": "@clevercanyon/madrun", | ||
@@ -41,4 +41,5 @@ "description": "Runs commands configured by a JS file; in sequence.", | ||
"shescape": "npm:@clevercanyon/shescape.fork@^1.6.4", | ||
"spawn-please": "npm:@clevercanyon/spawn-please.fork@^2.0.2", | ||
"yargs": "^17.6.2" | ||
} | ||
} |
12119
316
8
5
+ Addedspawn-please@npm:@clevercanyon/spawn-please.fork@^2.0.2
+ Added@clevercanyon/spawn-please.fork@2.0.141(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)