mirror of
https://github.com/vercel/commerce.git
synced 2025-06-08 09:16:58 +00:00
Updated commerce config
This commit is contained in:
parent
1735b9e5ab
commit
32c60e9248
@ -9,13 +9,19 @@
|
|||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
"*": "./dist/*"
|
"*": "./dist/*",
|
||||||
|
"config": "./config.js"
|
||||||
},
|
},
|
||||||
"typesVersions": {
|
"typesVersions": {
|
||||||
"*": {
|
"*": {
|
||||||
"*": [
|
"*": [
|
||||||
"src/*",
|
"src/*"
|
||||||
|
],
|
||||||
|
"api": [
|
||||||
"src/api/index.ts"
|
"src/api/index.ts"
|
||||||
|
],
|
||||||
|
"config": [
|
||||||
|
"dist/config.d.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
30
packages/commerce/src/config.js
Normal file
30
packages/commerce/src/config.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* This file is expected to be used in next.config.js only
|
||||||
|
*/
|
||||||
|
|
||||||
|
const path = require('path')
|
||||||
|
const merge = require('deepmerge')
|
||||||
|
|
||||||
|
function withCommerceConfig(nextConfig = {}) {
|
||||||
|
const commerce = nextConfig.commerce || {}
|
||||||
|
const { provider } = commerce
|
||||||
|
|
||||||
|
if (!provider) {
|
||||||
|
throw new Error(
|
||||||
|
`The commerce provider is missing, please add a valid provider name`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const commerceNextConfig = require(path.join(provider, 'next.config'))
|
||||||
|
const config = merge(nextConfig, commerceNextConfig)
|
||||||
|
|
||||||
|
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 }
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
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 PROVIDERS = [
|
const PROVIDERS = [
|
||||||
'local',
|
'local',
|
||||||
@ -50,43 +50,24 @@ function withCommerceConfig(nextConfig = {}) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const commerceNextConfig = require(path.join('../', name, 'next.config'))
|
|
||||||
const config = merge(nextConfig, commerceNextConfig)
|
|
||||||
|
|
||||||
config.env = config.env || {}
|
|
||||||
|
|
||||||
Object.entries(config.commerce.features).forEach(([k, v]) => {
|
|
||||||
if (v) config.env[`COMMERCE_${k.toUpperCase()}_ENABLED`] = true
|
|
||||||
})
|
|
||||||
|
|
||||||
// Update paths in `tsconfig.json` to point to the selected provider
|
// Update paths in `tsconfig.json` to point to the selected provider
|
||||||
if (config.commerce.updateTSConfig !== false) {
|
if (nextConfig.commerce.updateTSConfig !== false) {
|
||||||
const tsconfigPath = path.join(process.cwd(), 'tsconfig.json')
|
const tsconfigPath = path.join(
|
||||||
|
process.cwd(),
|
||||||
|
commerce.tsconfigPath || 'tsconfig.json'
|
||||||
|
)
|
||||||
const tsconfig = require(tsconfigPath)
|
const tsconfig = require(tsconfigPath)
|
||||||
|
|
||||||
tsconfig.compilerOptions.paths['@framework'] = [`framework/${name}`]
|
tsconfig.compilerOptions.paths['@framework'] = [`framework/${name}`]
|
||||||
tsconfig.compilerOptions.paths['@framework/*'] = [`framework/${name}/*`]
|
tsconfig.compilerOptions.paths['@framework/*'] = [`framework/${name}/*`]
|
||||||
|
|
||||||
// When running for production it may be useful to exclude the other providers
|
|
||||||
// from TS checking
|
|
||||||
if (process.env.VERCEL) {
|
|
||||||
const exclude = tsconfig.exclude.filter(
|
|
||||||
(item) => !item.startsWith('framework/')
|
|
||||||
)
|
|
||||||
|
|
||||||
tsconfig.exclude = PROVIDERS.reduce((exclude, current) => {
|
|
||||||
if (current !== name) exclude.push(`framework/${current}`)
|
|
||||||
return exclude
|
|
||||||
}, exclude)
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
tsconfigPath,
|
tsconfigPath,
|
||||||
prettier.format(JSON.stringify(tsconfig), { parser: 'json' })
|
prettier.format(JSON.stringify(tsconfig), { parser: 'json' })
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return core.withCommerceConfig(nextConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { withCommerceConfig, getProviderName }
|
module.exports = { withCommerceConfig, getProviderName }
|
@ -1,8 +1,5 @@
|
|||||||
const commerce = require('./commerce.config.json')
|
const commerce = require('./commerce.config.json')
|
||||||
const {
|
const { withCommerceConfig, getProviderName } = require('./commerce-config')
|
||||||
withCommerceConfig,
|
|
||||||
getProviderName,
|
|
||||||
} = require('./framework/commerce/config')
|
|
||||||
|
|
||||||
const provider = commerce.provider || getProviderName()
|
const provider = commerce.provider || getProviderName()
|
||||||
const isBC = provider === 'bigcommerce'
|
const isBC = provider === 'bigcommerce'
|
||||||
|
@ -27,18 +27,6 @@
|
|||||||
"@framework/*": ["framework/local/*"]
|
"@framework/*": ["framework/local/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["site/next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],
|
"include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],
|
||||||
"exclude": [
|
"exclude": ["node_modules"]
|
||||||
"node_modules",
|
|
||||||
"./framework/local",
|
|
||||||
"./framework/bigcommerce",
|
|
||||||
"./framework/shopify",
|
|
||||||
"./framework/swell",
|
|
||||||
"./framework/vendure",
|
|
||||||
"./framework/saleor",
|
|
||||||
"./framework/spree",
|
|
||||||
"./framework/ordercloud",
|
|
||||||
"./framework/kibocommerce",
|
|
||||||
"./framework/commercejs"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user