Sort Generated Content-Types and Components Definitions (#21868)

This commit is contained in:
Jean-Sébastien Herbaux 2024-10-17 10:04:52 +02:00 committed by GitHub
parent c823b10e98
commit c23fb8e09d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 15 deletions

View File

@ -18,9 +18,9 @@ module.exports = {
},
generateImportDefinition() {
const formattedImports = imports.map((key) =>
factory.createImportSpecifier(false, undefined, factory.createIdentifier(key))
);
const formattedImports = imports
.sort()
.map((key) => factory.createImportSpecifier(false, undefined, factory.createIdentifier(key)));
return [
factory.createImportDeclaration(

View File

@ -22,9 +22,11 @@ const { addImport } = require('../imports');
const generateAttributePropertySignature = (schema) => {
const { attributes } = schema;
const properties = Object.entries(attributes).map(([attributeName, attribute]) => {
return attributeToPropertySignature(schema, attributeName, attribute);
});
const properties = Object.entries(attributes)
.sort((a, b) => a[0].localeCompare(b[0]))
.map(([attributeName, attribute]) => {
return attributeToPropertySignature(schema, attributeName, attribute);
});
return factory.createPropertySignature(
undefined,

View File

@ -111,7 +111,7 @@ const toTypeLiteral = (data) => {
throw new Error(`Cannot convert to object literal. Unknown type "${typeof data}"`);
}
const entries = Object.entries(data);
const entries = Object.entries(data).sort((a, b) => a[0].localeCompare(b[0]));
const props = entries.reduce((acc, [key, value]) => {
// Handle keys such as content-type-builder & co.

View File

@ -1,6 +1,7 @@
'use strict';
const { factory } = require('typescript');
const { pipe, values, sortBy, map } = require('lodash/fp');
const { models } = require('../common');
const { emitDefinitions, format, generateSharedExtensionDefinition } = require('../utils');
@ -23,10 +24,14 @@ const generateComponentsDefinitions = async (options = {}) => {
const { components } = strapi;
const componentsDefinitions = Object.values(components).map((contentType) => ({
uid: contentType.uid,
definition: models.schema.generateSchemaDefinition(contentType),
}));
const componentsDefinitions = pipe(
values,
sortBy('uid'),
map((component) => ({
uid: component.uid,
definition: models.schema.generateSchemaDefinition(component),
}))
)(components);
options.logger.debug(`Found ${componentsDefinitions.length} components.`);

View File

@ -1,6 +1,7 @@
'use strict';
const { factory } = require('typescript');
const { values, pipe, map, sortBy } = require('lodash/fp');
const { models } = require('../common');
const { emitDefinitions, format, generateSharedExtensionDefinition } = require('../utils');
@ -23,10 +24,14 @@ const generateContentTypesDefinitions = async (options = {}) => {
const { contentTypes } = strapi;
const contentTypesDefinitions = Object.values(contentTypes).map((contentType) => ({
uid: contentType.uid,
definition: models.schema.generateSchemaDefinition(contentType),
}));
const contentTypesDefinitions = pipe(
values,
sortBy('uid'),
map((contentType) => ({
uid: contentType.uid,
definition: models.schema.generateSchemaDefinition(contentType),
}))
)(contentTypes);
options.logger.debug(`Found ${contentTypesDefinitions.length} content-types.`);