Refactor to external scraper and update dependencies (#113)
This commit is contained in:
2978
mocks/data/audio.json
Normal file
2978
mocks/data/audio.json
Normal file
File diff suppressed because it is too large
Load Diff
287
mocks/data/fullInfo.json
Normal file
287
mocks/data/fullInfo.json
Normal file
@@ -0,0 +1,287 @@
|
||||
{
|
||||
"detectedSource": "en",
|
||||
"pronunciation": {
|
||||
"query": "win"
|
||||
},
|
||||
"definitions": [
|
||||
{
|
||||
"type": "verb",
|
||||
"list": [
|
||||
{
|
||||
"definition": "be successful or victorious in (a contest or conflict).",
|
||||
"example": "the Mets have won four games in a row",
|
||||
"synonyms": [
|
||||
"come first in",
|
||||
"finish first in",
|
||||
"be victorious in",
|
||||
"triumph in",
|
||||
"take first prize in",
|
||||
"achieve success in",
|
||||
"be successful in",
|
||||
"prevail in",
|
||||
"come first",
|
||||
"finish first",
|
||||
"be the winner",
|
||||
"be victorious",
|
||||
"be the victor",
|
||||
"carry/win the day",
|
||||
"carry all before one",
|
||||
"defeat/overcome the opposition",
|
||||
"take the honors/crown",
|
||||
"gain the palm",
|
||||
"come out ahead",
|
||||
"come out on top",
|
||||
"succeed",
|
||||
"triumph",
|
||||
"prevail",
|
||||
"achieve mastery",
|
||||
"sweep the board",
|
||||
"make a clean sweep",
|
||||
"wrap up",
|
||||
"win out",
|
||||
"clean up"
|
||||
]
|
||||
},
|
||||
{
|
||||
"definition": "acquire or secure as a result of a contest, conflict, bet, or other endeavor.",
|
||||
"example": "there are hundreds of prizes to be won",
|
||||
"synonyms": [
|
||||
"secure",
|
||||
"gain",
|
||||
"achieve",
|
||||
"attain",
|
||||
"earn",
|
||||
"obtain",
|
||||
"acquire",
|
||||
"procure",
|
||||
"get",
|
||||
"collect",
|
||||
"pick up",
|
||||
"walk away/off with",
|
||||
"come away with",
|
||||
"carry off",
|
||||
"receive",
|
||||
"land",
|
||||
"net",
|
||||
"bag",
|
||||
"bank",
|
||||
"pot",
|
||||
"scoop"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "noun",
|
||||
"list": [
|
||||
{
|
||||
"definition": "a successful result in a contest, conflict, bet, or other endeavor; a victory.",
|
||||
"example": "a win against Norway",
|
||||
"synonyms": [
|
||||
"victory",
|
||||
"triumph",
|
||||
"conquest",
|
||||
"success",
|
||||
"game",
|
||||
"set",
|
||||
"and match"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"examples": [
|
||||
"a <b>win</b> against Norway",
|
||||
"many lived to <b>win</b> the great cave",
|
||||
"you will find it difficult to <b>win</b> back their attention",
|
||||
"a determination to <b>win</b>"
|
||||
],
|
||||
"similar": [],
|
||||
"extraTranslations": [
|
||||
{
|
||||
"type": "verb",
|
||||
"list": [
|
||||
{
|
||||
"word": "ganar",
|
||||
"meanings": [
|
||||
"win",
|
||||
"earn",
|
||||
"gain",
|
||||
"make",
|
||||
"get",
|
||||
"beat"
|
||||
],
|
||||
"frequency": 3
|
||||
},
|
||||
{
|
||||
"word": "vencer",
|
||||
"meanings": [
|
||||
"overcome",
|
||||
"beat",
|
||||
"defeat",
|
||||
"win",
|
||||
"conquer",
|
||||
"expire"
|
||||
],
|
||||
"frequency": 2
|
||||
},
|
||||
{
|
||||
"word": "triunfar",
|
||||
"meanings": [
|
||||
"succeed",
|
||||
"triumph",
|
||||
"win",
|
||||
"prevail",
|
||||
"overcome",
|
||||
"trump"
|
||||
],
|
||||
"frequency": 1
|
||||
},
|
||||
{
|
||||
"word": "conseguir",
|
||||
"meanings": [
|
||||
"get",
|
||||
"achieve",
|
||||
"obtain",
|
||||
"gain",
|
||||
"attain",
|
||||
"win"
|
||||
],
|
||||
"frequency": 1
|
||||
},
|
||||
{
|
||||
"word": "lograr",
|
||||
"meanings": [
|
||||
"achieve",
|
||||
"accomplish",
|
||||
"get",
|
||||
"attain",
|
||||
"reach",
|
||||
"win"
|
||||
],
|
||||
"frequency": 1
|
||||
},
|
||||
{
|
||||
"word": "alcanzar",
|
||||
"meanings": [
|
||||
"reach",
|
||||
"achieve",
|
||||
"attain",
|
||||
"accomplish",
|
||||
"hit",
|
||||
"catch up"
|
||||
],
|
||||
"frequency": 1
|
||||
},
|
||||
{
|
||||
"word": "llevarse",
|
||||
"meanings": [
|
||||
"get",
|
||||
"take away",
|
||||
"win",
|
||||
"carry away",
|
||||
"carry off",
|
||||
"walk away"
|
||||
],
|
||||
"frequency": 1
|
||||
},
|
||||
{
|
||||
"word": "tener éxito",
|
||||
"meanings": [
|
||||
"succeed",
|
||||
"be successful",
|
||||
"win",
|
||||
"take",
|
||||
"get on",
|
||||
"make the grade"
|
||||
],
|
||||
"frequency": 1
|
||||
},
|
||||
{
|
||||
"word": "captar",
|
||||
"meanings": [
|
||||
"capture",
|
||||
"catch",
|
||||
"attract",
|
||||
"get",
|
||||
"pick up",
|
||||
"understand"
|
||||
],
|
||||
"frequency": 1
|
||||
},
|
||||
{
|
||||
"word": "arrancar",
|
||||
"meanings": [
|
||||
"tear",
|
||||
"pull",
|
||||
"pluck",
|
||||
"tear off",
|
||||
"pull up",
|
||||
"extract"
|
||||
],
|
||||
"frequency": 1
|
||||
},
|
||||
{
|
||||
"word": "atraerse",
|
||||
"meanings": [
|
||||
"win",
|
||||
"win over",
|
||||
"win round"
|
||||
],
|
||||
"frequency": 1
|
||||
},
|
||||
{
|
||||
"word": "extraer",
|
||||
"meanings": [
|
||||
"extract",
|
||||
"draw",
|
||||
"pull",
|
||||
"pull out",
|
||||
"mine",
|
||||
"take out"
|
||||
],
|
||||
"frequency": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "noun",
|
||||
"list": [
|
||||
{
|
||||
"word": "triunfo",
|
||||
"article": "el",
|
||||
"meanings": [
|
||||
"triumph",
|
||||
"win",
|
||||
"success",
|
||||
"trump"
|
||||
],
|
||||
"frequency": 3
|
||||
},
|
||||
{
|
||||
"word": "victoria",
|
||||
"article": "la",
|
||||
"meanings": [
|
||||
"victory",
|
||||
"win",
|
||||
"victoria"
|
||||
],
|
||||
"frequency": 3
|
||||
},
|
||||
{
|
||||
"word": "éxito",
|
||||
"article": "el",
|
||||
"meanings": [
|
||||
"success",
|
||||
"hit",
|
||||
"achievement",
|
||||
"accomplishment",
|
||||
"win",
|
||||
"triumph"
|
||||
],
|
||||
"frequency": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
25
mocks/data/index.ts
Normal file
25
mocks/data/index.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { TranslationInfo, LangCode } from "lingva-scraper";
|
||||
|
||||
import fullInfo from "./fullInfo.json";
|
||||
import simpleInfo from "./simpleInfo.json";
|
||||
import pronunciationInfo from "./pronunciationInfo.json";
|
||||
import audio from "./audio.json";
|
||||
|
||||
export const fullInfoMock = fullInfo as TranslationInfo;
|
||||
export const simpleInfoMock = simpleInfo as TranslationInfo;
|
||||
export const pronunciationInfoMock = pronunciationInfo as TranslationInfo;
|
||||
export const audioMock = {
|
||||
query: audio as number[],
|
||||
translation: audio as number[]
|
||||
};
|
||||
export const translationMock = "victoria";
|
||||
export const initialMock = {
|
||||
source: "es" as LangCode<"source">,
|
||||
target: "en" as LangCode<"target">,
|
||||
query: "hola"
|
||||
};
|
||||
export const initialAutoMock = {
|
||||
source: "auto" as LangCode<"source">,
|
||||
target: "es" as LangCode<"target">,
|
||||
query: "win"
|
||||
};
|
||||
10
mocks/data/pronunciationInfo.json
Normal file
10
mocks/data/pronunciationInfo.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"pronunciation": {
|
||||
"query": "Zǎo ān",
|
||||
"translation": "joh-eun achim"
|
||||
},
|
||||
"definitions": [],
|
||||
"examples": [],
|
||||
"similar": [],
|
||||
"extraTranslations": []
|
||||
}
|
||||
7
mocks/data/simpleInfo.json
Normal file
7
mocks/data/simpleInfo.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"pronunciation": {},
|
||||
"definitions": [],
|
||||
"examples": [],
|
||||
"similar": [],
|
||||
"extraTranslations": []
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
import Router from "next/router";
|
||||
|
||||
export const routerPushMock = jest.spyOn(Router, "push").mockImplementation(async () => true);
|
||||
31
mocks/next.tsx
Normal file
31
mocks/next.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { FC, PropsWithChildren } from "react";
|
||||
import { RouterContext } from "next/dist/shared/lib/router-context";
|
||||
|
||||
export const routerMock = {
|
||||
basePath: "",
|
||||
pathname: "/",
|
||||
route: "/",
|
||||
asPath: "/",
|
||||
query: {},
|
||||
push: jest.fn().mockResolvedValue(true),
|
||||
replace: jest.fn().mockResolvedValue(true),
|
||||
reload: jest.fn(),
|
||||
back: jest.fn(),
|
||||
prefetch: jest.fn().mockResolvedValue(undefined),
|
||||
beforePopState: jest.fn(),
|
||||
events: {
|
||||
on: jest.fn(),
|
||||
off: jest.fn(),
|
||||
emit: jest.fn(),
|
||||
},
|
||||
isFallback: false,
|
||||
isLocaleDomain: false,
|
||||
isReady: false,
|
||||
isPreview: false
|
||||
};
|
||||
|
||||
export const RouterProviderMock: FC<PropsWithChildren> = ({ children }) => (
|
||||
<RouterContext.Provider value={routerMock}>
|
||||
{children}
|
||||
</RouterContext.Provider>
|
||||
);
|
||||
40
mocks/renewData.ts
Normal file
40
mocks/renewData.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { getTranslationInfo, getAudio, LangCode } from "lingva-scraper";
|
||||
|
||||
const handleError = (obj: object | null) => {
|
||||
if (!obj)
|
||||
throw new Error();
|
||||
return obj;
|
||||
};
|
||||
|
||||
const renew = {
|
||||
fullInfo: () => getTranslationInfo("auto" as LangCode<"source">, "es" as LangCode<"target">, "win").then(handleError),
|
||||
simpleInfo: () => getTranslationInfo("es" as LangCode<"source">, "en" as LangCode<"target">, "hola").then(handleError),
|
||||
pronunciationInfo: () => getTranslationInfo("zh" as LangCode<"source">, "ko" as LangCode<"target">, "早安").then(handleError),
|
||||
audio: () => getAudio("es" as LangCode<"target">, "hola").then(handleError),
|
||||
};
|
||||
|
||||
type DataType = keyof typeof renew;
|
||||
|
||||
const save = (json: object, type: DataType) => {
|
||||
writeFile(
|
||||
`./mocks/data/${type}.json`,
|
||||
JSON.stringify(json, null, 2),
|
||||
"utf-8"
|
||||
).then(() =>
|
||||
console.log(`Successfully renewed '${type}'`)
|
||||
).catch(() =>
|
||||
console.log(`Error renewing '${type}'`)
|
||||
)
|
||||
};
|
||||
|
||||
const isKeyOf = <T extends object>(obj: T, key: keyof any): key is keyof T => key in obj;
|
||||
|
||||
const arg = process.argv[2];
|
||||
|
||||
if (arg && isKeyOf(renew, arg))
|
||||
renew[arg]().then(json => save(json, arg));
|
||||
else
|
||||
Object.entries(renew).forEach(([key, fn]) =>
|
||||
isKeyOf(renew, key) && fn().then(json => save(json, key))
|
||||
);
|
||||
Reference in New Issue
Block a user