mirror of
https://github.com/strapi/strapi.git
synced 2025-08-15 04:08:04 +00:00
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
const { createDefaultSettings, syncSettings } = require('./settings');
|
|
const { createDefaultMetadatas, syncMetadatas } = require('./metadatas');
|
|
const { createDefaultLayouts, syncLayouts } = require('./layouts');
|
|
const { formatContentTypeSchema } = require('../../ContentTypes');
|
|
const {
|
|
createModelConfigurationSchema,
|
|
} = require('../../../controllers/validation');
|
|
|
|
async function validateCustomConfig(model, schema) {
|
|
try {
|
|
await createModelConfigurationSchema(model, schema, {
|
|
allowUndefined: true,
|
|
}).validate(model.config);
|
|
} catch (error) {
|
|
throw new Error(
|
|
`Invalid Model configuration for model ${model.uid}. Verify your {{modelName}}.config.js(on) file:\n - ${error.message}\n`
|
|
);
|
|
}
|
|
}
|
|
|
|
async function createDefaultConfiguration(model) {
|
|
// convert model to schema
|
|
|
|
const schema = formatContentTypeSchema(model);
|
|
|
|
if (model.config) {
|
|
await validateCustomConfig(model, schema);
|
|
schema.config = model.config;
|
|
}
|
|
|
|
return {
|
|
settings: await createDefaultSettings(schema),
|
|
metadatas: await createDefaultMetadatas(schema),
|
|
layouts: await createDefaultLayouts(schema),
|
|
};
|
|
}
|
|
|
|
async function syncConfiguration(conf, model) {
|
|
// convert model to schema
|
|
const schema = formatContentTypeSchema(model);
|
|
|
|
if (model.config) {
|
|
await validateCustomConfig(model, schema);
|
|
schema.config = model.config;
|
|
}
|
|
|
|
return {
|
|
settings: await syncSettings(conf, schema),
|
|
layouts: await syncLayouts(conf, schema),
|
|
metadatas: await syncMetadatas(conf, schema),
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
createDefaultConfiguration,
|
|
syncConfiguration,
|
|
};
|