@4very/strapi-plugin-schemas-to-ts
Version:
A Strapi plugin that automatically generates Typescript interfaces for Strapi entities and components.
53 lines (52 loc) • 2.06 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommonHelpers = void 0;
const prettier_1 = __importDefault(require("prettier"));
const pluginName_1 = require("../models/pluginName");
const schemaSource_1 = require("../models/schemaSource");
const logger_1 = require("./logger");
class CommonHelpers {
constructor(config, strapiRootPath) {
this.config = config;
this.strapiRootPath = strapiRootPath;
this.headerComment = CommonHelpers.headerComment;
this.logger = new logger_1.Logger(config.logLevel);
}
getPrettierOptions() {
if (!this.config.usePrettierIfAvailable) {
return undefined;
}
const prettierConfigFile = prettier_1.default.resolveConfigFile.sync(this.strapiRootPath);
if (prettierConfigFile !== null) {
return prettier_1.default.resolveConfig.sync(prettierConfigFile, { editorconfig: true });
}
}
getFileNameFromSchema(schemaInfo, withExtension) {
let fileName = schemaInfo.source === schemaSource_1.SchemaSource.Api
? schemaInfo.schema.info.singularName
: schemaInfo.pascalName;
if (!!withExtension) {
fileName += '.ts';
}
return fileName;
}
static isWindows() {
return process.platform === 'win32';
}
static capitalizeFirstLetter(text) {
return text.charAt(0).toUpperCase() + text.slice(1);
}
static compareIgnoringLineBreaks(str1, str2) {
function trimLineBreaks(str) {
return str.replaceAll('\n', '').trim();
}
const normalizedStr1 = trimLineBreaks(str1);
const normalizedStr2 = trimLineBreaks(str2);
return normalizedStr1 === normalizedStr2;
}
}
exports.CommonHelpers = CommonHelpers;
CommonHelpers.headerComment = `// Interface automatically generated by ${pluginName_1.pluginName}\n\n`;