@kontent-ai/model-generator
Version:
This utility generates strongly-typed models for Delivery JS SDK, Migration toolkit or just general scripting to improve the experience when referencing Kontent.ai related objects.
39 lines • 1.36 kB
JavaScript
import { sdkInfo } from "../sdk-info.js";
export function wrapComment(comment, options) {
const nonEmptyLines = options?.lines?.filter((m) => m.value) ?? [];
if (!nonEmptyLines.length) {
return `/*\n* ${toSafeComment(comment)}\n*/`;
}
return `/*
* ${toSafeComment(comment)}
*
${nonEmptyLines.map((m) => `* ${m.name}: ${m.value}`).join("\n")}
*/`;
}
export function toSafeComment(text) {
const replaceContent = "";
return text.replace(/\/\*/g, replaceContent).replace(/\*\//g, replaceContent);
}
export function toGuidelinesComment(guidelines) {
return removeLineEndings(guidelines);
}
export function getEnvironmentInfoComment(data) {
return `
/*
* This file has been auto-generated by '${sdkInfo.name}@${sdkInfo.version}'.
*
* (c) Kontent.ai
*
* -------------------------------------------------------------------------------
*
* Project: ${toSafeComment(data.environmentInfo.name)}
* Environment: ${toSafeComment(data.environmentInfo.environment)}
* Id: ${data.environmentInfo.id}${data.timestampDate ? `\n* Generated: ${data.timestampDate.toLocaleString()}` : ""}
*
* -------------------------------------------------------------------------------
*/`;
}
function removeLineEndings(value) {
return value.replace(/(\r\n|\n|\r)/g, " ");
}
//# sourceMappingURL=comment.utils.js.map