Add Placeholders for Empty Artifacts in Type Generation (#21441)

This commit is contained in:
Jean-Sébastien Herbaux 2024-09-24 11:31:14 +02:00 committed by GitHub
parent c7b2b2abcc
commit 89197526ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View File

@ -5,6 +5,11 @@ const { factory } = require('typescript');
const { models } = require('../common');
const { emitDefinitions, format, generateSharedExtensionDefinition } = require('../utils');
const NO_COMPONENT_PLACEHOLDER_COMMENT = `/*
* The app doesn't have any components yet.
*/
`;
/**
* Generate type definitions for Strapi Components
*
@ -23,6 +28,12 @@ const generateComponentsDefinitions = async (options = {}) => {
definition: models.schema.generateSchemaDefinition(contentType),
}));
options.logger.debug(`Found ${componentsDefinitions.length} components.`);
if (componentsDefinitions.length === 0) {
return { output: NO_COMPONENT_PLACEHOLDER_COMMENT, stats: {} };
}
const formattedSchemasDefinitions = componentsDefinitions.reduce((acc, def) => {
acc.push(
// Definition

View File

@ -5,6 +5,11 @@ const { factory } = require('typescript');
const { models } = require('../common');
const { emitDefinitions, format, generateSharedExtensionDefinition } = require('../utils');
const NO_CONTENT_TYPE_PLACEHOLDER_COMMENT = `/*
* The app doesn't have any content-types yet.
*/
`;
/**
* Generate type definitions for Strapi Content-Types
*
@ -23,6 +28,12 @@ const generateContentTypesDefinitions = async (options = {}) => {
definition: models.schema.generateSchemaDefinition(contentType),
}));
options.logger.debug(`Found ${contentTypesDefinitions.length} content-types.`);
if (contentTypesDefinitions.length === 0) {
return { output: NO_CONTENT_TYPE_PLACEHOLDER_COMMENT, stats: {} };
}
const formattedSchemasDefinitions = contentTypesDefinitions.reduce((acc, def) => {
acc.push(
// Definition