diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 00000000..d0519e20 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,54 @@ +const { task, src, series, dest } = require('gulp'); +const log = require('fancy-log'); +const modifyFile = require('gulp-modify-file'); +const prettier = require('gulp-prettier'); + +task('check-wiki.json', done => { + src('./wiki.json') + .pipe( + modifyFile(content => { + let hasWrongFormatName = false; + const wikiData = JSON.parse(content); + + for (let idx = 0; idx < wikiData.length; idx++) { + if (isValidName(wikiData[idx].name) === false) { + hasWrongFormatName = true; + break; + } + } + + const sorted = !!hasWrongFormatName + ? wikiData + : wikiData.sort((a, b) => { + return a.name < b.name ? -1 : a.name > b.name ? 1 : 0; + }); + + return JSON.stringify(sorted); + }), + ) + .pipe(prettier()) + .pipe(dest('./')); + done(); +}); + +function isValidName(str) { + const regex = + /^[a-zA-Z0-9가-힣][a-zA-Z0-9가-힣\s]*[a-zA-Z0-9가-힣]\s\([a-zA-Z0-9][a-zA-Z0-9\s]*[a-zA-Z0-9]\)/; + + if (regex.test(str) === false) { + log.error(` + Error occured in wiki.json data : ${str} + Please check below wiki.json naming convetion + ● Each part of name must start with non-whitespace + ● First part of name must be combination of (korean | english | number | whitespace) + ● Second part of name must be wrapped round brackets + ● Second part of name must be combination of (english | number | whitespace) + ● Second part of name must not be empty + ● More than two words must be separated by ', ' + `); + return false; + } + return true; +} + +exports.default = series('check-wiki.json'); diff --git a/package.json b/package.json index f2111902..ee2414dd 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "scripts": { "docusaurus": "docusaurus", "start": "docusaurus start", + "prebuild": "gulp", "build": "docusaurus build", "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy", @@ -67,6 +68,10 @@ "eslint-plugin-react": "^7.24.0", "eslint-plugin-react-hooks": "^4.2.0", "eslint-plugin-testing-library": "^4.10.1", + "fancy-log": "^1.3.3", + "gulp": "^4.0.2", + "gulp-modify-file": "^1.0.1", + "gulp-prettier": "^4.0.0", "prettier": "^2.3.2", "typescript": "^4.3.5" }