@stackbit/sdk
Advanced tools
Comparing version 0.2.24 to 0.2.25
import { ConfigError, ConfigLoadError, ConfigValidationError } from './config-errors'; | ||
import { Config, Model } from './config-types'; | ||
import { Config, Model, ModelsSource } from './config-types'; | ||
export interface ConfigLoaderOptions { | ||
[option: string]: any; | ||
dirPath: string; | ||
modelsSource?: string; | ||
modelsSource?: ModelsSource; | ||
} | ||
@@ -8,0 +8,0 @@ export interface ConfigLoaderResult { |
@@ -173,6 +173,5 @@ "use strict"; | ||
} | ||
async function loadModelsFromExternalSource(config, dirPath, options) { | ||
var _a; | ||
const modelsSource = lodash_1.default.get(config, 'modelsSource', {}); | ||
const sourceType = (_a = options.modelsSource) !== null && _a !== void 0 ? _a : lodash_1.default.get(modelsSource, 'type', 'files'); | ||
async function loadModelsFromExternalSource(config, dirPath, options = {}) { | ||
const modelsSource = lodash_1.default.get(config, 'modelsSource', options.modelsSource); | ||
const sourceType = lodash_1.default.get(modelsSource, 'type', 'files'); | ||
if (sourceType === 'files') { | ||
@@ -183,6 +182,6 @@ return { models: [], errors: [] }; | ||
const contentfulModule = lodash_1.default.get(modelsSource, 'module', '@stackbit/cms-contentful'); | ||
const modulePath = path_1.default.join(dirPath, 'node_modules', contentfulModule); | ||
const modulePath = path_1.default.resolve(dirPath, 'node_modules', contentfulModule); | ||
const module = await Promise.resolve().then(() => __importStar(require(modulePath))); | ||
try { | ||
const { models } = await module.fetchAndConvertSchema(options); | ||
const { models } = await module.fetchAndConvertSchema(lodash_1.default.omit(options, 'modelsSource')); | ||
return { | ||
@@ -189,0 +188,0 @@ models: models, |
{ | ||
"name": "@stackbit/sdk", | ||
"version": "0.2.24", | ||
"version": "0.2.25", | ||
"description": "Stackbit SDK", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -29,3 +29,3 @@ import path from 'path'; | ||
import { append, omitByNil, parseFile, readDirRecursively, reducePromise, rename } from '@stackbit/utils'; | ||
import { Config, DataModel, FieldEnum, FieldModel, FieldObjectProps, Model, PageModel, YamlModel } from './config-types'; | ||
import { Config, DataModel, FieldEnum, FieldModel, FieldObjectProps, Model, ModelsSource, PageModel, YamlModel } from './config-types'; | ||
import { loadPresets } from './presets-loader'; | ||
@@ -36,3 +36,3 @@ | ||
dirPath: string; | ||
modelsSource?: string; | ||
modelsSource?: ModelsSource; | ||
} | ||
@@ -225,6 +225,6 @@ | ||
dirPath: string, | ||
options: Omit<ConfigLoaderOptions, 'dirPath'> | ||
options: Omit<ConfigLoaderOptions, 'dirPath'> = {} | ||
): Promise<{ models: Model[]; errors: ConfigLoadError[] }> { | ||
const modelsSource = _.get(config, 'modelsSource', {}); | ||
const sourceType = options.modelsSource ?? _.get(modelsSource, 'type', 'files'); | ||
const modelsSource = _.get(config, 'modelsSource', options.modelsSource); | ||
const sourceType = _.get(modelsSource, 'type', 'files'); | ||
if (sourceType === 'files') { | ||
@@ -234,6 +234,6 @@ return { models: [], errors: [] }; | ||
const contentfulModule = _.get(modelsSource, 'module', '@stackbit/cms-contentful'); | ||
const modulePath = path.join(dirPath, 'node_modules', contentfulModule); | ||
const modulePath = path.resolve(dirPath, 'node_modules', contentfulModule); | ||
const module = await import(modulePath); | ||
try { | ||
const { models } = await module.fetchAndConvertSchema(options); | ||
const { models } = await module.fetchAndConvertSchema(_.omit(options, 'modelsSource')); | ||
return { | ||
@@ -240,0 +240,0 @@ models: models, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
771318
13726