chore(client): refactor & organise config (#40875)

This commit is contained in:
Oliver Eyton-Williams
2021-02-03 10:52:07 +01:00
committed by GitHub
parent c1f9cd93f5
commit fffc0e51ec
32 changed files with 36 additions and 39 deletions

7
.gitignore vendored
View File

@ -154,13 +154,18 @@ jspm_packages/
### Netlify ### ### Netlify ###
.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 ### ### Additional Files ###
*.csv *.csv
*.dat *.dat
*.out *.out
*.gz *.gz
*.swp *.swp
env.json
curriculum/curricula.json curriculum/curricula.json
client/static/js/frame-runner.js client/static/js/frame-runner.js
client/static/js/frame-runner.js.map client/static/js/frame-runner.js.map

5
client/.gitignore vendored
View File

@ -3,11 +3,6 @@
node_modules node_modules
yarn-error.log yarn-error.log
config/env.json
config/frame-runner.json
config/sass-compile.json
config/test-evaluator.json
# Build directory # Build directory
/public /public
.DS_Store .DS_Store

View File

@ -1 +0,0 @@
# this file is here to add an empty dir to git

View File

@ -4,7 +4,8 @@ const {
clientLocale, clientLocale,
curriculumLocale, curriculumLocale,
homeLocation homeLocation
} = require('../config/env'); } = require('../config/env.json');
const { const {
buildChallenges, buildChallenges,
replaceChallengeNode, replaceChallengeNode,

View File

@ -1,8 +1,8 @@
import i18n from 'i18next'; import i18n from 'i18next';
import { initReactI18next } from 'react-i18next'; import { initReactI18next } from 'react-i18next';
const { clientLocale } = require('../config/env'); import { clientLocale } from '../../config/env.json';
const { i18nextCodes } = require('./allLangs'); import { i18nextCodes } from './allLangs';
const i18nextCode = i18nextCodes[clientLocale]; const i18nextCode = i18nextCodes[clientLocale];

View File

@ -4,7 +4,7 @@ const React = require('react');
const gatsby = jest.requireActual('gatsby'); const gatsby = jest.requireActual('gatsby');
const { clientLocale } = require('../../config/env'); const { clientLocale } = require('../../../config/env.json');
module.exports = { module.exports = {
...gatsby, ...gatsby,

View File

@ -5,7 +5,7 @@ import { createSelector } from 'reselect';
import { Grid, Button } from '@freecodecamp/react-bootstrap'; import { Grid, Button } from '@freecodecamp/react-bootstrap';
import Helmet from 'react-helmet'; import Helmet from 'react-helmet';
import { apiLocation } from '../../config/env.json'; import { apiLocation } from '../../../config/env.json';
import { import {
signInLoadingSelector, signInLoadingSelector,
userSelector, userSelector,

View File

@ -1,7 +1,7 @@
/* global jest, expect */ /* global jest, expect */
import React from 'react'; import React from 'react';
import ShallowRenderer from 'react-test-renderer/shallow'; import ShallowRenderer from 'react-test-renderer/shallow';
import { apiLocation } from '../../config/env.json'; import { apiLocation } from '../../../config/env.json';
import { ShowSettings } from './ShowSettings'; import { ShowSettings } from './ShowSettings';

View File

@ -4,7 +4,7 @@ import { Grid, Panel, Button } from '@freecodecamp/react-bootstrap';
import Helmet from 'react-helmet'; import Helmet from 'react-helmet';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import env from '../../config/env.json'; import env from '../../../config/env.json';
import FullWidthRow from '../components/helpers/FullWidthRow'; import FullWidthRow from '../components/helpers/FullWidthRow';
import { Spacer } from '../components/helpers'; import { Spacer } from '../components/helpers';

View File

@ -24,10 +24,9 @@ import {
donationUrls, donationUrls,
modalDefaultDonation modalDefaultDonation
} from '../../../../config/donation-settings'; } from '../../../../config/donation-settings';
import { stripePublicKey } from '../../../../config/env.json'; import { stripePublicKey, deploymentEnv } from '../../../../config/env.json';
import { stripeScriptLoader } from '../../utils/scriptLoaders'; import { stripeScriptLoader } from '../../utils/scriptLoaders';
import DonateFormChildViewForHOC from './DonateFormChildViewForHOC'; import DonateFormChildViewForHOC from './DonateFormChildViewForHOC';
import { deploymentEnv } from '../../../config/env.json';
import Spacer from '../helpers/Spacer'; import Spacer from '../helpers/Spacer';
import PaypalButton from './PaypalButton'; import PaypalButton from './PaypalButton';
import DonateCompletion from './DonateCompletion'; import DonateCompletion from './DonateCompletion';

View File

@ -7,7 +7,7 @@ import { createSelector } from 'reselect';
import PayPalButtonScriptLoader from './PayPalButtonScriptLoader'; import PayPalButtonScriptLoader from './PayPalButtonScriptLoader';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import { paypalClientId, deploymentEnv } from '../../../config/env.json'; import { paypalClientId, deploymentEnv } from '../../../../config/env.json';
import { import {
paypalConfigurator, paypalConfigurator,
paypalConfigTypes paypalConfigTypes

View File

@ -6,7 +6,7 @@ import { Button } from '@freecodecamp/react-bootstrap';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { isSignedInSelector } from '../../../redux'; import { isSignedInSelector } from '../../../redux';
import { apiLocation, homeLocation } from '../../../../config/env.json'; import { apiLocation, homeLocation } from '../../../../../config/env.json';
import './login.css'; import './login.css';

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { Link, Spacer } from '../../helpers'; import { Link, Spacer } from '../../helpers';
import { forumLocation } from '../../../../config/env.json'; import { forumLocation } from '../../../../../config/env.json';
import { Trans, useTranslation } from 'react-i18next'; import { Trans, useTranslation } from 'react-i18next';
import '../intro.css'; import '../intro.css';

View File

@ -1,4 +1,4 @@
import { forumLocation } from '../../config/env.json'; import { forumLocation } from '../../../config/env.json';
const createExternalRedirect = (page, { clientLocale }) => { const createExternalRedirect = (page, { clientLocale }) => {
const isNotEnglish = clientLocale !== 'english'; const isNotEnglish = clientLocale !== 'english';

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { apiLocation } from '../../../config/env.json'; import { apiLocation } from '../../../../config/env.json';
const currentChallengeApi = '/challenges/current-challenge'; const currentChallengeApi = '/challenges/current-challenge';

View File

@ -11,7 +11,7 @@ import HeatMap from './components/HeatMap';
import Certifications from './components/Certifications'; import Certifications from './components/Certifications';
import Portfolio from './components/Portfolio'; import Portfolio from './components/Portfolio';
import Timeline from './components/TimeLine'; import Timeline from './components/TimeLine';
import { apiLocation } from '../../../config/env.json'; import { apiLocation } from '../../../../config/env.json';
const propTypes = { const propTypes = {
isSessionUser: PropTypes.bool, isSessionUser: PropTypes.bool,

View File

@ -16,7 +16,7 @@ import Link from '../../helpers/Link';
import './camper.css'; import './camper.css';
import { langCodes } from '../../../../i18n/allLangs'; import { langCodes } from '../../../../i18n/allLangs';
import { clientLocale } from '../../../../config/env'; import { clientLocale } from '../../../../../config/env.json';
const localeCode = langCodes[clientLocale]; const localeCode = langCodes[clientLocale];

View File

@ -16,7 +16,7 @@ import '@freecodecamp/react-calendar-heatmap/dist/styles.css';
import './heatmap.css'; import './heatmap.css';
import { langCodes } from '../../../../i18n/allLangs'; import { langCodes } from '../../../../i18n/allLangs';
import { clientLocale } from '../../../../config/env'; import { clientLocale } from '../../../../../config/env.json';
const localeCode = langCodes[clientLocale]; const localeCode = langCodes[clientLocale];

View File

@ -25,7 +25,7 @@ import { maybeUrlRE } from '../../../utils';
import CertificationIcon from '../../../assets/icons/CertificationIcon'; import CertificationIcon from '../../../assets/icons/CertificationIcon';
import { langCodes } from '../../../../i18n/allLangs'; import { langCodes } from '../../../../i18n/allLangs';
import { clientLocale } from '../../../../config/env'; import { clientLocale } from '../../../../../config/env.json';
const localeCode = langCodes[clientLocale]; const localeCode = langCodes[clientLocale];

View File

@ -15,7 +15,7 @@ import {
toggleSearchDropdown, toggleSearchDropdown,
updateSearchQuery updateSearchQuery
} from './redux'; } from './redux';
import { algoliaAppId, algoliaAPIKey } from '../../../config/env.json'; import { algoliaAppId, algoliaAPIKey } from '../../../../config/env.json';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';

View File

@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import { first } from 'lodash'; import { first } from 'lodash';
import EditorTabs from './EditorTabs'; import EditorTabs from './EditorTabs';
import ActionRow from './ActionRow'; import ActionRow from './ActionRow';
import { showUpcomingChanges } from '../../../../config/env.json'; import { showUpcomingChanges } from '../../../../../config/env.json';
const propTypes = { const propTypes = {
challengeFiles: PropTypes.object, challengeFiles: PropTypes.object,

View File

@ -8,7 +8,7 @@ import { createStructuredSelector } from 'reselect';
import { currentTabSelector, moveToTab } from '../redux'; import { currentTabSelector, moveToTab } from '../redux';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import EditorTabs from './EditorTabs'; import EditorTabs from './EditorTabs';
import { showUpcomingChanges } from '../../../../config/env.json'; import { showUpcomingChanges } from '../../../../../config/env.json';
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
currentTab: currentTabSelector currentTab: currentTabSelector

View File

@ -7,7 +7,7 @@ import { Trans, withTranslation } from 'react-i18next';
import { createQuestion, closeModal, isHelpModalOpenSelector } from '../redux'; import { createQuestion, closeModal, isHelpModalOpenSelector } from '../redux';
import { executeGA } from '../../../redux'; import { executeGA } from '../../../redux';
import { forumLocation } from '../../../../config/env.json'; import { forumLocation } from '../../../../../config/env.json';
import './help-modal.css'; import './help-modal.css';

View File

@ -17,7 +17,7 @@ import createWorker from '../utils/worker-executor';
// the config files are created during the build, but not before linting // the config files are created during the build, but not before linting
// eslint-disable-next-line import/no-unresolved // 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 protectTimeout = 100;
const testProtectTimeout = 1500; const testProtectTimeout = 1500;

View File

@ -10,9 +10,9 @@ import {
// the config files are created during the build, but not before linting // the config files are created during the build, but not before linting
// eslint-disable-next-line import/no-unresolved // 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 // 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 = [ const frameRunner = [
{ {

View File

@ -1,4 +1,4 @@
import { apiLocation } from '../../config/env.json'; import { apiLocation } from '../../../config/env.json';
import axios from 'axios'; import axios from 'axios';
import Tokens from 'csrf'; import Tokens from 'csrf';
import cookies from 'browser-cookies'; import cookies from 'browser-cookies';

View File

@ -1,4 +1,4 @@
const config = require('../../config/env'); const config = require('../../../config/env.json');
const words = require(`../../i18n/locales/${config.clientLocale}/motivation.json`); const words = require(`../../i18n/locales/${config.clientLocale}/motivation.json`);

View File

@ -6,7 +6,7 @@ const {
challengesDir, challengesDir,
getChallengesDirForLang getChallengesDirForLang
} = require('../../curriculum/getChallenges'); } = require('../../curriculum/getChallenges');
const { curriculumLocale } = require('../config/env.json'); const { curriculumLocale } = require('../../config/env.json');
exports.localeChallengesRootDir = getChallengesDirForLang(curriculumLocale); exports.localeChallengesRootDir = getChallengesDirForLang(curriculumLocale);

View File

@ -5,7 +5,7 @@ const { writeFileSync } = require('fs');
module.exports = (env = {}) => { module.exports = (env = {}) => {
const __DEV__ = env.production !== true; const __DEV__ = env.production !== true;
const staticPath = path.join(__dirname, './static/js'); const staticPath = path.join(__dirname, './static/js');
const configPath = path.join(__dirname, './config'); const configPath = path.join(__dirname, '../config/client');
return { return {
mode: __DEV__ ? 'development' : 'production', mode: __DEV__ ? 'development' : 'production',
entry: { entry: {

0
config/client/.gitkeep Normal file
View File

View File

@ -60,7 +60,7 @@ const TRANSLATABLE_COMMENTS = getTranslatableComments(
path.resolve(__dirname, '..', 'dictionaries') path.resolve(__dirname, '..', 'dictionaries')
); );
const testEvaluator = require('../../client/config/test-evaluator').filename; const testEvaluator = require('../../config/client/test-evaluator').filename;
const commentExtractors = { const commentExtractors = {
html: require('./utils/extract-html-comments'), html: require('./utils/extract-html-comments'),

View File

@ -4,7 +4,6 @@ const path = require('path');
const env = require('../../../config/env'); const env = require('../../../config/env');
const { availableLangs } = require('../../../client/i18n/allLangs'); const { availableLangs } = require('../../../client/i18n/allLangs');
const clientPath = path.resolve(__dirname, '../../../client');
const globalConfigPath = path.resolve(__dirname, '../../../config'); const globalConfigPath = path.resolve(__dirname, '../../../config');
const { FREECODECAMP_NODE_ENV } = process.env; const { FREECODECAMP_NODE_ENV } = process.env;
@ -104,5 +103,4 @@ if (FREECODECAMP_NODE_ENV !== 'development') {
checkCurriculumLocale(); checkCurriculumLocale();
} }
fs.writeFileSync(`${clientPath}/config/env.json`, JSON.stringify(env));
fs.writeFileSync(`${globalConfigPath}/env.json`, JSON.stringify(env)); fs.writeFileSync(`${globalConfigPath}/env.json`, JSON.stringify(env));