Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add wiki.json testing & sorting task #119

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
Comment on lines +9 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
}
}
modifyFile(wikiData => {
const records = JSON.parse(wikiData);
const hasWrongFormatName = records.some(record => !isValidName(record.name));
  1. Array.prototype.some 사용해봐도 좋을 것 같슴다 ㅎㅎ
  2. 배열 변수 네이밍은 복수형으로해봐도 조흘듯합니다..!


const sorted = !!hasWrongFormatName
? wikiData
: wikiData.sort((a, b) => {
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
});
Comment on lines +22 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: wikiData.sort((a, b) => {
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
});
: wikiData.sort((a, b) => a.localeCompare(b));

String.prototype.localeCompare 써봐도 좋을 것 같아요!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greatSumini 이런게 있군요!


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');
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start",
"prebuild": "gulp",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
Expand Down Expand Up @@ -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"
}
Expand Down