UNPKG

cli-block

Version:
71 lines 3.37 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.blockSettings = exports.createBlockSettings = void 0; const tools_1 = require("@sil/tools"); const util_1 = require("../util"); const settings_1 = require("../settings"); const blocks_line_1 = require("./blocks.line"); const util_2 = require("../util"); const config_1 = require("../settings/config"); const isExcluded = (exclude, value) => { if (exclude.length == 0) return false; let excluded = false; exclude.forEach((exclude) => { if ((exclude.indexOf("*") > -1 && value.indexOf(exclude.replace("*", "")) > -1) || exclude == value) { excluded = true; } }); return excluded; }; // Auto Settings display const createBlockSettings = (obj, settings = {}, config = null) => __awaiter(void 0, void 0, void 0, function* () { settings = (0, settings_1.useSettings)(settings); config = (0, config_1.useConfig)(config); const settingLines = []; const lines = []; yield (0, tools_1.asyncForEach)(Object.keys(obj), (key) => { let value = (0, util_2.stylizeValue)(obj[key]); let error = false; ["src", "dest", "template"].includes(key) && !obj[key] && (error = true); if (error) value = `${(0, util_1.red)("×")} ${value}`; if (config.include.length > 0) { config.include.includes(key) && settingLines.push(`${(0, util_1.bold)(key)}${(0, util_2.spaces)(20, key)}${value}`); } else if (!isExcluded(config.exclude, key)) { settingLines.push(`${(0, util_1.bold)(key)}${(0, util_2.spaces)(20, key)}${value}`); } }); config.margin && config.marginTop && lines.push((0, blocks_line_1.createBlockLine)(null, settings)[0]); config.header && lines.push((0, blocks_line_1.createBlockLine)([config.header], settings)[0]); settingLines.forEach((line) => { lines.push((0, blocks_line_1.createBlockLine)(line, settings)[0]); }); config.footer && lines.push((0, blocks_line_1.createBlockLine)([config.footer], settings)[0]); config.margin && config.marginBottom && lines.push((0, blocks_line_1.createBlockLine)(null, settings)[0]); return lines; }); exports.createBlockSettings = createBlockSettings; const blockSettings = (obj, settings = {}, config = null) => __awaiter(void 0, void 0, void 0, function* () { const lines = yield (0, exports.createBlockSettings)(obj, settings, config); lines.forEach((line) => (0, util_2.logger)(line, settings)); }); exports.blockSettings = blockSettings; //# sourceMappingURL=blocks.settings.js.map