chore(utils): ts-migration of utils/slugs (#44921)

* chore: utils is added in the tsconfig

* test(util): test and test function is updated to typescript

* chore: add tsconfig for utils

* fix: exclude files importing from client/

* fix: refactor to just export functions

* chore: add emitted files to prettierignore

* fix: add new tsconfig to eslint project

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
palash-signoz
2022-03-29 21:21:13 +05:30
committed by GitHub
parent 0a3690572c
commit 004c5b6fb6
7 changed files with 33 additions and 18 deletions

View File

@ -45,7 +45,8 @@
"project": [ "project": [
"./tsconfig.json", "./tsconfig.json",
"./config/tsconfig.json", "./config/tsconfig.json",
"./tools/ui-components/tsconfig.json" "./tools/ui-components/tsconfig.json",
"./utils/tsconfig.json"
] ]
}, },
"extends": [ "extends": [

3
.gitignore vendored
View File

@ -165,6 +165,9 @@ config/curriculum.json
config/i18n/all-langs.js config/i18n/all-langs.js
config/certification-settings.js config/certification-settings.js
### Generated utils files ###
utils/slugs.js
utils/slugs.test.js
### vim ### ### vim ###
# Swap # Swap

View File

@ -9,4 +9,6 @@ config/i18n/all-langs.js
config/certification-settings.js config/certification-settings.js
client/i18n/**/*.json client/i18n/**/*.json
docs/i18n docs/i18n
utils/slugs.js
utils/slugs.test.js
**/package-lock.json **/package-lock.json

View File

@ -33,7 +33,7 @@
], ],
"scripts": { "scripts": {
"analyze-bundle": "webpack-bundle-analyzer", "analyze-bundle": "webpack-bundle-analyzer",
"prebuild": "npm run create:config", "prebuild": "npm-run-all create:*",
"build": "npm-run-all -p build:*", "build": "npm-run-all -p build:*",
"build-workers": "cd ./client && npm run prebuild", "build-workers": "cd ./client && npm run prebuild",
"build:client": "cd ./client && npm run build", "build:client": "cd ./client && npm run build",
@ -46,6 +46,7 @@
"clean:packages": "rimraf ./**/node_modules", "clean:packages": "rimraf ./**/node_modules",
"clean:server": "rimraf ./api-server/lib", "clean:server": "rimraf ./api-server/lib",
"create:config": "tsc -p config && npm run ensure-env", "create:config": "tsc -p config && npm run ensure-env",
"create:utils": "tsc -p utils",
"precypress": "node ./cypress-install.js", "precypress": "node ./cypress-install.js",
"cypress": "cypress", "cypress": "cypress",
"cypress:dev:run": "npm run cypress -- run", "cypress:dev:run": "npm run cypress -- run",
@ -54,7 +55,7 @@
"cypress:install-build-tools": "sh ./cypress-install.sh", "cypress:install-build-tools": "sh ./cypress-install.sh",
"cypress:prd:run": "npm run cypress -- run", "cypress:prd:run": "npm run cypress -- run",
"cypress:prd:watch": "npm run cypress -- open", "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": "npm-run-all build:curriculum -p develop:*",
"develop:client": "npm run build:curriculum && cd ./client && npm run develop", "develop:client": "npm run build:curriculum && cd ./client && npm run develop",
"develop:server": "npm run predevelop && cd ./api-server && npm run develop", "develop:server": "npm run predevelop && cd ./api-server && npm run develop",
@ -70,20 +71,20 @@
"format:prettier": "prettier --write .", "format:prettier": "prettier --write .",
"hooks:install": "node node_modules/husky/husky.js install", "hooks:install": "node node_modules/husky/husky.js install",
"hooks:uninstall": "node node_modules/husky/husky.js uninstall", "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:challenges": "cd ./curriculum && npm run lint",
"lint:js": "eslint --max-warnings 0 .", "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 .", "lint:prettier": "prettier --list-different .",
"seed": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser", "seed": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser",
"seed:certified-user": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser certUser", "seed:certified-user": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser certUser",
"serve:client": "cd ./client && npm run serve", "serve:client": "cd ./client && npm run serve",
"serve:client-ci": "cd ./client && npm run serve-ci", "serve:client-ci": "cd ./client && npm run serve-ci",
"start": "npm-run-all create:config -p develop:server serve:client", "start": "npm-run-all create:* -p develop:server serve:client",
"start-ci": "npm-run-all create:config -p start:server serve:client-ci", "start-ci": "npm-run-all create:* -p start:server serve:client-ci",
"start:server": "cd ./api-server && npm start", "start:server": "cd ./api-server && npm start",
"storybook": "cd ./tools/ui-components && npm run storybook", "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:source": "jest",
"test:curriculum": "cd ./curriculum && npm test", "test:curriculum": "cd ./curriculum && npm test",
"test-curriculum-full-output": "cd ./curriculum && npm run test:full-output", "test-curriculum-full-output": "cd ./curriculum && npm run test:full-output",

View File

@ -1,7 +1,6 @@
const slugs = require('./slugs'); import { dasherize, nameify, unDasherize } from './slugs';
describe('dasherize', () => { describe('dasherize', () => {
const { dasherize } = slugs;
it('returns a string', () => { it('returns a string', () => {
expect(dasherize('')).toBe(''); expect(dasherize('')).toBe('');
}); });
@ -26,7 +25,6 @@ describe('dasherize', () => {
}); });
describe('nameify', () => { describe('nameify', () => {
const { nameify } = slugs;
it('returns a string', () => { it('returns a string', () => {
expect(nameify('')).toBe(''); expect(nameify('')).toBe('');
}); });
@ -36,7 +34,6 @@ describe('nameify', () => {
}); });
describe('unDasherize', () => { describe('unDasherize', () => {
const { unDasherize } = slugs;
it('returns a string', () => { it('returns a string', () => {
expect(unDasherize('')).toBe(''); expect(unDasherize('')).toBe('');
}); });

View File

@ -1,16 +1,16 @@
exports.dasherize = function dasherize(name) { function dasherize(name: string): string {
return ('' + name) return ('' + name)
.toLowerCase() .toLowerCase()
.trim() .trim()
.replace(/\s|\./g, '-') .replace(/\s|\./g, '-')
.replace(/[^a-z\d\-.]/g, ''); .replace(/[^a-z\d\-.]/g, '');
}; }
exports.nameify = function nameify(str) { function nameify(str: string): string {
return ('' + str).replace(/[^a-z\d\s]/gi, ''); return ('' + str).replace(/[^a-z\d\s]/gi, '');
}; }
exports.unDasherize = function unDasherize(name) { function unDasherize(name: string): string {
return ( return (
('' + name) ('' + name)
// replace dash with space // replace dash with space
@ -19,4 +19,6 @@ exports.unDasherize = function unDasherize(name) {
.replace(/[^a-z\d\s]/gi, '') .replace(/[^a-z\d\s]/gi, '')
.trim() .trim()
); );
}; }
export { dasherize, nameify, unDasherize };

9
utils/tsconfig.json Normal file
View File

@ -0,0 +1,9 @@
{
"include": ["**/*.ts", "**/*.test.ts"],
"exclude": ["./__fixtures__"],
"extends": "../tsconfig-base.json",
"compilerOptions": {
"noEmit": false,
"module": "CommonJS"
}
}