@goldstack/utils-sh
Advanced tools
Comparing version 0.4.26 to 0.4.27
@@ -32,2 +32,4 @@ import { sync as globSync } from 'glob'; | ||
declare const read: (path: string) => string; | ||
declare const tryRead: (path: string) => string | undefined; | ||
declare const readToType: <T>(path: string) => T | undefined; | ||
declare const write: (content: string, path: string) => void; | ||
@@ -37,3 +39,4 @@ declare const pwd: () => string; | ||
declare const commandExists: (command: string) => boolean; | ||
export { exec, execSafe, pwd, read, write, cd, globSync, commandExists }; | ||
declare const changeExtension: (file: string, extension: string) => string; | ||
export { exec, execSafe, pwd, read, write, cd, globSync, commandExists, readToType, tryRead, changeExtension, }; | ||
//# 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.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; | ||
exports.changeExtension = exports.tryRead = exports.readToType = 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"); | ||
@@ -250,2 +250,19 @@ const fs_1 = __importDefault(require("fs")); | ||
exports.read = read; | ||
const tryRead = (path) => { | ||
let buffer; | ||
try { | ||
buffer = fs_1.default.readFileSync(path, 'utf8'); | ||
} | ||
catch (ex) { } | ||
return buffer === null || buffer === void 0 ? void 0 : buffer.toString(); | ||
}; | ||
exports.tryRead = tryRead; | ||
const readToType = (path) => { | ||
const stringObject = tryRead(path); | ||
let result = undefined; | ||
if (stringObject) | ||
result = JSON.parse(stringObject); | ||
return result; | ||
}; | ||
exports.readToType = readToType; | ||
const write = (content, path) => { | ||
@@ -266,2 +283,9 @@ fs_1.default.writeFileSync(path, content); | ||
exports.commandExists = commandExists; | ||
// https://stackoverflow.com/a/57371333 | ||
const changeExtension = (file, extension) => { | ||
// extension should include the dot, for example '.html' | ||
const basename = path_1.default.basename(file, path_1.default.extname(file)); | ||
return path_1.default.join(path_1.default.dirname(file), basename + extension); | ||
}; | ||
exports.changeExtension = changeExtension; | ||
//# sourceMappingURL=utilsSh.js.map |
{ | ||
"name": "@goldstack/utils-sh", | ||
"version": "0.4.26", | ||
"version": "0.4.27", | ||
"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
29294
372