mirror of
https://github.com/vercel/commerce.git
synced 2025-05-19 07:56:59 +00:00
Updated commerce hoc
This commit is contained in:
parent
39db23da17
commit
95f621090c
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const merge = require('deepmerge')
|
||||||
const prettier = require('prettier')
|
const prettier = require('prettier')
|
||||||
const core = require('@vercel/commerce/config')
|
const core = require('@vercel/commerce/config')
|
||||||
|
|
||||||
@ -34,32 +35,38 @@ function getProviderName() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function withCommerceConfig(nextConfig = {}) {
|
function withCommerceConfig(nextConfig = {}) {
|
||||||
const commerce = nextConfig.commerce || {}
|
const config = merge(
|
||||||
const name = commerce.provider || getProviderName()
|
{ commerce: { provider: getProviderName() } },
|
||||||
|
nextConfig
|
||||||
|
)
|
||||||
|
const { commerce } = config
|
||||||
|
const { provider } = commerce
|
||||||
|
|
||||||
if (!name) {
|
console.log('CONFIG', config)
|
||||||
|
|
||||||
|
if (!provider) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The commerce provider is missing, please add a valid provider name or its environment variables`
|
`The commerce provider is missing, please add a valid provider name or its environment variables`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (!PROVIDERS.includes(name)) {
|
if (!PROVIDERS.includes(provider)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The commerce provider "${name}" can't be found, please use one of "${PROVIDERS.join(
|
`The commerce provider "${provider}" can't be found, please use one of "${PROVIDERS.join(
|
||||||
', '
|
', '
|
||||||
)}"`
|
)}"`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update paths in `tsconfig.json` to point to the selected provider
|
// Update paths in `tsconfig.json` to point to the selected provider
|
||||||
if (nextConfig.commerce.updateTSConfig !== false) {
|
if (commerce.updateTSConfig !== false) {
|
||||||
const tsconfigPath = path.join(
|
const tsconfigPath = path.join(
|
||||||
process.cwd(),
|
process.cwd(),
|
||||||
commerce.tsconfigPath || 'tsconfig.json'
|
commerce.tsconfigPath || 'tsconfig.json'
|
||||||
)
|
)
|
||||||
const tsconfig = require(tsconfigPath)
|
const tsconfig = require(tsconfigPath)
|
||||||
|
|
||||||
tsconfig.compilerOptions.paths['@framework'] = [`${name}`]
|
tsconfig.compilerOptions.paths['@framework'] = [`${provider}`]
|
||||||
tsconfig.compilerOptions.paths['@framework/*'] = [`${name}/*`]
|
tsconfig.compilerOptions.paths['@framework/*'] = [`${provider}/*`]
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
tsconfigPath,
|
tsconfigPath,
|
||||||
@ -67,7 +74,7 @@ function withCommerceConfig(nextConfig = {}) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return core.withCommerceConfig(nextConfig)
|
return core.withCommerceConfig(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { withCommerceConfig, getProviderName }
|
module.exports = { withCommerceConfig, getProviderName }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user