diff --git a/.eslintrc.json b/.eslintrc.json index 50dad0fcabea43..06a94aa018f478 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -45,7 +45,8 @@ "project": [ "./tsconfig.json", "./config/tsconfig.json", - "./tools/ui-components/tsconfig.json" + "./tools/ui-components/tsconfig.json", + "./utils/tsconfig.json" ] }, "extends": [ diff --git a/.gitignore b/.gitignore index 5949a11c4fcbc7..c7d58b52a5f456 100644 --- a/.gitignore +++ b/.gitignore @@ -165,6 +165,9 @@ config/curriculum.json config/i18n/all-langs.js config/certification-settings.js +### Generated utils files ### +utils/slugs.js +utils/slugs.test.js ### vim ### # Swap diff --git a/.prettierignore b/.prettierignore index 43b14598a2d6c4..072c0e392f9b67 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,4 +9,6 @@ config/i18n/all-langs.js config/certification-settings.js client/i18n/**/*.json docs/i18n +utils/slugs.js +utils/slugs.test.js **/package-lock.json diff --git a/package.json b/package.json index 198d2e45ca7726..0d334fd3d42b87 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ ], "scripts": { "analyze-bundle": "webpack-bundle-analyzer", - "prebuild": "npm run create:config", + "prebuild": "npm-run-all create:*", "build": "npm-run-all -p build:*", "build-workers": "cd ./client && npm run prebuild", "build:client": "cd ./client && npm run build", @@ -46,6 +46,7 @@ "clean:packages": "rimraf ./**/node_modules", "clean:server": "rimraf ./api-server/lib", "create:config": "tsc -p config && npm run ensure-env", + "create:utils": "tsc -p utils", "precypress": "node ./cypress-install.js", "cypress": "cypress", "cypress:dev:run": "npm run cypress -- run", @@ -54,7 +55,7 @@ "cypress:install-build-tools": "sh ./cypress-install.sh", "cypress:prd:run": "npm run cypress -- run", "cypress:prd:watch": "npm run cypress -- open", - "predevelop": "npm run create:config", + "predevelop": "npm-run-all create:*", "develop": "npm-run-all build:curriculum -p develop:*", "develop:client": "npm run build:curriculum && cd ./client && npm run develop", "develop:server": "npm run predevelop && cd ./api-server && npm run develop", @@ -70,20 +71,20 @@ "format:prettier": "prettier --write .", "hooks:install": "node node_modules/husky/husky.js install", "hooks:uninstall": "node node_modules/husky/husky.js uninstall", - "lint": "npm-run-all create:config -p lint:*", + "lint": "npm-run-all create:* -p lint:*", "lint:challenges": "cd ./curriculum && npm run lint", "lint:js": "eslint --max-warnings 0 .", - "lint:ts": "tsc && tsc -p config && tsc -p tools/ui-components", + "lint:ts": "tsc && tsc -p config && tsc -p tools/ui-components && tsc -p utils", "lint:prettier": "prettier --list-different .", "seed": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser", "seed:certified-user": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser certUser", "serve:client": "cd ./client && npm run serve", "serve:client-ci": "cd ./client && npm run serve-ci", - "start": "npm-run-all create:config -p develop:server serve:client", - "start-ci": "npm-run-all create:config -p start:server serve:client-ci", + "start": "npm-run-all create:* -p develop:server serve:client", + "start-ci": "npm-run-all create:* -p start:server serve:client-ci", "start:server": "cd ./api-server && npm start", "storybook": "cd ./tools/ui-components && npm run storybook", - "test": "run-s create:config build:curriculum build-workers test:*", + "test": "run-s create:* build:curriculum build-workers test:*", "test:source": "jest", "test:curriculum": "cd ./curriculum && npm test", "test-curriculum-full-output": "cd ./curriculum && npm run test:full-output", diff --git a/utils/slugs.test.js b/utils/slugs.test.ts similarity index 92% rename from utils/slugs.test.js rename to utils/slugs.test.ts index 8e37e601f35eb9..26a41635cf1050 100644 --- a/utils/slugs.test.js +++ b/utils/slugs.test.ts @@ -1,7 +1,6 @@ -const slugs = require('./slugs'); +import { dasherize, nameify, unDasherize } from './slugs'; describe('dasherize', () => { - const { dasherize } = slugs; it('returns a string', () => { expect(dasherize('')).toBe(''); }); @@ -26,7 +25,6 @@ describe('dasherize', () => { }); describe('nameify', () => { - const { nameify } = slugs; it('returns a string', () => { expect(nameify('')).toBe(''); }); @@ -36,7 +34,6 @@ describe('nameify', () => { }); describe('unDasherize', () => { - const { unDasherize } = slugs; it('returns a string', () => { expect(unDasherize('')).toBe(''); }); diff --git a/utils/slugs.js b/utils/slugs.ts similarity index 66% rename from utils/slugs.js rename to utils/slugs.ts index 85fe8ff9c30dcc..c4567d32cc1cd6 100644 --- a/utils/slugs.js +++ b/utils/slugs.ts @@ -1,16 +1,16 @@ -exports.dasherize = function dasherize(name) { +function dasherize(name: string): string { return ('' + name) .toLowerCase() .trim() .replace(/\s|\./g, '-') .replace(/[^a-z\d\-.]/g, ''); -}; +} -exports.nameify = function nameify(str) { +function nameify(str: string): string { return ('' + str).replace(/[^a-z\d\s]/gi, ''); -}; +} -exports.unDasherize = function unDasherize(name) { +function unDasherize(name: string): string { return ( ('' + name) // replace dash with space @@ -19,4 +19,6 @@ exports.unDasherize = function unDasherize(name) { .replace(/[^a-z\d\s]/gi, '') .trim() ); -}; +} + +export { dasherize, nameify, unDasherize }; diff --git a/utils/tsconfig.json b/utils/tsconfig.json new file mode 100644 index 00000000000000..70c136a33a0bef --- /dev/null +++ b/utils/tsconfig.json @@ -0,0 +1,9 @@ +{ + "include": ["**/*.ts", "**/*.test.ts"], + "exclude": ["./__fixtures__"], + "extends": "../tsconfig-base.json", + "compilerOptions": { + "noEmit": false, + "module": "CommonJS" + } +}