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

View File

@ -42,11 +42,11 @@ export default async function publish(): Promise<PublishDictionaryResponse> {
if (errors.length) {
return({ ok: false, errors });
}
const duplicates = findDuplicates(entries);
duplicates.forEach((duplicate) => {
const index = entries.findIndex(e => e.ts === duplicate.ts);
if (index > -1) entries.splice(index, 1);
})
// const duplicates = findDuplicates(entries);
// duplicates.forEach((duplicate) => {
// const index = entries.findIndex(e => e.ts === duplicate.ts);
// if (index > -1) entries.splice(index, 1);
// })
const dictionary: T.Dictionary = {
info: {
title,
@ -76,6 +76,14 @@ async function doHunspell(entries: T.DictionaryEntry[]) {
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[]> {
const doc = new GoogleSpreadsheet(
functions.config().sheet.id,
@ -87,11 +95,14 @@ async function getRawEntries(): Promise<T.DictionaryEntry[]> {
await doc.loadInfo();
const sheet = doc.sheetsByIndex[0];
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;
}
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 e: T.DictionaryEntry = {
i: 1,
@ -157,19 +168,19 @@ function checkForErrors(entries: T.DictionaryEntry[]): T.DictionaryEntryError[]
}, []);
}
function findDuplicates(entries: T.DictionaryEntry[]): T.DictionaryEntry[] {
const tsSoFar = new Set();
const duplicates: T.DictionaryEntry[] = [];
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < entries.length; i++) {
const ts = entries[i].ts;
if (tsSoFar.has(ts)) {
duplicates.push(entries[i]);
}
tsSoFar.add(ts);
}
return duplicates;
}
// function findDuplicates(entries: T.DictionaryEntry[]): T.DictionaryEntry[] {
// const tsSoFar = new Set();
// const duplicates: T.DictionaryEntry[] = [];
// // tslint:disable-next-line: prefer-for-of
// for (let i = 0; i < entries.length; i++) {
// const ts = entries[i].ts;
// if (tsSoFar.has(ts)) {
// duplicates.push(entries[i]);
// }
// tsSoFar.add(ts);
// }
// return duplicates;
// }
async function upload(content: Buffer | string, filename: string) {
const isBuffer = typeof content !== "string";