From 71234f9bd6a7acac3fb7544fa66a778c4e2ea788 Mon Sep 17 00:00:00 2001 From: John Hildenbiddle Date: Thu, 21 Dec 2023 14:04:52 -0600 Subject: [PATCH] Switch to named server config exports --- jest.config.js | 4 ++-- playwright.config.js | 4 ++-- server.configs.js | 20 +++++++------------- server.js | 10 ++++------ test/config/server.js | 4 ++-- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/jest.config.js b/jest.config.js index d6969f50f..66ac68ded 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,6 @@ -import serverConfigs from './server.configs.js'; +import { testConfig } from './server.configs.js'; -const { hostname, port } = serverConfigs.test; +const { hostname, port } = testConfig; const TEST_HOST = `http://${hostname}:${port}`; const sharedConfig = { errorOnDeprecated: true, diff --git a/playwright.config.js b/playwright.config.js index b2157d633..2c7e8894d 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -1,7 +1,7 @@ import { devices } from '@playwright/test'; -import serverConfigs from './server.configs.js'; +import { testConfig } from './server.configs.js'; -const { hostname, port } = serverConfigs.test; +const { hostname, port } = testConfig; const TEST_HOST = `http://${hostname}:${port}`; process.env.TEST_HOST = TEST_HOST; diff --git a/server.configs.js b/server.configs.js index 24cec22db..2f0889c72 100644 --- a/server.configs.js +++ b/server.configs.js @@ -6,7 +6,7 @@ const __filename = url.fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // Production (CDN URLs, watch disabled) -const prod = { +export const prodConfig = { hostname: '127.0.0.1', notify: false, open: false, @@ -19,13 +19,13 @@ const prod = { }; // Development (local URLs, watch enabled) -const dev = { - ...prod, +export const devConfig = { + ...prodConfig, files: ['CHANGELOG.md', 'docs/**/*', 'lib/**/*'], port: 3000, rewriteRules, server: { - ...prod.server, + ...prodConfig.server, routes: { '/changelog.md': path.resolve(__dirname, 'CHANGELOG.md'), '/lib': path.resolve(__dirname, 'lib'), @@ -36,11 +36,11 @@ const dev = { }; // Test (local URLs, watch disabled) -const test = { - ...dev, +export const testConfig = { + ...devConfig, port: 4000, server: { - ...dev.server, + ...devConfig.server, middleware: [ // Blank page required for test environment { @@ -56,9 +56,3 @@ const test = { snippet: false, watch: false, }; - -export default { - dev, - prod, - test, -}; diff --git a/server.js b/server.js index 366c9a1e4..d6da12cbe 100644 --- a/server.js +++ b/server.js @@ -1,15 +1,13 @@ import { create } from 'browser-sync'; -import serverConfigs from './server.configs.js'; +import { devConfig, prodConfig } from './server.configs.js'; const bsServer = create(); const args = process.argv.slice(2); -const configName = - Object.keys(serverConfigs).find(name => args.includes(`--${name}`)) || 'prod'; -const settings = serverConfigs[configName]; -const isWatch = Boolean(settings.files) && settings.watch !== false; +const config = args.includes('--dev') ? devConfig : prodConfig; +const isWatch = Boolean(config.files) && config.watch !== false; const urlType = configName === 'prod' ? 'CDN' : 'local'; // prettier-ignore console.log(`\nStarting ${configName} server (${urlType} URLs, watch: ${isWatch})\n`); -bsServer.init(settings); +bsServer.init(config); diff --git a/test/config/server.js b/test/config/server.js index aceea3804..d896b58f6 100644 --- a/test/config/server.js +++ b/test/config/server.js @@ -1,13 +1,13 @@ import * as process from 'node:process'; import { create } from 'browser-sync'; -import serverConfigs from '../../server.configs.js'; +import { testConfig } from '../../server.configs.js'; const bsServer = create(); export async function startServer() { // Wait for server to start return new Promise(resolve => { - const settings = serverConfigs.test; + const settings = testConfig; console.log('\n');