UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

29 lines (28 loc) 1.14 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.editAsFile = void 0; const tmp_promise_1 = require("tmp-promise"); const yaml_1 = require("yaml"); const fs_extra_1 = require("fs-extra"); const getEditor_1 = __importDefault(require("./getEditor")); const editAsFile = async (inObject, preamble) => { const fullPreamble = preamble ? `# # ${preamble.split("\n").join("\n# ")} # ` : "\n"; const asString = fullPreamble + (0, yaml_1.stringify)(inObject, { aliasDuplicateObjects: false }); let newContent; await (0, tmp_promise_1.withFile)(async ({ path: tmpFilePath }) => { await (0, fs_extra_1.writeFile)(tmpFilePath, asString); await (await (0, getEditor_1.default)()).open(tmpFilePath); newContent = (0, yaml_1.parse)((await (0, fs_extra_1.readFile)(tmpFilePath)).toString("utf-8")); }, { postfix: ".yml" }); return newContent; }; exports.editAsFile = editAsFile; //# sourceMappingURL=editAsFile.js.map