2021-03-09 12:39:13 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2021 lingdocs.com
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
const fs = require("fs");
|
|
|
|
const fetch = require("node-fetch");
|
|
|
|
const path = require("path");
|
|
|
|
const collectionPath = path.join(".", "verbs");
|
2021-03-16 10:10:29 +00:00
|
|
|
const verbTsFiles = fs.readdirSync(collectionPath);
|
2021-03-16 10:34:34 +00:00
|
|
|
const protoModels = require("./src/lib/dictionary-models.js");
|
2021-03-16 10:10:29 +00:00
|
|
|
const Pbf = require("pbf");
|
2021-03-09 12:39:13 +00:00
|
|
|
|
|
|
|
const allTsS = [...new Set(verbTsFiles.reduce((arr, fileName) => {
|
|
|
|
const TsS = require("./verbs/"+fileName);
|
|
|
|
return [...arr, ...TsS];
|
|
|
|
}, []))];
|
|
|
|
|
2021-03-16 10:07:30 +00:00
|
|
|
fetch(process.env.LINGDOCS_DICTIONARY_URL).then(res => res.arrayBuffer()).then(buffer => {
|
2021-03-16 10:10:29 +00:00
|
|
|
const pbf = new Pbf(buffer);
|
|
|
|
const dictionary = protoModels.Dictionary.read(pbf);
|
2021-03-16 10:07:30 +00:00
|
|
|
const entries = dictionary.entries;
|
2021-03-09 12:39:13 +00:00
|
|
|
const allVerbs = getFromTsS(entries);
|
|
|
|
const content = `
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2021 lingdocs.com
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { DictionaryEntry } from "./types";
|
|
|
|
|
|
|
|
const verbs: {
|
|
|
|
entry: DictionaryEntry,
|
|
|
|
complement?: DictionaryEntry,
|
|
|
|
}[] = ${JSON.stringify(allVerbs)};
|
|
|
|
export default verbs;`;
|
|
|
|
fs.writeFileSync("./src/verbs.ts", content);
|
|
|
|
console.log("fetched verbs from dictionary");
|
|
|
|
});
|
|
|
|
|
|
|
|
function getFromTsS(entries) {
|
|
|
|
return allTsS.map(ts => {
|
|
|
|
const entry = entries.find(x => ts === x.ts);
|
|
|
|
if (!entry) {
|
|
|
|
console.log("couldn't find ts", ts);
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
if (entry.c && entry.c.includes("comp.")) {
|
|
|
|
const complement = entries.find(x => entry.l === x.ts);
|
|
|
|
return {
|
|
|
|
entry,
|
|
|
|
complement,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return { entry };
|
|
|
|
}).filter(x => x);
|
|
|
|
}
|