feat: 中英字典收集工具
This commit is contained in:
+23481
-51136
File diff suppressed because one or more lines are too long
+19961
-59326
File diff suppressed because one or more lines are too long
+16849
-77839
File diff suppressed because one or more lines are too long
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user