Skip to content

Commit

Permalink
Merge pull request #32 from AkioSarkiz/refactoring
Browse files Browse the repository at this point in the history
refactoring
  • Loading branch information
AkioSarkiz authored Sep 30, 2024
2 parents 87d9454 + ca8691d commit 3609e11
Show file tree
Hide file tree
Showing 42 changed files with 98 additions and 89 deletions.
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@akiosarkiz/manga-collector",
"version": "1.18.0",
"version": "1.20.0",
"exports": "./src/index.ts",
"exclude": [
"tests",
Expand Down
2 changes: 1 addition & 1 deletion src/examples/mangadex/get-detailed-chapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/mangadex/get-detailed-manga.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/mangadex/get-latest-updates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/mangadex/search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/mangafire/get-detailed-chapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/mangafire/get-detailed-manga.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/mangafire/get-latest-updates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/mangafire/search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/manganato/get-detailed-chapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/manganato/get-detailed-manga.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/manganato/get-latest-updates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/toonily/get-detailed-chapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/toonily/get-detailed-manga.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/toonily/get-latest-updates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/toonily/search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MangaScraperFactory, MangaSource } from "../../index.js";
import { MangaScraperFactory, MangaSource } from "../../index";
import fs from "fs";

const main = async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/external-sources/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { MangaUpdatesExternalSourceMatcher } from "./manga-updates-external-source-matcher.js";
export { MyAnimeListExternalSourceMatcher } from "./my-anime-list-external-source-matcher.js";
export { MangaUpdatesExternalSourceMatcher } from "./manga-updates-external-source-matcher";
export { MyAnimeListExternalSourceMatcher } from "./my-anime-list-external-source-matcher";
6 changes: 3 additions & 3 deletions src/external-sources/manga-updates-external-source-matcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MangaUpdatesClient } from "../lib/index.js";
import { type ScrapedDetailedManga, type ExternalSourceMatcher } from "../index.js";
import { compareDiacriticsStrings } from "./functions.js";
import { MangaUpdatesClient } from "../lib/index";
import { type ScrapedDetailedManga, type ExternalSourceMatcher } from "../index";
import { compareDiacriticsStrings } from "./functions";

export class MangaUpdatesExternalSourceMatcher implements ExternalSourceMatcher {
private readonly mangaUpdatesClient: MangaUpdatesClient;
Expand Down
4 changes: 2 additions & 2 deletions src/external-sources/my-anime-list-external-source-matcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ScrapedDetailedManga, type ExternalSourceMatcher } from "../index.js";
import { type ScrapedDetailedManga, type ExternalSourceMatcher } from "../index";
import { Marika } from "@shineiichijo/marika";
import { compareDiacriticsStrings } from "./functions.js";
import { compareDiacriticsStrings } from "./functions";

export class MyAnimeListExternalSourceMatcher implements ExternalSourceMatcher {
private readonly marika: Marika;
Expand Down
4 changes: 2 additions & 2 deletions src/factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MangaSource, type Scraper } from "./index.js";
import { ToonilyScraper, ManganatoScraper, MangadexScraper, MangafireScraper } from "./providers/index.js";
import { MangaSource, type Scraper } from "./index";
import { ToonilyScraper, ManganatoScraper, MangadexScraper, MangafireScraper } from "./providers/index";

export class MangaScraperFactory {
/**
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type * from "./types/index.js";
export type * from "./types/index";

export * from "./external-sources/index.js";
export { MangaScraperFactory } from "./factory.js";
export * from "./external-sources/index";
export { MangaScraperFactory } from "./factory";

export enum MangaSource {
MANGANATO = "manganato",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { axios } from "./axios.js";
export { MangaUpdatesClient } from "./manga-updates.js";
export { dayjs } from "./dayjs.js";
export { axios } from "./axios";
export { MangaUpdatesClient } from "./manga-updates";
export { dayjs } from "./dayjs";
6 changes: 3 additions & 3 deletions src/lib/manga-updates.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { axios } from "./index.js";
import { axios } from "./index";
import { AxiosInstance, AxiosRequestConfig } from "axios";
import type { SearchedSeriesResponse, SeriesResponse } from "../types/index.d.js";
import type { SearchedSeriesResponse, SeriesResponse } from "../types";
import { decode } from "html-entities";
import { urlJoin } from "../functions.js";
import { urlJoin } from "../functions";

export class MangaUpdatesClient {
private readonly baseUrl: string = "https://api.mangaupdates.com/v1";
Expand Down
8 changes: 4 additions & 4 deletions src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { MangadexScraper } from "./mangadex/index.js";
export { ManganatoScraper } from "./manganato/index.js";
export { ToonilyScraper } from "./toonily/index.js";
export { MangafireScraper } from "./mangafire/index.js";
export { MangadexScraper } from "./mangadex/index";
export { ManganatoScraper } from "./manganato/index";
export { ToonilyScraper } from "./toonily/index";
export { MangafireScraper } from "./mangafire/index";
6 changes: 3 additions & 3 deletions src/providers/mangadex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
ScrapedListOfManga,
ScrapedListOfMangaItem,
Scraper,
} from "../../types/index.d.js";
import { axios } from "../../lib/index.js";
import { urlJoin } from "../../functions.js";
} from "../../types";
import { axios } from "../../lib";
import { urlJoin } from "../../functions";

export class MangadexScraper implements Scraper {
private readonly baseUrl: string = "https://mangadex.org";
Expand Down
6 changes: 3 additions & 3 deletions src/providers/mangafire/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
ScrapedListOfMangaItem,
ScrapedMangaStatus,
Scraper,
} from "../../index.js";
} from "../../index";
import * as cheerio from "cheerio";
import { axios } from "../../lib/axios.js";
import { urlJoin } from "../../functions.js";
import { axios } from "../../lib/axios";
import { urlJoin } from "../../functions";

export class MangafireScraper implements Scraper {
private readonly baseUrl = "https://mangafire.to";
Expand Down
8 changes: 4 additions & 4 deletions src/providers/manganato/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import type {
ScrapedListOfMangaItem,
ScrapedMangaStatus,
Scraper,
} from "../../types/index.d.js";
} from "../../types/index";
import {
convertToNumber,
extractChapterIndex,
extractNumbersFromStrings,
isOnlyNumbers,
parseRelativeTime,
} from "../../utils/index.js";
import { dayjs } from "../../lib/index.js";
} from "../../utils/index";
import { dayjs } from "../../lib/index";
import * as cheerio from "cheerio";
import { axios } from "../../lib/index.js";
import { axios } from "../../lib/index";

interface ParsedTableRow {
header: cheerio.Cheerio<cheerio.Element>;
Expand Down
10 changes: 5 additions & 5 deletions src/providers/toonily/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import type {
ScrapedListOfMangaItem,
ScrapedMangaStatus,
Scraper,
} from "../../types/index.d.js";
import { dayjs } from "../../lib/index.js";
import { convertToNumber, extractChapterIndex } from "../../utils/index.js";
import { axios } from "../../lib/index.js";
import { urlJoin } from "../../functions.js";
} from "../../types/index";
import { dayjs } from "../../lib/index";
import { convertToNumber, extractChapterIndex } from "../../utils/index";
import { axios } from "../../lib/index";
import { urlJoin } from "../../functions";

export class ToonilyScraper implements Scraper {
private readonly baseUrl: string = "https://toonily.com/";
Expand Down
6 changes: 3 additions & 3 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./scraper.js";
export * from "./manga-updates.js";
export * from "./external-source-matcher.js";
export * from "./scraper";
export * from "./manga-updates";
export * from "./external-source-matcher";
2 changes: 1 addition & 1 deletion src/types/scraper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IManga } from "@shineiichijo/marika";
import { SeriesResponse } from "./manga-updates.js";
import { SeriesResponse } from "./manga-updates";

export type ScrapedMangaStatus = "ongoing" | "completed" | "hiatus" | "cancelled";
export type ScrapedMangaType = "manga" | "novel" | "one-shot" | "doujin" | "manhwa" | "manhua";
Expand Down
6 changes: 3 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ManipulateType } from "dayjs";
import { dayjs } from "../lib/index.js";
import { dayjs } from "../lib";

export { extractChapterIndex } from "./chapter";

/**
* Checks if a given string consists only of numbers.
Expand Down Expand Up @@ -89,5 +91,3 @@ export const extractNumbersFromStrings = (input: string): number[] => {
return [];
}
};

export { extractChapterIndex } from "./chapter.js";
2 changes: 1 addition & 1 deletion tests/external-sources/manga-updates.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "vitest";
import path from "path";
import { MangaUpdatesExternalSourceMatcher } from "../../src/index.js";
import { MangaUpdatesExternalSourceMatcher } from "../../src/index";

const MANGA_LINK_DATA = [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/external-sources/my-anime-list.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "vitest";
import path from "node:path";
import { MyAnimeListExternalSourceMatcher } from "../../src/index.js";
import { MyAnimeListExternalSourceMatcher } from "../../src/index";

const MANGA_LINK_DATA = [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/manga-updates/manga-updates.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectTypeOf, test } from "vitest";
import { MangaUpdatesClient } from "../../src/lib/index.js";
import { MangaUpdatesClient } from "../../src/lib/index";
import { SearchedSeriesResponse } from "../../src";

test("should search series", async () => {
Expand Down
10 changes: 7 additions & 3 deletions tests/mangadex/mangadex.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { expectTypeOf, test } from "vitest";
import { MangaSource } from "../../src/index.js";
import { MangaScraperFactory } from "../../src/factory.js";
import { ScrapedDetailedChapter, ScrapedDetailedManga, ScrapedListOfManga } from "../../src/index.js";
import {
MangaSource,
MangaScraperFactory,
ScrapedDetailedChapter,
ScrapedDetailedManga,
ScrapedListOfManga,
} from "../../src/index";

test("search", async () => {
const query = "test";
Expand Down
22 changes: 12 additions & 10 deletions tests/mangadex/mangadex.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect, test } from "vitest";
import { MangaSource } from "../../src/index.js";
import { MangaScraperFactory } from "../../src/factory.js";
import { MangaScraperFactory, MangaSource } from "../../src/index";
import path from "path";

const MANGA_DATA_TO_SEARCH_SCRAPE = [{ query: "san" }, { query: "attack on titan" }, { query: "one piece" }];
Expand Down Expand Up @@ -95,12 +94,15 @@ test.each(MANGA_DATA_TO_DETAILED_SCRAPE)("get detailed manga of $link", async ({
}
});

test.each(MANGA_DATA_TO_DETAILED_CHAPTER_SCRAPE)("get detailed chapter of $link", async ({ link, expectedDataPath }) => {
const expectedData = { ...(await import(expectedDataPath)) };
const scraper = await MangaScraperFactory.make(MangaSource.MANGADEX);
const result = await scraper.getDetailedChapter(link);
test.each(MANGA_DATA_TO_DETAILED_CHAPTER_SCRAPE)(
"get detailed chapter of $link",
async ({ link, expectedDataPath }) => {
const expectedData = { ...(await import(expectedDataPath)) };
const scraper = await MangaScraperFactory.make(MangaSource.MANGADEX);
const result = await scraper.getDetailedChapter(link);

expect(result.title).toEqual(expectedData.title);
expect(result.url).toEqual(expectedData.url);
expect(new Set(result.frames)).toEqual(new Set(expectedData.frames));
});
expect(result.title).toEqual(expectedData.title);
expect(result.url).toEqual(expectedData.url);
expect(new Set(result.frames)).toEqual(new Set(expectedData.frames));
}
);
10 changes: 5 additions & 5 deletions tests/mangafire/mangafire.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {
ScrapedDetailedManga,
ScrapedListOfManga,
ScrapedDetailedChapter,
} from "../../src/index.js";
} from "../../src/index";

describe("should load latest manga", async () => {
const scraper = await MangaScraperFactory.make(MangaSource.MANGAFIRE);

test("without any props", async () => {
const result = await scraper.getLatestUpdates();

expect(result.data.length).toBeGreaterThanOrEqual(1);
expectTypeOf(result).toEqualTypeOf<ScrapedListOfManga>();
});
Expand All @@ -28,18 +28,18 @@ describe("should load latest manga", async () => {
test('should search "san"', async () => {
const scraper = await MangaScraperFactory.make(MangaSource.MANGAFIRE);
const result = await scraper.search("san");

expectTypeOf(result).toEqualTypeOf<ScrapedListOfManga>();
});

test('should get detailed manga information',async () => {
test("should get detailed manga information", async () => {
const scraper = await MangaScraperFactory.make(MangaSource.MANGAFIRE);
const result = await scraper.getDetailedManga("https://mangafire.to/manga/mushibamihime.qn0q5");

expectTypeOf(result).toEqualTypeOf<ScrapedDetailedManga>();
});

test('should get detailed chapter information', async () => {
test("should get detailed chapter information", async () => {
const scraper = await MangaScraperFactory.make(MangaSource.MANGAFIRE);
const result = await scraper.getDetailedChapter("https://mangafire.to/read/mushibamihime.qn0q5/en/chapter-6");

Expand Down
2 changes: 1 addition & 1 deletion tests/mangafire/mangafire.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, test, expect } from "vitest";
import { MangaSource, MangaScraperFactory } from "../../src/index.js";
import { MangaSource, MangaScraperFactory } from "../../src/index";
import path from "node:path";

const MANGA_DATA_TO_DETAILED_SCRAPE = [
Expand Down
2 changes: 1 addition & 1 deletion tests/manganato/manganato.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ScrapedDetailedManga,
ScrapedListOfManga,
ScrapedDetailedChapter,
} from "../../src/index.js";
} from "../../src/index";

describe("should load latest manga", async () => {
const scraper = await MangaScraperFactory.make(MangaSource.MANGANATO);
Expand Down
2 changes: 1 addition & 1 deletion tests/manganato/manganato.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, test, expect, assert } from "vitest";
import { MangaSource, MangaScraperFactory } from "../../src/index.js";
import { MangaSource, MangaScraperFactory } from "../../src/index";
import path from "path";

const MANGA_DATA_TO_DETAILED_SCRAPE = [
Expand Down
Loading

0 comments on commit 3609e11

Please sign in to comment.