Moved configs

This commit is contained in:
Luis Alvarez 2021-03-17 14:08:58 -06:00
parent 8dee3bdf94
commit e56852d1bf
5 changed files with 58 additions and 6 deletions

View File

@ -1,3 +1,6 @@
# Only include the environment variables for a single provider
# To test a different provider, comment or remove the variables of other providers first
BIGCOMMERCE_STOREFRONT_API_URL=
BIGCOMMERCE_STOREFRONT_API_TOKEN=
BIGCOMMERCE_STORE_API_URL=

View File

@ -1,5 +1,4 @@
{
"provider": "bigcommerce",
"features": {
"wishlist": true,
"customCheckout": false

View File

@ -0,0 +1,46 @@
/**
* This file is expected to be used in next.config.js only
*/
const merge = require('deepmerge')
const PROVIDERS = ['bigcommerce', 'shopify']
function getProviderName() {
return process.env.BIGCOMMERCE_STOREFRONT_API_URL
? 'bigcommerce'
: process.env.NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN
? 'shopify'
: null
}
function withCommerceConfig(nextConfig = {}) {
const commerce = nextConfig.commerce || {}
const name = commerce.provider || getProviderName()
if (!name) {
throw new Error(
`The commerce provider is missing, please add a valid provider name or its environment variables`
)
}
if (!PROVIDERS.includes(name)) {
throw new Error(
`The commerce provider "${name}" can't be found, please use one of "${PROVIDERS.join(
', '
)}"`
)
}
const commerceNextConfig = require(`../${name}/next.config`)
const config = merge(commerceNextConfig, nextConfig)
config.env = config.env || {}
Object.entries(config.commerce.features).forEach(([k, v]) => {
if (v) config.env[`COMMERCE_${k.toUpperCase()}_ENABLED`] = true
})
return config
}
module.exports = { withCommerceConfig, getProviderName }

View File

@ -1,8 +1,12 @@
const commerce = require('./commerce.config.json')
const withCommerceConfig = require('./framework/commerce/with-config')
const {
withCommerceConfig,
getProviderName,
} = require('./framework/commerce/config')
const isBC = commerce.provider === 'bigcommerce'
const isShopify = commerce.provider === 'shopify'
const provider = commerce.provider || getProviderName()
const isBC = provider === 'bigcommerce'
const isShopify = provider === 'shopify'
module.exports = withCommerceConfig({
commerce,

View File

@ -22,8 +22,8 @@
"@components/*": ["components/*"],
"@commerce": ["framework/commerce"],
"@commerce/*": ["framework/commerce/*"],
"@framework": ["framework/bigcommerce"],
"@framework/*": ["framework/bigcommerce/*"]
"@framework": ["framework/shopify"],
"@framework/*": ["framework/shopify/*"]
}
},
"include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],