UNPKG

@cto.ai/ops-rc

Version:

💻 CTO.ai Ops - The CLI built for Teams 🚀

35 lines (34 loc) • 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.copyTemplate = exports.customizeManifest = void 0; const tslib_1 = require("tslib"); const yaml = tslib_1.__importStar(require("yaml")); const fs = tslib_1.__importStar(require("fs-extra")); const path = tslib_1.__importStar(require("path")); const CustomErrors_1 = require("./../errors/CustomErrors"); // TODO: get the types somewhere I can use them here exports.customizeManifest = async (kind, metadata, targetPath) => { const manifestPath = path.join(targetPath, 'ops.yml'); const objectPath = [`${kind}s`, 0]; try { const manifestDoc = yaml.parseDocument(await fs.readFile(manifestPath, 'utf8')); manifestDoc .getIn(objectPath) .set('name', `${metadata.name}:${metadata.version}`); manifestDoc.getIn(objectPath).set('description', metadata.description); await fs.writeFile(manifestPath, manifestDoc.toString()); } catch (err) { throw new CustomErrors_1.CouldNotInitializeOp(err); } }; exports.copyTemplate = async (srcDir, destDir) => { try { await fs.ensureDir(destDir); await fs.copy(srcDir, destDir); } catch (err) { console.log('%O', err); throw new CustomErrors_1.CopyTemplateFilesError(err); } };