UNPKG

@salilvnair/jsxpa

Version:
39 lines (38 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var FsCommonUtil = /** @class */ (function () { function FsCommonUtil(jsxElectronUtil) { this.jsxElectronUtil = jsxElectronUtil; this.path = this.jsxElectronUtil.remote.require('path'); this.fs = this.jsxElectronUtil.remote.require('fs'); } FsCommonUtil.prototype.writeFileIfNotExist = function (fileWithPath, contents) { if (!this.fs.existsSync(fileWithPath)) { var options = options || {}; options.flag = "wx"; this.fs.writeFileSync(fileWithPath, contents, options); } }; FsCommonUtil.prototype.checkAndCreateDestinationPath = function (fileDestination) { this._forceCreateDir(fileDestination); }; FsCommonUtil.prototype._forceCreateDir = function (dir) { if (this.fs.existsSync(dir)) { return; } try { this.fs.mkdirSync(dir); } catch (err) { if ((err + '').indexOf('ENOENT') > -1) { this._forceCreateDir(this.path.dirname(dir)); //create parent dir this._forceCreateDir(dir); //create dir } } }; FsCommonUtil.prototype.readFileAsJson = function (jsonPath) { return JSON.parse(this.fs.readFileSync(jsonPath, "utf8")); }; return FsCommonUtil; }()); exports.FsCommonUtil = FsCommonUtil;