diff --git a/.gitpod.yml b/.gitpod.yml index ec983467b83..e2a45901b97 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -48,8 +48,6 @@ tasks: gp sync-done pnpm-install && gp ports await 27017 command: > - pnpm run create:config && - pnpm run build:curriculum && pnpm run seed && mongosh --eval "db.fsyncLock(); db.fsyncUnlock()" && gp ports await 27017 && @@ -60,12 +58,10 @@ tasks: init: > cd ./client && gp sync-await pnpm-install && - pnpm run predevelop && cd .. command: > gp ports await 3000 && - cd ./client && - pnpm run develop -- -H '0.0.0.0' + pnpm run develop:client -- -H '0.0.0.0' openMode: split-right github: diff --git a/client/package.json b/client/package.json index ef6b5aeb870..66858b7f352 100644 --- a/client/package.json +++ b/client/package.json @@ -19,11 +19,14 @@ "author": "freeCodeCamp ", "main": "none", "scripts": { - "prebuild": "pnpm -w run create:config && pnpm run build:scripts --env production && pnpm run build:components-library", + "prebuild": "pnpm run common-setup && pnpm run build:scripts --env production", "build": "cross-env NODE_OPTIONS=\"--max-old-space-size=7168\" gatsby build --prefix-paths", "build:scripts": "pnpm run -F=browser-scripts build", "clean": "gatsby clean", - "predevelop": "pnpm run build:scripts --env development && pnpm run build:components-library", + "common-setup": "pnpm -w run create:config && pnpm run create:env && pnpm run create:trending && pnpm run build:components-library", + "create:env": "cross-env DEBUG=fcc:* ts-node ./tools/create-env.ts", + "create:trending": "ts-node ./tools/download-trending.ts", + "predevelop": "pnpm run common-setup && pnpm run build:scripts --env development", "build:components-library": "pnpm run -F=@freecodecamp/ui build", "develop": "cross-env NODE_OPTIONS=\"--max-old-space-size=5000\" gatsby develop --inspect=9230", "lint": "ts-node ./i18n/schema-validation.ts", @@ -147,8 +150,10 @@ "@types/enzyme-adapter-react-16": "1.0.6", "@types/jest": "29.5.3", "@types/jquery": "^3.5.16", + "@types/js-yaml": "4.0.5", "@types/loadable__component": "5.13.4", "@types/lodash-es": "^4.17.6", + "@types/node-fetch": "2", "@types/prismjs": "^1.26.0", "@types/reach__router": "1.3.11", "@types/react": "16.14.43", @@ -174,12 +179,16 @@ "chokidar": "3.5.3", "copy-webpack-plugin": "9.1.0", "core-js": "2.6.12", + "cross-env": "7.0.3", "dotenv": "16.3.1", "eslint-plugin-testing-library": "^3.9.0", "gatsby-plugin-webpack-bundle-analyser-v2": "1.1.31", "jest-environment-jsdom": "29.6.2", "jest-json-schema-extended": "1.0.1", + "joi": "17.9.2", + "js-yaml": "4.1.0", "monaco-editor-webpack-plugin": "4.2.0", + "node-fetch": "2.6.12", "react-test-renderer": "16.14.0", "redux-mock-store": "1.5.4", "redux-saga-test-plan": "4.0.6", diff --git a/tools/scripts/build/ensure-env.ts b/client/tools/create-env.ts similarity index 95% rename from tools/scripts/build/ensure-env.ts rename to client/tools/create-env.ts index 53eef16a3fb..9e4bfd857e6 100644 --- a/tools/scripts/build/ensure-env.ts +++ b/client/tools/create-env.ts @@ -2,10 +2,10 @@ import { spawn } from 'child_process'; import * as fs from 'fs'; import * as path from 'path'; -import { availableLangs, Languages } from '../../../config/i18n'; -import env from '../../../config/read-env'; +import { availableLangs, Languages } from '../../config/i18n'; +import env from './read-env'; -const globalConfigPath = path.resolve(__dirname, '../../../config'); +const globalConfigPath = path.resolve(__dirname, '../../config'); const { FREECODECAMP_NODE_ENV } = process.env; diff --git a/tools/scripts/build/download-trending.ts b/client/tools/download-trending.ts similarity index 91% rename from tools/scripts/build/download-trending.ts rename to client/tools/download-trending.ts index e2a39e98a4e..77b5709229c 100644 --- a/tools/scripts/build/download-trending.ts +++ b/client/tools/download-trending.ts @@ -7,7 +7,7 @@ import { config } from 'dotenv'; import { trendingSchemaValidator } from './schema/trending-schema'; -config({ path: path.resolve(__dirname, '../../../.env') }); +config({ path: path.resolve(__dirname, '../../.env') }); const createCdnUrl = (lang: string) => `https://cdn.freecodecamp.org/universal/trending/${lang}.yaml`; @@ -28,7 +28,10 @@ const download = async (clientLocale: string) => { const data = await res.text(); const trendingJSON = JSON.stringify(yaml.load(data)); - const trendingLocation = `./client/i18n/locales/${clientLocale}/trending.json`; + const trendingLocation = path.resolve( + __dirname, + `../i18n/locales/${clientLocale}/trending.json` + ); writeFileSync(trendingLocation, trendingJSON); const trendingObject = JSON.parse(trendingJSON) as Record; diff --git a/config/read-env.js b/client/tools/read-env.ts similarity index 92% rename from config/read-env.js rename to client/tools/read-env.ts index 50d07fbb1e5..e0dce174997 100644 --- a/config/read-env.js +++ b/client/tools/read-env.ts @@ -1,7 +1,8 @@ -const path = require('path'); +import path from 'path'; +import { config } from 'dotenv'; -const envPath = path.resolve(__dirname, '../.env'); -const { error } = require('dotenv').config({ path: envPath }); +const envPath = path.resolve(__dirname, '../../.env'); +const { error } = config({ path: envPath }); if (error) { console.warn(` @@ -47,7 +48,7 @@ const locations = { : radioLocation }; -module.exports = Object.assign(locations, { +export default Object.assign(locations, { clientLocale, curriculumLocale, showLocaleDropdownMenu: showLocaleDropdownMenu === 'true', diff --git a/tools/scripts/build/schema/trending-schema.ts b/client/tools/schema/trending-schema.ts similarity index 100% rename from tools/scripts/build/schema/trending-schema.ts rename to client/tools/schema/trending-schema.ts diff --git a/client/tsconfig.json b/client/tsconfig.json index 441cb64d66b..819182eaea5 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -15,5 +15,18 @@ "resolveJsonModule": true, "skipLibCheck": true }, - "include": ["i18n/**/*", "plugins/**/*", "src/**/*", "utils/**/*"] + "include": [ + "i18n/**/*", + "plugins/**/*", + "src/**/*", + "utils/**/*", + "tools/**/*" + ], // since ts-node compiles ts on the fly and then uses node, it needs to + // compile the scripts to commonjs (or node will complain about the requires) + "ts-node": { + "compilerOptions": { + "module": "commonjs" + }, + "transpileOnly": true + } } diff --git a/package.json b/package.json index 07d85064b40..4568dd24aaf 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "clean:curriculum": "rm -rf ./config/curriculum.json", "clean:packages": "rm -rf ./node_modules ./**/node_modules", "clean:server": "rm -rf ./api-server/lib", - "create:config": "tsc -p config && pnpm run ensure-env && pnpm run download-trending", + "create:config": "tsc -p config", "create:utils": "tsc -p utils", "precypress": "node ./cypress-install.js", "cypress": "cypress", @@ -55,8 +55,6 @@ "e2e:dev:watch": "start-test develop 'localhost:3000/status/ping|localhost:8000' cypress:dev:watch", "e2e:prd:run": "pnpm run build && start-test 'localhost:3000/status/ping|localhost:8000' cypress:dev:run", "e2e:prd:watch": "pnpm run build && start-test 'localhost:3000/status/ping|localhost:8000' cypress:dev:watch", - "download-trending": "ts-node ./tools/scripts/build/download-trending.ts", - "ensure-env": "cross-env DEBUG=fcc:* ts-node ./tools/scripts/build/ensure-env.ts", "format": "run-s format:eslint format:prettier", "format:curriculum": "run-s format:curriculum:eslint format:curriculum:prettier", "format:curriculum:eslint": "eslint ./curriculum --fix", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0019d544cf8..909aa95ed71 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -798,12 +798,18 @@ importers: '@types/jquery': specifier: ^3.5.16 version: 3.5.16 + '@types/js-yaml': + specifier: 4.0.5 + version: 4.0.5 '@types/loadable__component': specifier: 5.13.4 version: 5.13.4 '@types/lodash-es': specifier: ^4.17.6 version: 4.17.6 + '@types/node-fetch': + specifier: '2' + version: 2.6.4 '@types/prismjs': specifier: ^1.26.0 version: 1.26.0 @@ -879,6 +885,9 @@ importers: core-js: specifier: 2.6.12 version: 2.6.12 + cross-env: + specifier: 7.0.3 + version: 7.0.3 dotenv: specifier: 16.3.1 version: 16.3.1 @@ -894,9 +903,18 @@ importers: jest-json-schema-extended: specifier: 1.0.1 version: 1.0.1 + joi: + specifier: 17.9.2 + version: 17.9.2 + js-yaml: + specifier: 4.1.0 + version: 4.1.0 monaco-editor-webpack-plugin: specifier: 4.2.0 version: 4.2.0(monaco-editor@0.28.1)(webpack@5.88.2) + node-fetch: + specifier: 2.6.12 + version: 2.6.12 react-test-renderer: specifier: 16.14.0 version: 16.14.0(react@16.14.0) @@ -1326,30 +1344,12 @@ importers: tools/scripts/build: devDependencies: - '@types/js-yaml': - specifier: 4.0.5 - version: 4.0.5 - '@types/node-fetch': - specifier: 2.6.4 - version: 2.6.4 chai: specifier: 4.3.7 version: 4.3.7 - debug: - specifier: 4.3.4 - version: 4.3.4(supports-color@8.1.1) - dotenv: - specifier: 16.3.1 - version: 16.3.1 joi: specifier: 17.9.2 version: 17.9.2 - js-yaml: - specifier: 4.1.0 - version: 4.1.0 - node-fetch: - specifier: 2.6.12 - version: 2.6.12 readdirp: specifier: 3.6.0 version: 3.6.0 @@ -11382,7 +11382,7 @@ packages: /@types/node-fetch@2.6.4: resolution: {integrity: sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg==} dependencies: - '@types/node': 18.16.0 + '@types/node': 18.17.1 form-data: 3.0.1 /@types/node@10.17.60: @@ -11408,6 +11408,7 @@ packages: /@types/node@18.16.0: resolution: {integrity: sha512-BsAaKhB+7X+H4GnSjGhJG9Qi8Tw+inU9nJDwmD5CgOmBLEI6ArdhikpLX7DjbjDRDTbqZzU2LSQNZg8WGPiSZQ==} + dev: true /@types/node@18.17.0: resolution: {integrity: sha512-GXZxEtOxYGFchyUzxvKI14iff9KZ2DI+A6a37o6EQevtg6uO9t+aUZKcaC1Te5Ng1OnLM7K9NVVj+FbecD9cJg==} @@ -16926,6 +16927,7 @@ packages: dependencies: ms: 2.1.3 supports-color: 8.1.1 + dev: true /debug@4.3.1: resolution: {integrity: sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==} @@ -17256,7 +17258,7 @@ packages: '@types/tmp': 0.0.33 application-config-path: 0.1.1 command-exists: 1.2.9 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) eol: 0.9.1 get-port: 3.2.0 glob: 7.2.3 @@ -18179,7 +18181,7 @@ packages: /eslint-import-resolver-node@0.3.7: resolution: {integrity: sha512-gozW2blMLJCeFpBwugLTGyvVjNoeo1knonXAcatC6bjPBZitotxdWf7Gimr25N4c0AAOo4eOUfaG82IJPDpqCA==} dependencies: - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) is-core-module: 2.12.1 resolve: 1.22.2 transitivePeerDependencies: @@ -18230,7 +18232,7 @@ packages: optional: true dependencies: '@typescript-eslint/parser': 4.33.0(eslint@7.32.0)(typescript@4.9.5) - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) eslint: 7.32.0 eslint-import-resolver-node: 0.3.7 eslint-import-resolver-typescript: 3.5.5(@typescript-eslint/parser@5.62.0)(eslint-plugin-import@2.28.0)(eslint@8.46.0) @@ -18259,7 +18261,7 @@ packages: optional: true dependencies: '@typescript-eslint/parser': 5.62.0(eslint@8.46.0)(typescript@4.9.5) - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) eslint: 8.46.0 eslint-import-resolver-typescript: 3.5.5(@typescript-eslint/parser@5.62.0)(eslint-plugin-import@2.28.0)(eslint@8.46.0) transitivePeerDependencies: @@ -18287,7 +18289,7 @@ packages: optional: true dependencies: '@typescript-eslint/parser': 5.62.0(eslint@8.46.0)(typescript@4.9.5) - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) eslint: 8.46.0 eslint-import-resolver-node: 0.3.7 eslint-import-resolver-typescript: 3.5.5(@typescript-eslint/parser@5.62.0)(eslint-plugin-import@2.28.0)(eslint@8.46.0) @@ -18361,7 +18363,7 @@ packages: array-includes: 3.1.6 array.prototype.flat: 1.3.1 array.prototype.flatmap: 1.3.1 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) doctrine: 2.1.0 eslint: 7.32.0 eslint-import-resolver-node: 0.3.7 @@ -18394,7 +18396,7 @@ packages: array.prototype.findlastindex: 1.2.2 array.prototype.flat: 1.3.1 array.prototype.flatmap: 1.3.1 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) doctrine: 2.1.0 eslint: 8.46.0 eslint-import-resolver-node: 0.3.7 @@ -19384,7 +19386,7 @@ packages: fastify-plugin: 4.5.0 http-errors: 2.0.0 node-cache: 5.1.2 - node-fetch: 2.6.9 + node-fetch: 2.6.12 transitivePeerDependencies: - encoding dev: false @@ -19690,7 +19692,6 @@ packages: optional: true dependencies: debug: 2.2.0 - dev: false /follow-redirects@1.15.2(debug@3.2.7): resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==} @@ -19701,7 +19702,7 @@ packages: debug: optional: true dependencies: - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) /follow-redirects@1.15.2(debug@4.3.4): resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==} @@ -20063,7 +20064,7 @@ packages: joi: 17.9.2 lodash: 4.17.21 meant: 1.0.3 - node-fetch: 2.6.9 + node-fetch: 2.6.12 opentracing: 0.14.7 pretty-error: 2.1.2 progress: 2.0.3 @@ -20523,7 +20524,7 @@ packages: css-minimizer-webpack-plugin: 2.0.0(webpack@5.88.2) css.escape: 1.5.1 date-fns: 2.30.0 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) deepmerge: 4.3.0 del: 5.1.0 detect-port: 1.5.1 @@ -24720,7 +24721,7 @@ packages: dependencies: async: 0.9.2 commondir: 1.0.1 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) lodash: 4.17.21 semver: 5.7.1 strong-globalize: 4.1.3 @@ -24733,7 +24734,7 @@ packages: resolution: {integrity: sha512-vDRR4gqkvGOEXh5yL383xGuGxUW9xtF+NCY6/lJu1VAgupKltZxEx3Vw+L3nsGvQrlkJTSmiK3jk72qxkoBtbw==} engines: {node: '>=6'} dependencies: - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) lodash: 4.17.21 loopback-swagger: 5.9.0 strong-globalize: 4.1.3 @@ -24748,7 +24749,7 @@ packages: dependencies: async: 2.6.4 bson: 1.1.6 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) loopback-connector: 4.11.1 mongodb: 3.6.9 strong-globalize: 4.1.3 @@ -24792,7 +24793,7 @@ packages: dependencies: async: 2.6.4 bluebird: 3.7.2 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) depd: 1.1.2 inflection: 1.13.4 lodash: 4.17.21 @@ -24816,7 +24817,7 @@ packages: resolution: {integrity: sha512-p0qSzuuX7eATe5Bxy+RqCj3vSfSFfdCtqyf3yuC+DpchMvgal33XlhEi2UmywyK/Ym28oVnZxxWmfrwFMzSwLQ==} engines: {node: '>=4.0.0'} dependencies: - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) transitivePeerDependencies: - supports-color dev: false @@ -24826,7 +24827,7 @@ packages: engines: {node: '>=8.9'} dependencies: async: 2.6.4 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) strong-globalize: 4.1.3 transitivePeerDependencies: - supports-color @@ -24837,7 +24838,7 @@ packages: engines: {node: '>=8'} dependencies: async: 2.6.4 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) ejs: 2.7.4 lodash: 4.17.21 strong-globalize: 4.1.3 @@ -26542,6 +26543,7 @@ packages: optional: true dependencies: whatwg-url: 5.0.0 + dev: false /node-forge@1.3.1: resolution: {integrity: sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==} @@ -34488,7 +34490,7 @@ packages: /webpack-virtual-modules@0.2.2: resolution: {integrity: sha512-kDUmfm3BZrei0y+1NTHJInejzxfhtU8eDj2M7OKb2IWrPFAeO1SOH2KuQ68MSZu9IGEHcxbkKKR1v18FrUSOmA==} dependencies: - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) transitivePeerDependencies: - supports-color dev: true @@ -34496,7 +34498,7 @@ packages: /webpack-virtual-modules@0.3.2: resolution: {integrity: sha512-RXQXioY6MhzM4CNQwmBwKXYgBs6ulaiQ8bkNQEl2J6Z+V+s7lgl/wGvaI/I0dLnYKB8cKsxQc17QOAVIphPLDw==} dependencies: - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) transitivePeerDependencies: - supports-color diff --git a/tools/scripts/build/package.json b/tools/scripts/build/package.json index e140c753433..42705f93a1f 100644 --- a/tools/scripts/build/package.json +++ b/tools/scripts/build/package.json @@ -19,14 +19,8 @@ "author": "freeCodeCamp ", "main": "none", "devDependencies": { - "@types/js-yaml": "4.0.5", - "@types/node-fetch": "2.6.4", "chai": "4.3.7", - "debug": "4.3.4", - "dotenv": "16.3.1", "joi": "17.9.2", - "js-yaml": "4.1.0", - "node-fetch": "2.6.12", "readdirp": "3.6.0" } }