Update TS config based on the selected provider

This commit is contained in:
Luis Alvarez 2021-03-17 14:53:29 -06:00
parent 40cf6247cf
commit 73ad0aa9c1
3 changed files with 20 additions and 1 deletions

View File

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

View File

@ -2,7 +2,10 @@
* This file is expected to be used in next.config.js only
*/
const path = require('path')
const fs = require('fs')
const merge = require('deepmerge')
const prettier = require('prettier')
const PROVIDERS = ['bigcommerce', 'shopify']
@ -31,7 +34,7 @@ function withCommerceConfig(nextConfig = {}) {
)
}
const commerceNextConfig = require(`../${name}/next.config`)
const commerceNextConfig = require(path.join('../', name, 'next.config'))
const config = merge(commerceNextConfig, nextConfig)
config.env = config.env || {}
@ -40,6 +43,20 @@ function withCommerceConfig(nextConfig = {}) {
if (v) config.env[`COMMERCE_${k.toUpperCase()}_ENABLED`] = true
})
// Update paths in `tsconfig.json` to point to the selected provider
if (config.commerce.updateTSConfig) {
const tsconfigPath = path.join(process.cwd(), 'tsconfig.json')
const tsconfig = require(tsconfigPath)
tsconfig.compilerOptions.paths['@framework'] = [`framework/${name}`]
tsconfig.compilerOptions.paths['@framework/*'] = [`framework/${name}/*`]
fs.writeFileSync(
tsconfigPath,
prettier.format(JSON.stringify(tsconfig), { parser: 'json' })
)
}
return config
}

View File

@ -44,4 +44,5 @@ module.exports = withCommerceConfig({
},
})
// Don't delete this console log, useful to see the commerce config in Vercel deployments
console.log('next.config.js', JSON.stringify(module.exports, null, 2))