@cto.ai/ops
Version:
💻 CTO.ai - The CLI built for Teams 🚀
49 lines (48 loc) • 1.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderFile = exports.copyTemplate = exports.customizeManifest = void 0;
const tslib_1 = require("tslib");
const Eta = tslib_1.__importStar(require("eta"));
const fs = tslib_1.__importStar(require("fs-extra"));
const path = tslib_1.__importStar(require("path"));
const yaml = tslib_1.__importStar(require("yaml"));
const CustomErrors_1 = require("./../errors/CustomErrors");
// TODO: get the types somewhere I can use them here
const 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.customizeManifest = customizeManifest;
const copyTemplate = async (srcDir, destDir, options) => {
try {
await fs.ensureDir(destDir);
await fs.copy(srcDir, destDir, options);
}
catch (err) {
console.log('%O', err);
throw new CustomErrors_1.CopyTemplateFilesError(err);
}
};
exports.copyTemplate = copyTemplate;
const renderFile = async (templateFile, destFile, data) => {
try {
const content = await Eta.renderFile(templateFile, data);
await fs.writeFile(destFile, content);
}
catch (err) {
console.log('%O', err);
throw new CustomErrors_1.CopyTemplateFilesError(err);
}
};
exports.renderFile = renderFile;