Skip to content

Commit 7216ca5

Browse files
refactor: organise TypeScript config and migrate helpers (freeCodeCamp#44747)
* feat: allow more 1000 steps to be created at once * refactor: start migrating to typescript * refactor: delete-step to ts * refactor: migrated some helpers * refactor: migrate create-empty-steps * refactor: migrate create-step-between * refactor: finish migrating to TS * refactor: migrate tests * fix: ensure mock.restore is done after each test * fix: prevent double-tscing * fix: repair the tests * chore: use ts-node for scripts We don't need the performance boost of incremental compilation and ts-node is easier to work with * refactor: consolidate tsconfigs * refactor: replace gulp * fix: use ts-node for build-curriculum * fix: allow ts compilation of config * feat: create and use create:config script * fix: add /config to eslint projects * fix: remove gulp script
1 parent 82ca6d8 commit 7216ca5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+444
-4287
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@ client/static/**
33
client/public/**
44
api-server/src/public/**
55
api-server/lib/**
6-
tools/scripts/build/ensure-env.js
7-
tools/scripts/lint/validate-keys.js
8-
tools/scripts/build/tsconfig.tsbuildinfo
96
config/i18n/all-langs.js
107
config/certification-settings.js

.eslintrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"parserOptions": {
4444
"project": [
4545
"./tsconfig.json",
46-
"./tools/ui-components/tsconfig.json",
47-
"./tools/tsconfig.json"
46+
"./config/tsconfig.json",
47+
"./tools/ui-components/tsconfig.json"
4848
]
4949
},
5050
"extends": [

.github/workflows/cypress.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
- name: Install and Build
114114
run: |
115115
npm ci
116-
npm run ensure-env
116+
npm run create:config
117117
npm run build:curriculum
118118
npm run build:server
119119

.github/workflows/node.js-tests-upcoming.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: Lint Source Files
4040
run: |
4141
npm ci
42-
npm run ensure-env
42+
npm run create:config
4343
npm run build:curriculum
4444
npm run lint
4545
@@ -73,7 +73,7 @@ jobs:
7373
- name: Install Dependencies
7474
run: |
7575
npm ci
76-
npm run ensure-env
76+
npm run create:config
7777
npm run build:curriculum
7878
7979
- name: Run Tests

.github/workflows/node.js-tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Lint Source Files
3434
run: |
3535
npm ci
36-
npm run ensure-env
36+
npm run create:config
3737
npm run build:curriculum
3838
npm run lint
3939
@@ -66,7 +66,7 @@ jobs:
6666
- name: Install Dependencies
6767
run: |
6868
npm ci
69-
npm run ensure-env
69+
npm run create:config
7070
npm run build:curriculum
7171
7272
- name: Run Tests
@@ -102,7 +102,7 @@ jobs:
102102
- name: Install Dependencies
103103
run: |
104104
npm ci
105-
npm run ensure-env
105+
npm run create:config
106106
npm run build:curriculum
107107
108108
- name: Run Tests
@@ -142,7 +142,7 @@ jobs:
142142
CLIENT_LOCALE: ${{ matrix.locale }}
143143
run: |
144144
npm ci
145-
npm run ensure-env
145+
npm run create:config
146146
npm run build:curriculum
147147
148148
- name: Run Tests

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ config/curriculum.json
165165
config/i18n/all-langs.js
166166
config/certification-settings.js
167167

168-
tools/scripts/build/ensure-env.js
169-
tools/tsconfig.tsbuildinfo
170-
tools/scripts/lint/validate-keys.js
171168

172169
### vim ###
173170
# Swap

.gitpod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tasks:
4343
npm run seed &&
4444
mongo --eval "db.fsyncLock(); db.fsyncUnlock()"
4545
command: >
46-
npm run ensure-env &&
46+
npm run create:config &&
4747
npm run build:curriculum &&
4848
gp await-port 27017 &&
4949
npm run develop:server

.prettierignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@ config/certification-settings.js
1010
client/i18n/**/*.json
1111
docs/i18n
1212
**/package-lock.json
13-
tools/scripts/build/ensure-env.js
14-
tools/scripts/lint/validate-keys.js

client.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ USER node
2121
WORKDIR /home/node/build
2222
COPY --chown=node:node . .
2323
RUN npm ci
24-
# we don't need to separately run ensure-env, since it gets called as part of
24+
# we don't need to separately run create:config, since it gets called as part of
2525
# build:client
2626
RUN npm run build:client
2727

client/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
"author": "freeCodeCamp <[email protected]>",
2020
"main": "none",
2121
"scripts": {
22-
"prebuild": "tsc -p ../tools/ && node ../tools/scripts/build/ensure-env.js && npm run build:workers -- --env production",
22+
"prebuild": "npm --prefix ../ run create:config && npm run build:workers -- --env production",
2323
"build": "cross-env NODE_OPTIONS=\"--max-old-space-size=7168\" gatsby build --prefix-paths",
2424
"build:workers": "cross-env NODE_OPTIONS=\"--max-old-space-size=7168\" webpack --config ./webpack-workers.js",
2525
"clean": "gatsby clean",
26-
"predevelop": "tsc -p ../tools/ && node ../tools/scripts/build/ensure-env.js && npm run build:workers -- --env development",
26+
"predevelop": "npm --prefix ../ run create:config && npm run build:workers -- --env development",
2727
"develop": "cross-env NODE_OPTIONS=\"--max-old-space-size=5000\" gatsby develop --inspect=9230",
2828
"lint": "node ./i18n/schema-validation.js",
2929
"serve": "gatsby serve -p 8000",
3030
"serve-ci": "serve -l 8000 -c ../serve.json public",
3131
"prestand-alone": "npm run prebuild",
3232
"stand-alone": "gatsby develop",
33-
"validate-keys": "tsc -p ../tools/ && node ../tools/scripts/lint/validate-keys.js"
33+
"validate-keys": "ts-node --project ../tsconfig.json ../tools/scripts/lint/validate-keys"
3434
},
3535
"dependencies": {
3636
"@babel/plugin-proposal-export-default-from": "7.16.7",
@@ -145,6 +145,7 @@
145145
"redux-mock-store": "1.5.4",
146146
"redux-saga-test-plan": "4.0.4",
147147
"serve": "13.0.2",
148+
"ts-node": "^10.4.0",
148149
"webpack": "5.67.0",
149150
"webpack-cli": "4.9.2"
150151
}

config/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"include": ["**/*.ts"],
3+
"extends": "../tsconfig-base.json",
4+
"compilerOptions": {
5+
"noEmit": false,
6+
"module": "CommonJS"
7+
}
8+
}

curriculum/gulpfile.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

curriculum/lint-localized.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var glob = require('glob');
2+
const lint = require('../tools/scripts/lint');
3+
const { testedLang } = require('./utils');
4+
5+
glob(`challenges/${testedLang()}/**/*.md`, (err, files) => {
6+
if (!files.length) throw Error('No files found');
7+
files.forEach(file => lint({ path: file }));
8+
});

curriculum/package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
"homepage": "https://github.com/freeCodeCamp/freeCodeCamp#readme",
1919
"author": "freeCodeCamp <[email protected]>",
2020
"scripts": {
21-
"build": "node ../tools/scripts/build/build-curriculum.js",
22-
"create-empty-steps": "cross-env CALLING_DIR=$INIT_CWD node ../tools/challenge-helper-scripts/create-empty-steps",
23-
"create-next-step": "cross-env CALLING_DIR=$INIT_CWD node ../tools/challenge-helper-scripts/create-next-step",
24-
"create-step-between": "cross-env CALLING_DIR=$INIT_CWD node ../tools/challenge-helper-scripts/create-step-between",
25-
"delete-step": "cross-env CALLING_DIR=$INIT_CWD node ../tools/challenge-helper-scripts/delete-step",
26-
"lint": "gulp lint",
27-
"reorder-steps": "cross-env CALLING_DIR=$INIT_CWD node ../tools/challenge-helper-scripts/reorder-steps",
21+
"build": "ts-node --project ../tsconfig.json ../tools/scripts/build/build-curriculum",
22+
"create-empty-steps": "cross-env CALLING_DIR=$INIT_CWD ts-node --project ../tsconfig.json ../tools/challenge-helper-scripts/create-empty-steps",
23+
"create-next-step": "cross-env CALLING_DIR=$INIT_CWD ts-node --project ../tsconfig.json ../tools/challenge-helper-scripts/create-next-step",
24+
"create-step-between": "cross-env CALLING_DIR=$INIT_CWD ts-node --project ../tsconfig.json ../tools/challenge-helper-scripts/create-step-between",
25+
"delete-step": "cross-env CALLING_DIR=$INIT_CWD ts-node --project ../tsconfig.json ../tools/challenge-helper-scripts/delete-step",
26+
"lint": "ts-node --project ../tsconfig.json lint-localized",
27+
"reorder-steps": "cross-env CALLING_DIR=$INIT_CWD ts-node --project ../tsconfig.json ../tools/challenge-helper-scripts/reorder-steps",
2828
"test": "mocha --delay --exit --reporter progress --bail",
2929
"test:full-output": "cross-env FULL_OUTPUT=true mocha --delay --reporter progress"
3030
},
@@ -45,7 +45,6 @@
4545
"chai": "4.3.4",
4646
"cross-env": "7.0.3",
4747
"css": "3.0.0",
48-
"gulp": "4.0.2",
4948
"invariant": "2.2.4",
5049
"joi": "17.5.0",
5150
"joi-objectid": "3.0.1",

docs/devops.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ Provisioning VMs with the Code
482482
7. Build the server
483483

484484
```console
485-
npm run ensure-env && npm run build:curriculum && npm run build:server
485+
npm run create:config && npm run build:curriculum && npm run build:server
486486
```
487487

488488
8. Start Instances
@@ -528,7 +528,7 @@ npm ci
528528
3. Build the server
529529

530530
```console
531-
npm run ensure-env && npm run build:curriculum && npm run build:server
531+
npm run create:config && npm run build:curriculum && npm run build:server
532532
```
533533

534534
4. Start Instances

docs/how-to-work-on-localized-client-webapp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Most of files for translating the platform are located in the [`client/i18n`](ht
1919

2020
```console
2121
config/i18n
22-
└── all-langs.js
22+
└── all-langs.ts
2323
...
2424
client/i18n
2525
├── configForTests.js
@@ -57,7 +57,7 @@ Most of files for translating the platform are located in the [`client/i18n`](ht
5757
│   └── trending.json
5858
├── locales.test.js
5959
├── schema-validation.js
60-
└── validate-keys.js
60+
└── validate-keys.ts
6161
```
6262

6363
Some of these files are translated on our translation platform (Crowdin), some are not.

0 commit comments

Comments
 (0)