@nullcc/diff2html-cli
Version:
Fast Diff to colorized HTML
58 lines • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var childProcess = require("child_process");
var fs = require("fs");
var path = require("path");
function exists(filePath) {
try {
return fs.existsSync(filePath);
}
catch (ignore) {
return false;
}
}
exports.exists = exists;
function readFile(filePath) {
var _filePath = exports.resolveFilePath(filePath);
return fs.readFileSync(_filePath, "utf8");
}
exports.readFile = readFile;
exports.resolveFilePath = function (filePath) {
if (filePath.length === 0) {
return filePath;
}
if (filePath[0] === "~") {
return path.join(process.env.HOME, filePath.slice(1));
}
return filePath;
};
function readStdin() {
return new Promise(function (resolve) {
var content = "";
process.stdin.resume();
process.stdin.on("data", function (buf) {
content += buf.toString("utf8");
});
process.stdin.on("end", function () { return resolve(content); });
});
}
exports.readStdin = readStdin;
function writeFile(filePath, content) {
return fs.writeFileSync(filePath, content);
}
exports.writeFile = writeFile;
function appendFileSync(filePath, content) {
return fs.appendFileSync(filePath, content);
}
exports.appendFileSync = appendFileSync;
function execute(cmd) {
return childProcess.execSync(cmd).toString("utf8");
}
exports.execute = execute;
function removeFile(filePath) {
if (fs.existsSync(filePath)) {
return fs.unlinkSync(filePath);
}
}
exports.removeFile = removeFile;
//# sourceMappingURL=utils.js.map