@goldstack/utils-sh
Advanced tools
@@ -29,2 +29,3 @@ import { sync as globSync } from 'glob'; | ||
declare const exec: (cmd: string, params?: ExecParams | undefined) => string; | ||
declare const execSafe: (file: string, args: string[], params?: ExecParams | undefined) => string; | ||
export declare const execAsync: (cmd: string, params?: ExecParams | undefined) => Promise<string>; | ||
@@ -36,3 +37,3 @@ declare const read: (path: string) => string; | ||
declare const commandExists: (command: string) => boolean; | ||
export { exec, pwd, read, write, cd, globSync, commandExists }; | ||
export { exec, execSafe, pwd, read, write, cd, globSync, commandExists }; | ||
//# sourceMappingURL=utilsSh.d.ts.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.commandExists = exports.globSync = exports.cd = exports.write = exports.read = exports.pwd = exports.exec = exports.execAsync = exports.tempDir = exports.unzip = exports.zip = exports.mkdir = exports.rm = exports.rmSafe = exports.cp = exports.assertDirectoryExists = exports.assertFileExists = exports.copy = void 0; | ||
exports.commandExists = exports.globSync = exports.cd = exports.write = exports.read = exports.pwd = exports.execSafe = exports.exec = exports.execAsync = exports.tempDir = exports.unzip = exports.zip = exports.mkdir = exports.rm = exports.rmSafe = exports.cp = exports.assertDirectoryExists = exports.assertFileExists = exports.copy = void 0; | ||
const child_process_1 = require("child_process"); | ||
@@ -206,2 +206,22 @@ const fs_1 = __importDefault(require("fs")); | ||
exports.exec = exec; | ||
const execSafe = (file, args, params) => { | ||
try { | ||
const res = (0, child_process_1.execFileSync)(file, args); | ||
if (!(params === null || params === void 0 ? void 0 : params.silent)) { | ||
console.log(res.toString()); | ||
} | ||
return res.toString(); | ||
} | ||
catch (e) { | ||
console.error('Command failed:', file, args); | ||
if (e.stderr) { | ||
console.error(e.stderr.toString()); | ||
} | ||
if (e.stdout) { | ||
console.log(e.stdout.toString()); | ||
} | ||
throw e; | ||
} | ||
}; | ||
exports.execSafe = execSafe; | ||
const execAsync = async (cmd, params) => { | ||
@@ -208,0 +228,0 @@ return new Promise((resolve, reject) => { |
{ | ||
"name": "@goldstack/utils-sh", | ||
"version": "0.4.25", | ||
"version": "0.4.26", | ||
"description": "Utilities for working with files and folders in a bash like manner", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
27215
5.48%345
6.48%