UNPKG

builder-util

Version:

Various utilities. Used by [electron-builder](https://github.com/electron-userland/electron-builder).

75 lines (60 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DebugLogger = void 0; function _fsExtraP() { const data = require("fs-extra-p"); _fsExtraP = function () { return data; }; return data; } function _util() { const data = require("./util"); _util = function () { return data; }; return data; } class DebugLogger { constructor(enabled = true) { this.enabled = enabled; this.data = {}; } add(key, value) { if (!this.enabled) { return; } const dataPath = key.split("."); let o = this.data; let lastName = null; for (const p of dataPath) { if (p === dataPath[dataPath.length - 1]) { lastName = p; break; } else { if (o[p] == null) { o[p] = Object.create(null); } else if (typeof o[p] === "string") { o[p] = [o[p]]; } o = o[p]; } } if (Array.isArray(o[lastName])) { o[lastName].push(value); } else { o[lastName] = value; } } save(file) { // toml and json doesn't correctly output multiline string as multiline if (this.enabled && Object.keys(this.data).length > 0) { return (0, _fsExtraP().outputFile)(file, (0, _util().serializeToYaml)(this.data)); } else { return Promise.resolve(); } } } exports.DebugLogger = DebugLogger; //# sourceMappingURL=DebugLogger.js.map