mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 21:21:21 +00:00
Moved configs
This commit is contained in:
parent
8dee3bdf94
commit
e56852d1bf
@ -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=
|
||||
|
@ -1,5 +1,4 @@
|
||||
{
|
||||
"provider": "bigcommerce",
|
||||
"features": {
|
||||
"wishlist": true,
|
||||
"customCheckout": false
|
||||
|
46
framework/commerce/config.js
Normal file
46
framework/commerce/config.js
Normal 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 }
|
@ -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,
|
||||
|
@ -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"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user