feat: 中英字典收集工具

This commit is contained in:
Zhicheng Wang
2018-03-01 20:11:12 +08:00
parent 6120300d4a
commit 1b786e0a72
5 changed files with 60302 additions and 188313 deletions
+23481 -51136
View File
File diff suppressed because one or more lines are too long
+19961 -59326
View File
File diff suppressed because one or more lines are too long
+16849 -77839
View File
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -31,19 +31,19 @@ describe('gather to dictionary', () => {
it('should gather from real file', function () {
const fs = require('fs');
const content = fs.readFileSync(__dirname + '/../../content/guide/forms.md', 'utf-8');
const content = fs.readFileSync(__dirname + '/../guide/forms.md', 'utf-8');
const result = gatherTranslations(content);
expect(result[0]).eql({original: '# Forms', translation: '# 表单'});
});
it('should list files recursive', function () {
expect(listMarkdownFiles().length).greaterThan(10);
expect(listMarkdownFiles(__dirname + '/../').length).greaterThan(10);
});
it('should gather from directory', () => {
const entries = gatherFromMarkdownFiles();
const entries = gatherFromMarkdownFiles(__dirname + '/../');
const dict = JSON.stringify(entries, null, 2);
const fs = require('fs');
fs.writeFileSync(__dirname + '/../../content/dict.json', dict, 'utf-8');
fs.writeFileSync(__dirname + '/../dict/dict-2.json', dict, 'utf-8');
expect(entries.length).greaterThan(100);
});
});
+7 -8
View File
@@ -29,8 +29,8 @@ export function gatherTranslations(text: string): DictEntry[] {
return result;
}
export function listMarkdownFiles(): string[] {
return globby.sync(__dirname + '/../**/*.md');
export function listMarkdownFiles(directory: string): string[] {
return globby.sync(directory + '**/*.md');
}
export function gatherFromMarkdownFile(fileName: string): DictEntry[] {
@@ -41,13 +41,12 @@ export function gatherFromMarkdownFile(fileName: string): DictEntry[] {
return entries;
}
export function gatherFromMarkdownFiles(): DictEntry[] {
const files = listMarkdownFiles();
export function gatherFromMarkdownFiles(directory: string): DictEntry[] {
const files = listMarkdownFiles(directory);
const entries = files.map(gatherFromMarkdownFile);
return entries.reduce((result, value) => result.concat(value), []);
}
const entries = gatherFromMarkdownFiles();
const dict = JSON.stringify(entries, null, 2);
const fs = require('fs');
fs.writeFileSync(__dirname + '/dict-current.json', dict, 'utf-8');
const contentDirectory = process.argv[2];
gatherFromMarkdownFiles(contentDirectory);