import _ from 'lodash'; import { Config, isListDataModel, loadConfigWithModelsPresetsAndValidate } from '@stackbit/sdk'; export function fetchAndConvertSchema(options: { dirPath: string }): Promise<{ schema: Config; errors: Error[] }> { return loadConfigWithModelsPresetsAndValidate({ dirPath: options.dirPath }).then(({ config, errors }) => { if (!config) { return { schema: {} as Config, errors }; } wrapListDataModels(config); const schema = _.pick(config, [ 'stackbitVersion', 'ssgName', 'ssgVersion', 'nodeVersion', 'devCommand', 'cmsName', 'import', 'publishDir', 'staticDir', 'uploadDir', 'assets', 'dataDir', 'pagesDir', 'pageLayoutKey', 'objectTypeKey', 'excludePages', 'logicFields', 'contentModels', 'presetSource', 'modelsSource', 'models', 'presets', 'dirPath', 'filePath', 'sidebarButtons' ]); return { schema, errors }; }); } function wrapListDataModels(config: Config) { _.forEach(config.models, (model) => { if (!isListDataModel(model)) { return; } _.set(model, 'fields', [ { type: 'list', name: 'items', items: model.items } ]); _.unset(model, 'items'); }); }