forked from vercel/commerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update master to work with multiple Vercel projects (vercel#237)
* Moved configs * Delete with-config.js * Added log for configs * Update TS config based on the selected provider * set tsconfig to bigcommerce * Updated readme instructions on provider config * Added new commerce variable * Change the default of updateTSConfig Co-authored-by: B <[email protected]>
- Loading branch information
Showing
6 changed files
with
80 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
"provider": "bigcommerce", | ||
"features": { | ||
"wishlist": true, | ||
"customCheckout": false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* 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'] | ||
|
||
function getProviderName() { | ||
return ( | ||
process.env.COMMERCE_PROVIDER || | ||
(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(path.join('../', 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 | ||
}) | ||
|
||
// Update paths in `tsconfig.json` to point to the selected provider | ||
if (config.commerce.updateTSConfig !== false) { | ||
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 | ||
} | ||
|
||
module.exports = { withCommerceConfig, getProviderName } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters