UNPKG

@knodes/typedoc-pluginutils

Version:
46 lines 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.writeDiag = exports.Narrow = exports.rootDir = exports.catchWrap = exports.rethrow = void 0; const fs_1 = require("fs"); const lodash_1 = require("lodash"); const path_1 = require("@knodes/typedoc-pluginutils/path"); const rethrow = (block, newErrorFactory) => { try { return block(); } catch (err) { const newErr = newErrorFactory(err); if ((0, lodash_1.isString)(newErr)) { throw new Error(newErr, { cause: err }); } else { throw newErr; } } }; exports.rethrow = rethrow; const catchWrap = (block, contextMessage) => (0, exports.rethrow)(block, err => (0, lodash_1.isFunction)(contextMessage) ? contextMessage(err) : new Error(contextMessage, { cause: err })); exports.catchWrap = catchWrap; exports.rootDir = (0, lodash_1.memoize)((app) => { const opts = app.options.getValue('options'); const stat = (0, fs_1.statSync)(opts); if (stat.isDirectory()) { return opts; } else if (stat.isFile()) { return (0, path_1.dirname)(opts); } else { throw new Error(); } }); const Narrow = (v) => true; exports.Narrow = Narrow; const writeDiag = (diagDir, file, content) => { if (diagDir) { (0, fs_1.mkdirSync)(diagDir, { recursive: true }); (0, fs_1.writeFileSync)((0, path_1.resolve)(diagDir, file), content()); } }; exports.writeDiag = writeDiag; //# sourceMappingURL=misc.js.map