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:
@ -45,7 +45,8 @@
|
||||
"project": [
|
||||
"./tsconfig.json",
|
||||
"./config/tsconfig.json",
|
||||
"./tools/ui-components/tsconfig.json"
|
||||
"./tools/ui-components/tsconfig.json",
|
||||
"./utils/tsconfig.json"
|
||||
]
|
||||
},
|
||||
"extends": [
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -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
|
||||
|
@ -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
|
||||
|
15
package.json
15
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",
|
||||
|
@ -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('');
|
||||
});
|
@ -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 };
|
9
utils/tsconfig.json
Normal file
9
utils/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"include": ["**/*.ts", "**/*.test.ts"],
|
||||
"exclude": ["./__fixtures__"],
|
||||
"extends": "../tsconfig-base.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": false,
|
||||
"module": "CommonJS"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user