mirror of
https://github.com/strapi/strapi.git
synced 2025-10-27 08:02:56 +00:00
Sort Generated Content-Types and Components Definitions (#21868)
This commit is contained in:
parent
c823b10e98
commit
c23fb8e09d
@ -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(
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.`);
|
||||
|
||||
|
||||
@ -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.`);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user