Skip to content

Commit ee6edfc

Browse files
committed
chore(npm): cleanup
1 parent 8093ef3 commit ee6edfc

File tree

2 files changed

+45
-43
lines changed

2 files changed

+45
-43
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
"textlint-rule-no-start-duplicated-conjunction": "^1.0.3",
6262
"textlint-rule-prh": "^2.0.0",
6363
"textlint-rule-spellcheck-tech-word": "^4.0.1",
64+
"stemming-x-keywords": "^1.0.3",
65+
"unist-util-is": "^1.0.0",
6466
"unist-util-parents": "^0.1.1",
6567
"unist-util-select": "^1.0.0"
6668
},
@@ -69,8 +71,6 @@
6971
"estraverse": "^4.1.0",
7072
"gulp": "^3.9.0",
7173
"gulp-util": "^3.0.6",
72-
"jquery": "^2.1.4",
73-
"stemming-x-keywords": "^1.0.3",
74-
"unist-util-is": "^1.0.0"
74+
"jquery": "^2.1.4"
7575
}
7676
}

test/keywords-test.js

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// LICENSE : MIT
22
"use strict";
33
import {getKeywords} from "stemming-x-keywords";
4-
import {getFilePathListAsync} from "gitbook-summary-to-path";
54
import path from "path";
65
import fs from "fs";
76
import mdast from "mdast";
87
import parents from "unist-util-parents";
98
import select from "unist-util-select";
109
import isUnist from "unist-util-is";
1110
import nlcstToString from "nlcst-to-string";
11+
1212
const rootDir = path.join(__dirname, "..");
13-
const OrganizationText = fs.readFileSync(__dirname + "/../ORGANIZATION.md", "utf-8");
13+
const OrganizationText = fs.readFileSync(path.join(rootDir, "ORGANIZATION.md"), "utf-8");
1414
function isNotContain(content, keywords) {
1515
// 含んでないものだけを返す
1616
return keywords.filter(keyword => {
@@ -42,46 +42,48 @@ function isAlreadyCheckKeyword(list, keyword) {
4242
return list.indexOf(keyword) !== -1;
4343
}
4444

45-
// キーワードが書くコンテンツに含まれているかをテストする
46-
describe("keywords", function () {
47-
it("Each chapter contain the keyword", function () {
48-
let ast = mdast.parse(OrganizationText);
49-
let headerLinks = select(parents(ast), "heading link[href]");
50-
let paragraphList = headerLinks.map(link => {
51-
let filePath = path.resolve(rootDir, link.href);
52-
let paragraphs = findAllAfter(ast, link.parent.node, "paragraph");
53-
let results = {
54-
filePath: filePath,
55-
content: fs.readFileSync(filePath, "utf-8"),
56-
keywords: []
57-
};
58-
let keywords = paragraphs.map(p => {
59-
let text = nlcstToString(p);
60-
return getKeywords(text).then(a => {
61-
results.keywords = results.keywords.concat(a);
62-
});
63-
});
64-
return Promise.all(keywords).then(()=> {
65-
return results;
45+
function checkKeyword(text){
46+
let ast = mdast.parse(text);
47+
let headerLinks = select(parents(ast), "heading link[href]");
48+
let paragraphList = headerLinks.map(link => {
49+
let filePath = path.resolve(rootDir, link.href);
50+
let paragraphs = findAllAfter(ast, link.parent.node, "paragraph");
51+
let results = {
52+
filePath: filePath,
53+
content: fs.readFileSync(filePath, "utf-8"),
54+
keywords: []
55+
};
56+
let keywords = paragraphs.map(p => {
57+
let text = nlcstToString(p);
58+
return getKeywords(text).then(a => {
59+
results.keywords = results.keywords.concat(a);
6660
});
6761
});
68-
let promises = Promise.all(paragraphList).then(results => {
69-
let confirmedKeywords = [];
70-
return results.forEach(({filePath, content, keywords}) => {
71-
let unusedKeywords = isNotContain(content, keywords);
72-
let isChecked = isAlreadyCheckKeyword.bind(null, confirmedKeywords);
73-
if (unusedKeywords.length === 0) {
74-
// 使用済みのキーワードを登録
75-
confirmedKeywords = confirmedKeywords.concat(keywords);
76-
return;
77-
}
78-
if (unusedKeywords.every(isChecked)) {
79-
console.log(unusedKeywords.join(",") + "はチェック済み");
80-
return;
81-
}
82-
throw new Error(`"${unusedKeywords.join(",")}" are not used in ${filePath}`);
83-
});
62+
return Promise.all(keywords).then(()=> {
63+
return results;
8464
});
85-
return promises;
65+
});
66+
return Promise.all(paragraphList).then(results => {
67+
let confirmedKeywords = [];
68+
return results.forEach(({filePath, content, keywords}) => {
69+
let unusedKeywords = isNotContain(content, keywords);
70+
let isChecked = isAlreadyCheckKeyword.bind(null, confirmedKeywords);
71+
if (unusedKeywords.length === 0) {
72+
// 使用済みのキーワードを登録
73+
confirmedKeywords = confirmedKeywords.concat(keywords);
74+
return;
75+
}
76+
if (unusedKeywords.every(isChecked)) {
77+
console.log(unusedKeywords.join(",") + "はチェック済み");
78+
return;
79+
}
80+
throw new Error(`"${unusedKeywords.join(",")}" are not used in ${filePath}`);
81+
});
82+
});
83+
}
84+
// キーワードが書くコンテンツに含まれているかをテストする
85+
describe("keywords", function () {
86+
it("Each chapter contain the keyword", function () {
87+
return checkKeyword(OrganizationText);
8688
});
8789
});

0 commit comments

Comments
 (0)