fix issue with peerDepencies holding old pashto-inflector

This commit is contained in:
adueck 2022-10-12 12:21:36 +05:00
parent a97430c981
commit de7abbffa2
3 changed files with 5742 additions and 5122 deletions

10737
functions/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,41 +1,37 @@
{ {
"name": "functions", "name": "functions",
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"serve": "npm run build && firebase emulators:start --only functions", "serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell", "shell": "npm run build && firebase functions:shell",
"start": "npm run shell", "start": "npm run shell",
"deploy": "firebase deploy --only functions", "deploy": "firebase deploy --only functions",
"logs": "firebase functions:log" "logs": "firebase functions:log"
}, },
"engines": { "engines": {
"node": "16" "node": "16"
}, },
"main": "lib/functions/src/index.js", "main": "lib/functions/src/index.js",
"dependencies": { "dependencies": {
"@google-cloud/storage": "^5.8.1", "@google-cloud/storage": "^5.8.1",
"@lingdocs/inflect": "5.1.2", "@lingdocs/inflect": "5.1.2",
"@types/cors": "^2.8.10", "@types/cors": "^2.8.10",
"@types/google-spreadsheet": "^3.0.2", "@types/google-spreadsheet": "^3.0.2",
"@types/react": "^18.0.21", "@types/react": "^18.0.21",
"cors": "^2.8.5", "cors": "^2.8.5",
"firebase-admin": "^9.2.0", "firebase-admin": "^9.2.0",
"firebase-functions": "^3.24.1", "firebase-functions": "^3.24.1",
"google-spreadsheet": "^3.1.15", "google-spreadsheet": "^3.1.15",
"nano": "^9.0.3", "nano": "^9.0.3",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"react": "^17.0.1", "react": "^17.0.1",
"react-bootstrap": "^1.5.1", "react-bootstrap": "^1.5.1",
"react-dom": "^17.0.1" "react-dom": "^17.0.1"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.20", "@types/jest": "^26.0.20",
"@types/node-fetch": "^2.5.12", "@types/node-fetch": "^2.5.12",
"firebase-functions-test": "^0.2.0", "firebase-functions-test": "^0.2.0",
"typescript": "^4.6.3" "typescript": "^4.6.3"
}, }
"private": true, }
"peerDependencies": {
"@lingdocs/pashto-inflector": "4.9.15"
}
}

View File

@ -42,11 +42,11 @@ export default async function publish(): Promise<PublishDictionaryResponse> {
if (errors.length) { if (errors.length) {
return({ ok: false, errors }); return({ ok: false, errors });
} }
const duplicates = findDuplicates(entries); // const duplicates = findDuplicates(entries);
duplicates.forEach((duplicate) => { // duplicates.forEach((duplicate) => {
const index = entries.findIndex(e => e.ts === duplicate.ts); // const index = entries.findIndex(e => e.ts === duplicate.ts);
if (index > -1) entries.splice(index, 1); // if (index > -1) entries.splice(index, 1);
}) // })
const dictionary: T.Dictionary = { const dictionary: T.Dictionary = {
info: { info: {
title, title,
@ -76,6 +76,14 @@ async function doHunspell(entries: T.DictionaryEntry[]) {
await uploadHunspellToStorage(hunspell); await uploadHunspellToStorage(hunspell);
} }
/**
* Gets the entries from the spreadsheet, and also deletes duplicate
* entries that are sometimes annoyingly created by the GoogleSheets API
* when adding entries programmatically
*
* @returns
*
*/
async function getRawEntries(): Promise<T.DictionaryEntry[]> { async function getRawEntries(): Promise<T.DictionaryEntry[]> {
const doc = new GoogleSpreadsheet( const doc = new GoogleSpreadsheet(
functions.config().sheet.id, functions.config().sheet.id,
@ -87,11 +95,14 @@ async function getRawEntries(): Promise<T.DictionaryEntry[]> {
await doc.loadInfo(); await doc.loadInfo();
const sheet = doc.sheetsByIndex[0]; const sheet = doc.sheetsByIndex[0];
const rows = await sheet.getRows(); const rows = await sheet.getRows();
const entries = makeEntries(rows); async function deleteRow(r: number) {
await rows[r].delete();
}
const entries = makeEntries(rows, deleteRow);
return entries; return entries;
} }
function makeEntries(rows: any[]): T.DictionaryEntry[] { function makeEntries(rows: any[], deleteRow: (r: number) => Promise<void>): T.DictionaryEntry[] {
const entries: T.DictionaryEntry[] = rows.map((row): T.DictionaryEntry => { const entries: T.DictionaryEntry[] = rows.map((row): T.DictionaryEntry => {
const e: T.DictionaryEntry = { const e: T.DictionaryEntry = {
i: 1, i: 1,
@ -157,19 +168,19 @@ function checkForErrors(entries: T.DictionaryEntry[]): T.DictionaryEntryError[]
}, []); }, []);
} }
function findDuplicates(entries: T.DictionaryEntry[]): T.DictionaryEntry[] { // function findDuplicates(entries: T.DictionaryEntry[]): T.DictionaryEntry[] {
const tsSoFar = new Set(); // const tsSoFar = new Set();
const duplicates: T.DictionaryEntry[] = []; // const duplicates: T.DictionaryEntry[] = [];
// tslint:disable-next-line: prefer-for-of // // tslint:disable-next-line: prefer-for-of
for (let i = 0; i < entries.length; i++) { // for (let i = 0; i < entries.length; i++) {
const ts = entries[i].ts; // const ts = entries[i].ts;
if (tsSoFar.has(ts)) { // if (tsSoFar.has(ts)) {
duplicates.push(entries[i]); // duplicates.push(entries[i]);
} // }
tsSoFar.add(ts); // tsSoFar.add(ts);
} // }
return duplicates; // return duplicates;
} // }
async function upload(content: Buffer | string, filename: string) { async function upload(content: Buffer | string, filename: string) {
const isBuffer = typeof content !== "string"; const isBuffer = typeof content !== "string";