mirror of
https://github.com/strapi/strapi.git
synced 2025-10-30 17:37:26 +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() {
|
generateImportDefinition() {
|
||||||
const formattedImports = imports.map((key) =>
|
const formattedImports = imports
|
||||||
factory.createImportSpecifier(false, undefined, factory.createIdentifier(key))
|
.sort()
|
||||||
);
|
.map((key) => factory.createImportSpecifier(false, undefined, factory.createIdentifier(key)));
|
||||||
|
|
||||||
return [
|
return [
|
||||||
factory.createImportDeclaration(
|
factory.createImportDeclaration(
|
||||||
|
|||||||
@ -22,9 +22,11 @@ const { addImport } = require('../imports');
|
|||||||
const generateAttributePropertySignature = (schema) => {
|
const generateAttributePropertySignature = (schema) => {
|
||||||
const { attributes } = schema;
|
const { attributes } = schema;
|
||||||
|
|
||||||
const properties = Object.entries(attributes).map(([attributeName, attribute]) => {
|
const properties = Object.entries(attributes)
|
||||||
return attributeToPropertySignature(schema, attributeName, attribute);
|
.sort((a, b) => a[0].localeCompare(b[0]))
|
||||||
});
|
.map(([attributeName, attribute]) => {
|
||||||
|
return attributeToPropertySignature(schema, attributeName, attribute);
|
||||||
|
});
|
||||||
|
|
||||||
return factory.createPropertySignature(
|
return factory.createPropertySignature(
|
||||||
undefined,
|
undefined,
|
||||||
|
|||||||
@ -111,7 +111,7 @@ const toTypeLiteral = (data) => {
|
|||||||
throw new Error(`Cannot convert to object literal. Unknown type "${typeof 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]) => {
|
const props = entries.reduce((acc, [key, value]) => {
|
||||||
// Handle keys such as content-type-builder & co.
|
// Handle keys such as content-type-builder & co.
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { factory } = require('typescript');
|
const { factory } = require('typescript');
|
||||||
|
const { pipe, values, sortBy, map } = require('lodash/fp');
|
||||||
|
|
||||||
const { models } = require('../common');
|
const { models } = require('../common');
|
||||||
const { emitDefinitions, format, generateSharedExtensionDefinition } = require('../utils');
|
const { emitDefinitions, format, generateSharedExtensionDefinition } = require('../utils');
|
||||||
@ -23,10 +24,14 @@ const generateComponentsDefinitions = async (options = {}) => {
|
|||||||
|
|
||||||
const { components } = strapi;
|
const { components } = strapi;
|
||||||
|
|
||||||
const componentsDefinitions = Object.values(components).map((contentType) => ({
|
const componentsDefinitions = pipe(
|
||||||
uid: contentType.uid,
|
values,
|
||||||
definition: models.schema.generateSchemaDefinition(contentType),
|
sortBy('uid'),
|
||||||
}));
|
map((component) => ({
|
||||||
|
uid: component.uid,
|
||||||
|
definition: models.schema.generateSchemaDefinition(component),
|
||||||
|
}))
|
||||||
|
)(components);
|
||||||
|
|
||||||
options.logger.debug(`Found ${componentsDefinitions.length} components.`);
|
options.logger.debug(`Found ${componentsDefinitions.length} components.`);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { factory } = require('typescript');
|
const { factory } = require('typescript');
|
||||||
|
const { values, pipe, map, sortBy } = require('lodash/fp');
|
||||||
|
|
||||||
const { models } = require('../common');
|
const { models } = require('../common');
|
||||||
const { emitDefinitions, format, generateSharedExtensionDefinition } = require('../utils');
|
const { emitDefinitions, format, generateSharedExtensionDefinition } = require('../utils');
|
||||||
@ -23,10 +24,14 @@ const generateContentTypesDefinitions = async (options = {}) => {
|
|||||||
|
|
||||||
const { contentTypes } = strapi;
|
const { contentTypes } = strapi;
|
||||||
|
|
||||||
const contentTypesDefinitions = Object.values(contentTypes).map((contentType) => ({
|
const contentTypesDefinitions = pipe(
|
||||||
uid: contentType.uid,
|
values,
|
||||||
definition: models.schema.generateSchemaDefinition(contentType),
|
sortBy('uid'),
|
||||||
}));
|
map((contentType) => ({
|
||||||
|
uid: contentType.uid,
|
||||||
|
definition: models.schema.generateSchemaDefinition(contentType),
|
||||||
|
}))
|
||||||
|
)(contentTypes);
|
||||||
|
|
||||||
options.logger.debug(`Found ${contentTypesDefinitions.length} content-types.`);
|
options.logger.debug(`Found ${contentTypesDefinitions.length} content-types.`);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user