mirror of
https://github.com/strapi/strapi.git
synced 2025-11-05 04:13:36 +00:00
Added silence option and handle skipped schemas
This commit is contained in:
parent
da56cc6a7b
commit
4308a2f269
@ -221,6 +221,7 @@ program
|
|||||||
'Specify a relative directory in which the schemas definitions will be generated'
|
'Specify a relative directory in which the schemas definitions will be generated'
|
||||||
)
|
)
|
||||||
.option('-f, --file <file>', 'Specify a filename to store the schemas definitions')
|
.option('-f, --file <file>', 'Specify a filename to store the schemas definitions')
|
||||||
|
.option('-s, --silence', `Don't display debug information`, false)
|
||||||
.action(getLocalScript('content-types/generate-types'));
|
.action(getLocalScript('content-types/generate-types'));
|
||||||
|
|
||||||
program
|
program
|
||||||
|
|||||||
@ -17,7 +17,7 @@ const { generateGlobalDefinition } = require('./global');
|
|||||||
const { generateImports } = require('./imports');
|
const { generateImports } = require('./imports');
|
||||||
const { logWarning, getSchemaTypeName } = require('./utils');
|
const { logWarning, getSchemaTypeName } = require('./utils');
|
||||||
|
|
||||||
module.exports = async function({ outDir, file }) {
|
module.exports = async function({ outDir, file, silence }) {
|
||||||
const [app, dirs] = await setup();
|
const [app, dirs] = await setup();
|
||||||
|
|
||||||
const schemas = getAllStrapiSchemas(app);
|
const schemas = getAllStrapiSchemas(app);
|
||||||
@ -36,16 +36,41 @@ module.exports = async function({ outDir, file }) {
|
|||||||
|
|
||||||
await generateSchemaFile(outDir || dirs.app, fullDefinition, file);
|
await generateSchemaFile(outDir || dirs.app, fullDefinition, file);
|
||||||
|
|
||||||
for (const defintion of definitions) {
|
for (const definition of definitions) {
|
||||||
table.push([defintion.kind, defintion.uid, defintion.type, chalk.greenBright('✓')]);
|
const isValidDefinition = definition.definition !== null;
|
||||||
|
const validateAndTransform = isValidDefinition ? fp.identity : chalk.redBright;
|
||||||
|
|
||||||
|
table.push([
|
||||||
|
validateAndTransform(definition.kind),
|
||||||
|
validateAndTransform(definition.uid),
|
||||||
|
validateAndTransform(definition.type),
|
||||||
|
isValidDefinition ? chalk.greenBright('✓') : chalk.redBright('✗'),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(table.toString());
|
const successfullDefinition = fp.filter(d => !fp.isNil(d.definition), definitions);
|
||||||
console.log(
|
const skippedDefinition = fp.filter(d => fp.isNil(d.definition), definitions);
|
||||||
chalk.greenBright(
|
|
||||||
`Generated ${fp.size(definitions)} type definition for your Strapi application's schemas.`
|
if (!silence) {
|
||||||
)
|
console.log(table.toString());
|
||||||
);
|
console.log(
|
||||||
|
chalk.greenBright(
|
||||||
|
`Generated ${fp.size(
|
||||||
|
successfullDefinition
|
||||||
|
)} type definition for your Strapi application's schemas.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const skippedAmount = fp.size(skippedDefinition);
|
||||||
|
|
||||||
|
if (skippedAmount > 0) {
|
||||||
|
console.log(
|
||||||
|
chalk.redBright(
|
||||||
|
`Skipped ${skippedAmount} (${skippedDefinition.map(d => d.uid).join(', ')})`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app.destroy();
|
app.destroy();
|
||||||
};
|
};
|
||||||
@ -90,16 +115,14 @@ const generateTypesDefinitions = schemas => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Content Types
|
// Content Types
|
||||||
else if (modelType === 'contentType') {
|
else if (modelType === 'contentType' && ['singleType', 'collectionType'].includes(kind)) {
|
||||||
definition = generateContentTypeDefinition(uid, schema, type);
|
definition = generateContentTypeDefinition(uid, schema, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
else {
|
else {
|
||||||
logWarning(
|
logWarning(`"${uid}" has an invalid model definition. Skipping...`);
|
||||||
`${uid} has an invalid model type: "${modelType}". Allowed model types are "component" and "contentType"`
|
definition = null;
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the generated definition to the list
|
// Add the generated definition to the list
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user