From fffc0e51ec17405e95da2a360f1eca05cc9290d8 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Wed, 3 Feb 2021 10:52:07 +0100 Subject: [PATCH] chore(client): refactor & organise config (#40875) --- .gitignore | 7 ++++++- client/.gitignore | 5 ----- client/config/.gitkeep | 1 - client/gatsby-config.js | 3 ++- client/i18n/config.js | 4 ++-- client/src/__mocks__/gatsby.js | 2 +- client/src/client-only-routes/ShowSettings.js | 2 +- client/src/client-only-routes/ShowSettings.test.js | 2 +- client/src/client-only-routes/ShowUnsubscribed.js | 2 +- client/src/components/Donation/DonateForm.js | 3 +-- client/src/components/Donation/PaypalButton.js | 2 +- client/src/components/Header/components/Login.js | 2 +- client/src/components/Intro/components/IntroDescription.js | 2 +- client/src/components/createExternalRedirects.js | 2 +- client/src/components/helpers/CurrentChallengeLink.js | 2 +- client/src/components/profile/Profile.js | 2 +- client/src/components/profile/components/Camper.js | 2 +- client/src/components/profile/components/HeatMap.js | 2 +- client/src/components/profile/components/TimeLine.js | 2 +- client/src/components/search/WithInstantSearch.js | 2 +- client/src/templates/Challenges/classic/DesktopLayout.js | 2 +- client/src/templates/Challenges/classic/MobileLayout.js | 2 +- client/src/templates/Challenges/components/HelpModal.js | 2 +- .../src/templates/Challenges/rechallenge/transformers.js | 2 +- client/src/templates/Challenges/utils/build.js | 4 ++-- client/src/utils/ajax.js | 2 +- client/src/utils/get-words.js | 2 +- client/utils/buildChallenges.js | 2 +- client/webpack-workers.js | 2 +- config/client/.gitkeep | 0 curriculum/test/test-challenges.js | 2 +- tools/scripts/build/ensure-env.js | 2 -- 32 files changed, 36 insertions(+), 39 deletions(-) delete mode 100644 client/config/.gitkeep create mode 100644 config/client/.gitkeep diff --git a/.gitignore b/.gitignore index ec72f14ee7..0ceab59a0b 100644 --- a/.gitignore +++ b/.gitignore @@ -154,13 +154,18 @@ jspm_packages/ ### Netlify ### .netlify +### Generated config files ### +config/env.json +config/client/sass-compile.json +config/client/frame-runner.json +config/client/test-evaluator.json + ### Additional Files ### *.csv *.dat *.out *.gz *.swp -env.json curriculum/curricula.json client/static/js/frame-runner.js client/static/js/frame-runner.js.map diff --git a/client/.gitignore b/client/.gitignore index cc6a71fd16..e55e63a5f3 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -3,11 +3,6 @@ node_modules yarn-error.log -config/env.json -config/frame-runner.json -config/sass-compile.json -config/test-evaluator.json - # Build directory /public .DS_Store diff --git a/client/config/.gitkeep b/client/config/.gitkeep deleted file mode 100644 index c9a37c48bc..0000000000 --- a/client/config/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -# this file is here to add an empty dir to git diff --git a/client/gatsby-config.js b/client/gatsby-config.js index 9b47bc4563..f13db80e38 100644 --- a/client/gatsby-config.js +++ b/client/gatsby-config.js @@ -4,7 +4,8 @@ const { clientLocale, curriculumLocale, homeLocation -} = require('../config/env'); +} = require('../config/env.json'); + const { buildChallenges, replaceChallengeNode, diff --git a/client/i18n/config.js b/client/i18n/config.js index 9684b6deb9..8ee2c4b770 100644 --- a/client/i18n/config.js +++ b/client/i18n/config.js @@ -1,8 +1,8 @@ import i18n from 'i18next'; import { initReactI18next } from 'react-i18next'; -const { clientLocale } = require('../config/env'); -const { i18nextCodes } = require('./allLangs'); +import { clientLocale } from '../../config/env.json'; +import { i18nextCodes } from './allLangs'; const i18nextCode = i18nextCodes[clientLocale]; diff --git a/client/src/__mocks__/gatsby.js b/client/src/__mocks__/gatsby.js index 7ee4afd3df..4adeedcb3e 100644 --- a/client/src/__mocks__/gatsby.js +++ b/client/src/__mocks__/gatsby.js @@ -4,7 +4,7 @@ const React = require('react'); const gatsby = jest.requireActual('gatsby'); -const { clientLocale } = require('../../config/env'); +const { clientLocale } = require('../../../config/env.json'); module.exports = { ...gatsby, diff --git a/client/src/client-only-routes/ShowSettings.js b/client/src/client-only-routes/ShowSettings.js index df418027c2..785d2cf824 100644 --- a/client/src/client-only-routes/ShowSettings.js +++ b/client/src/client-only-routes/ShowSettings.js @@ -5,7 +5,7 @@ import { createSelector } from 'reselect'; import { Grid, Button } from '@freecodecamp/react-bootstrap'; import Helmet from 'react-helmet'; -import { apiLocation } from '../../config/env.json'; +import { apiLocation } from '../../../config/env.json'; import { signInLoadingSelector, userSelector, diff --git a/client/src/client-only-routes/ShowSettings.test.js b/client/src/client-only-routes/ShowSettings.test.js index 7c5825f628..ccab3fde27 100644 --- a/client/src/client-only-routes/ShowSettings.test.js +++ b/client/src/client-only-routes/ShowSettings.test.js @@ -1,7 +1,7 @@ /* global jest, expect */ import React from 'react'; import ShallowRenderer from 'react-test-renderer/shallow'; -import { apiLocation } from '../../config/env.json'; +import { apiLocation } from '../../../config/env.json'; import { ShowSettings } from './ShowSettings'; diff --git a/client/src/client-only-routes/ShowUnsubscribed.js b/client/src/client-only-routes/ShowUnsubscribed.js index e3827dd5de..02e1e32693 100644 --- a/client/src/client-only-routes/ShowUnsubscribed.js +++ b/client/src/client-only-routes/ShowUnsubscribed.js @@ -4,7 +4,7 @@ import { Grid, Panel, Button } from '@freecodecamp/react-bootstrap'; import Helmet from 'react-helmet'; import { useTranslation } from 'react-i18next'; -import env from '../../config/env.json'; +import env from '../../../config/env.json'; import FullWidthRow from '../components/helpers/FullWidthRow'; import { Spacer } from '../components/helpers'; diff --git a/client/src/components/Donation/DonateForm.js b/client/src/components/Donation/DonateForm.js index 4f199fa977..4cd42d6489 100644 --- a/client/src/components/Donation/DonateForm.js +++ b/client/src/components/Donation/DonateForm.js @@ -24,10 +24,9 @@ import { donationUrls, modalDefaultDonation } from '../../../../config/donation-settings'; -import { stripePublicKey } from '../../../../config/env.json'; +import { stripePublicKey, deploymentEnv } from '../../../../config/env.json'; import { stripeScriptLoader } from '../../utils/scriptLoaders'; import DonateFormChildViewForHOC from './DonateFormChildViewForHOC'; -import { deploymentEnv } from '../../../config/env.json'; import Spacer from '../helpers/Spacer'; import PaypalButton from './PaypalButton'; import DonateCompletion from './DonateCompletion'; diff --git a/client/src/components/Donation/PaypalButton.js b/client/src/components/Donation/PaypalButton.js index f329b51707..4450218561 100644 --- a/client/src/components/Donation/PaypalButton.js +++ b/client/src/components/Donation/PaypalButton.js @@ -7,7 +7,7 @@ import { createSelector } from 'reselect'; import PayPalButtonScriptLoader from './PayPalButtonScriptLoader'; import { withTranslation } from 'react-i18next'; -import { paypalClientId, deploymentEnv } from '../../../config/env.json'; +import { paypalClientId, deploymentEnv } from '../../../../config/env.json'; import { paypalConfigurator, paypalConfigTypes diff --git a/client/src/components/Header/components/Login.js b/client/src/components/Header/components/Login.js index 3551d1415a..7d055d9680 100644 --- a/client/src/components/Header/components/Login.js +++ b/client/src/components/Header/components/Login.js @@ -6,7 +6,7 @@ import { Button } from '@freecodecamp/react-bootstrap'; import { useTranslation } from 'react-i18next'; import { isSignedInSelector } from '../../../redux'; -import { apiLocation, homeLocation } from '../../../../config/env.json'; +import { apiLocation, homeLocation } from '../../../../../config/env.json'; import './login.css'; diff --git a/client/src/components/Intro/components/IntroDescription.js b/client/src/components/Intro/components/IntroDescription.js index 525dedadc7..4928ce80db 100644 --- a/client/src/components/Intro/components/IntroDescription.js +++ b/client/src/components/Intro/components/IntroDescription.js @@ -1,6 +1,6 @@ import React from 'react'; import { Link, Spacer } from '../../helpers'; -import { forumLocation } from '../../../../config/env.json'; +import { forumLocation } from '../../../../../config/env.json'; import { Trans, useTranslation } from 'react-i18next'; import '../intro.css'; diff --git a/client/src/components/createExternalRedirects.js b/client/src/components/createExternalRedirects.js index bb8480689a..903a7ba752 100644 --- a/client/src/components/createExternalRedirects.js +++ b/client/src/components/createExternalRedirects.js @@ -1,4 +1,4 @@ -import { forumLocation } from '../../config/env.json'; +import { forumLocation } from '../../../config/env.json'; const createExternalRedirect = (page, { clientLocale }) => { const isNotEnglish = clientLocale !== 'english'; diff --git a/client/src/components/helpers/CurrentChallengeLink.js b/client/src/components/helpers/CurrentChallengeLink.js index bb149f1b95..f1da4c23cd 100644 --- a/client/src/components/helpers/CurrentChallengeLink.js +++ b/client/src/components/helpers/CurrentChallengeLink.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { apiLocation } from '../../../config/env.json'; +import { apiLocation } from '../../../../config/env.json'; const currentChallengeApi = '/challenges/current-challenge'; diff --git a/client/src/components/profile/Profile.js b/client/src/components/profile/Profile.js index ce81d8607e..7b63bf55db 100644 --- a/client/src/components/profile/Profile.js +++ b/client/src/components/profile/Profile.js @@ -11,7 +11,7 @@ import HeatMap from './components/HeatMap'; import Certifications from './components/Certifications'; import Portfolio from './components/Portfolio'; import Timeline from './components/TimeLine'; -import { apiLocation } from '../../../config/env.json'; +import { apiLocation } from '../../../../config/env.json'; const propTypes = { isSessionUser: PropTypes.bool, diff --git a/client/src/components/profile/components/Camper.js b/client/src/components/profile/components/Camper.js index 47e7b29191..c346e73e92 100644 --- a/client/src/components/profile/components/Camper.js +++ b/client/src/components/profile/components/Camper.js @@ -16,7 +16,7 @@ import Link from '../../helpers/Link'; import './camper.css'; import { langCodes } from '../../../../i18n/allLangs'; -import { clientLocale } from '../../../../config/env'; +import { clientLocale } from '../../../../../config/env.json'; const localeCode = langCodes[clientLocale]; diff --git a/client/src/components/profile/components/HeatMap.js b/client/src/components/profile/components/HeatMap.js index ebd1716577..21243d862d 100644 --- a/client/src/components/profile/components/HeatMap.js +++ b/client/src/components/profile/components/HeatMap.js @@ -16,7 +16,7 @@ import '@freecodecamp/react-calendar-heatmap/dist/styles.css'; import './heatmap.css'; import { langCodes } from '../../../../i18n/allLangs'; -import { clientLocale } from '../../../../config/env'; +import { clientLocale } from '../../../../../config/env.json'; const localeCode = langCodes[clientLocale]; diff --git a/client/src/components/profile/components/TimeLine.js b/client/src/components/profile/components/TimeLine.js index 4287fe9c2d..eaca8e2074 100644 --- a/client/src/components/profile/components/TimeLine.js +++ b/client/src/components/profile/components/TimeLine.js @@ -25,7 +25,7 @@ import { maybeUrlRE } from '../../../utils'; import CertificationIcon from '../../../assets/icons/CertificationIcon'; import { langCodes } from '../../../../i18n/allLangs'; -import { clientLocale } from '../../../../config/env'; +import { clientLocale } from '../../../../../config/env.json'; const localeCode = langCodes[clientLocale]; diff --git a/client/src/components/search/WithInstantSearch.js b/client/src/components/search/WithInstantSearch.js index cb80c6455a..8e6cc77afd 100644 --- a/client/src/components/search/WithInstantSearch.js +++ b/client/src/components/search/WithInstantSearch.js @@ -15,7 +15,7 @@ import { toggleSearchDropdown, updateSearchQuery } from './redux'; -import { algoliaAppId, algoliaAPIKey } from '../../../config/env.json'; +import { algoliaAppId, algoliaAPIKey } from '../../../../config/env.json'; import { createSelector } from 'reselect'; diff --git a/client/src/templates/Challenges/classic/DesktopLayout.js b/client/src/templates/Challenges/classic/DesktopLayout.js index 459b34227f..e6510f4867 100644 --- a/client/src/templates/Challenges/classic/DesktopLayout.js +++ b/client/src/templates/Challenges/classic/DesktopLayout.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'; import { first } from 'lodash'; import EditorTabs from './EditorTabs'; import ActionRow from './ActionRow'; -import { showUpcomingChanges } from '../../../../config/env.json'; +import { showUpcomingChanges } from '../../../../../config/env.json'; const propTypes = { challengeFiles: PropTypes.object, diff --git a/client/src/templates/Challenges/classic/MobileLayout.js b/client/src/templates/Challenges/classic/MobileLayout.js index 6447249ca7..a75598ed5f 100644 --- a/client/src/templates/Challenges/classic/MobileLayout.js +++ b/client/src/templates/Challenges/classic/MobileLayout.js @@ -8,7 +8,7 @@ import { createStructuredSelector } from 'reselect'; import { currentTabSelector, moveToTab } from '../redux'; import { bindActionCreators } from 'redux'; import EditorTabs from './EditorTabs'; -import { showUpcomingChanges } from '../../../../config/env.json'; +import { showUpcomingChanges } from '../../../../../config/env.json'; const mapStateToProps = createStructuredSelector({ currentTab: currentTabSelector diff --git a/client/src/templates/Challenges/components/HelpModal.js b/client/src/templates/Challenges/components/HelpModal.js index cf97071cb5..66960ef12c 100644 --- a/client/src/templates/Challenges/components/HelpModal.js +++ b/client/src/templates/Challenges/components/HelpModal.js @@ -7,7 +7,7 @@ import { Trans, withTranslation } from 'react-i18next'; import { createQuestion, closeModal, isHelpModalOpenSelector } from '../redux'; import { executeGA } from '../../../redux'; -import { forumLocation } from '../../../../config/env.json'; +import { forumLocation } from '../../../../../config/env.json'; import './help-modal.css'; diff --git a/client/src/templates/Challenges/rechallenge/transformers.js b/client/src/templates/Challenges/rechallenge/transformers.js index 061e160c61..81c35dfa47 100644 --- a/client/src/templates/Challenges/rechallenge/transformers.js +++ b/client/src/templates/Challenges/rechallenge/transformers.js @@ -17,7 +17,7 @@ import createWorker from '../utils/worker-executor'; // the config files are created during the build, but not before linting // eslint-disable-next-line import/no-unresolved -import { filename as sassCompile } from '../../../../config/sass-compile'; +import { filename as sassCompile } from '../../../../../config/client/sass-compile'; const protectTimeout = 100; const testProtectTimeout = 1500; diff --git a/client/src/templates/Challenges/utils/build.js b/client/src/templates/Challenges/utils/build.js index 02965c3573..e6bb913b59 100644 --- a/client/src/templates/Challenges/utils/build.js +++ b/client/src/templates/Challenges/utils/build.js @@ -10,9 +10,9 @@ import { // the config files are created during the build, but not before linting // eslint-disable-next-line import/no-unresolved -import { filename as runner } from '../../../../config/frame-runner'; +import { filename as runner } from '../../../../../config/client/frame-runner'; // eslint-disable-next-line import/no-unresolved -import { filename as testEvaluator } from '../../../../config/test-evaluator'; +import { filename as testEvaluator } from '../../../../../config/client/test-evaluator'; const frameRunner = [ { diff --git a/client/src/utils/ajax.js b/client/src/utils/ajax.js index 7f6931cdad..0b640b75f4 100644 --- a/client/src/utils/ajax.js +++ b/client/src/utils/ajax.js @@ -1,4 +1,4 @@ -import { apiLocation } from '../../config/env.json'; +import { apiLocation } from '../../../config/env.json'; import axios from 'axios'; import Tokens from 'csrf'; import cookies from 'browser-cookies'; diff --git a/client/src/utils/get-words.js b/client/src/utils/get-words.js index f1a8f13e88..9d94249855 100644 --- a/client/src/utils/get-words.js +++ b/client/src/utils/get-words.js @@ -1,4 +1,4 @@ -const config = require('../../config/env'); +const config = require('../../../config/env.json'); const words = require(`../../i18n/locales/${config.clientLocale}/motivation.json`); diff --git a/client/utils/buildChallenges.js b/client/utils/buildChallenges.js index db916db301..ba3ed5491f 100644 --- a/client/utils/buildChallenges.js +++ b/client/utils/buildChallenges.js @@ -6,7 +6,7 @@ const { challengesDir, getChallengesDirForLang } = require('../../curriculum/getChallenges'); -const { curriculumLocale } = require('../config/env.json'); +const { curriculumLocale } = require('../../config/env.json'); exports.localeChallengesRootDir = getChallengesDirForLang(curriculumLocale); diff --git a/client/webpack-workers.js b/client/webpack-workers.js index 9822de100d..214e95a01f 100644 --- a/client/webpack-workers.js +++ b/client/webpack-workers.js @@ -5,7 +5,7 @@ const { writeFileSync } = require('fs'); module.exports = (env = {}) => { const __DEV__ = env.production !== true; const staticPath = path.join(__dirname, './static/js'); - const configPath = path.join(__dirname, './config'); + const configPath = path.join(__dirname, '../config/client'); return { mode: __DEV__ ? 'development' : 'production', entry: { diff --git a/config/client/.gitkeep b/config/client/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/curriculum/test/test-challenges.js b/curriculum/test/test-challenges.js index ea23ed057f..bc13363e0d 100644 --- a/curriculum/test/test-challenges.js +++ b/curriculum/test/test-challenges.js @@ -60,7 +60,7 @@ const TRANSLATABLE_COMMENTS = getTranslatableComments( path.resolve(__dirname, '..', 'dictionaries') ); -const testEvaluator = require('../../client/config/test-evaluator').filename; +const testEvaluator = require('../../config/client/test-evaluator').filename; const commentExtractors = { html: require('./utils/extract-html-comments'), diff --git a/tools/scripts/build/ensure-env.js b/tools/scripts/build/ensure-env.js index ad843e1c5b..75198fd010 100644 --- a/tools/scripts/build/ensure-env.js +++ b/tools/scripts/build/ensure-env.js @@ -4,7 +4,6 @@ const path = require('path'); const env = require('../../../config/env'); const { availableLangs } = require('../../../client/i18n/allLangs'); -const clientPath = path.resolve(__dirname, '../../../client'); const globalConfigPath = path.resolve(__dirname, '../../../config'); const { FREECODECAMP_NODE_ENV } = process.env; @@ -104,5 +103,4 @@ if (FREECODECAMP_NODE_ENV !== 'development') { checkCurriculumLocale(); } -fs.writeFileSync(`${clientPath}/config/env.json`, JSON.stringify(env)); fs.writeFileSync(`${globalConfigPath}/env.json`, JSON.stringify(env));