From 5c25f9c429861df9778e39aa7a6cb1a88bc5952a Mon Sep 17 00:00:00 2001 From: rickstaa Date: Thu, 13 Oct 2022 10:38:00 +0200 Subject: [PATCH] refactor: improve folder structure --- .github/labeler.yml | 2 +- api/index.js | 2 +- api/pin.js | 2 +- api/top-langs.js | 2 +- api/wakatime.js | 2 +- src/{ => assets}/translations.js | 2 +- src/cards/repo-card.js | 2 +- src/cards/stats-card.js | 4 ++-- src/cards/top-languages-card.js | 2 +- src/cards/wakatime-card.js | 4 ++-- src/common/Card.js | 2 +- src/{ => common}/getStyles.js | 0 src/{ => fetchers/helpers}/calculateRank.js | 0 src/fetchers/stats-fetcher.js | 2 +- tests/api.test.js | 2 +- tests/calculateRank.test.js | 2 +- tests/fetchStats.test.js | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) rename src/{ => assets}/translations.js (99%) rename src/{ => common}/getStyles.js (100%) rename src/{ => fetchers/helpers}/calculateRank.js (100%) diff --git a/.github/labeler.yml b/.github/labeler.yml index be97765f..5b2a4b9c 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,3 +1,3 @@ themes: themes/index.js doc-translation: docs/* -card-i18n: src/translations.js +card-i18n: src/assets/translations.js diff --git a/api/index.js b/api/index.js index b449d43b..24f3ee61 100644 --- a/api/index.js +++ b/api/index.js @@ -8,7 +8,7 @@ import { renderError, } from "../src/common/utils.js"; import { fetchStats } from "../src/fetchers/stats-fetcher.js"; -import { isLocaleAvailable } from "../src/translations.js"; +import { isLocaleAvailable } from "../src/assets/translations.js"; export default async (req, res) => { const { diff --git a/api/pin.js b/api/pin.js index 4838b0f0..9c336737 100644 --- a/api/pin.js +++ b/api/pin.js @@ -7,7 +7,7 @@ import { renderError, } from "../src/common/utils.js"; import { fetchRepo } from "../src/fetchers/repo-fetcher.js"; -import { isLocaleAvailable } from "../src/translations.js"; +import { isLocaleAvailable } from "../src/assets/translations.js"; export default async (req, res) => { const { diff --git a/api/top-langs.js b/api/top-langs.js index d183d3b4..d621a1b1 100644 --- a/api/top-langs.js +++ b/api/top-langs.js @@ -8,7 +8,7 @@ import { renderError, } from "../src/common/utils.js"; import { fetchTopLanguages } from "../src/fetchers/top-languages-fetcher.js"; -import { isLocaleAvailable } from "../src/translations.js"; +import { isLocaleAvailable } from "../src/assets/translations.js"; export default async (req, res) => { const { diff --git a/api/wakatime.js b/api/wakatime.js index d439c5b7..e5dde3f4 100644 --- a/api/wakatime.js +++ b/api/wakatime.js @@ -7,7 +7,7 @@ import { renderError, } from "../src/common/utils.js"; import { fetchWakatimeStats } from "../src/fetchers/wakatime-fetcher.js"; -import { isLocaleAvailable } from "../src/translations.js"; +import { isLocaleAvailable } from "../src/assets/translations.js"; export default async (req, res) => { const { diff --git a/src/translations.js b/src/assets/translations.js similarity index 99% rename from src/translations.js rename to src/assets/translations.js index 45c8295e..b13bc570 100644 --- a/src/translations.js +++ b/src/assets/translations.js @@ -1,4 +1,4 @@ -import { encodeHTML } from "./common/utils.js"; +import { encodeHTML } from "../common/utils.js"; /** * Retrieves stat card labels in the available locales. diff --git a/src/cards/repo-card.js b/src/cards/repo-card.js index a306c1d5..394144de 100644 --- a/src/cards/repo-card.js +++ b/src/cards/repo-card.js @@ -11,7 +11,7 @@ import { parseEmojis, wrapTextMultiline, } from "../common/utils.js"; -import { repoCardLocales } from "../translations.js"; +import { repoCardLocales } from "../assets/translations.js"; /** * Retrieves the repository description and wraps it to fit the card width. diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index a049ecce..0a2e6cc4 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -9,8 +9,8 @@ import { kFormatter, measureText, } from "../common/utils.js"; -import { getStyles } from "../getStyles.js"; -import { statCardLocales } from "../translations.js"; +import { getStyles } from "../common/getStyles.js"; +import { statCardLocales } from "../assets/translations.js"; /** * Create a stats card text item. diff --git a/src/cards/top-languages-card.js b/src/cards/top-languages-card.js index 602d1b81..7e26c620 100644 --- a/src/cards/top-languages-card.js +++ b/src/cards/top-languages-card.js @@ -10,7 +10,7 @@ import { lowercaseTrim, measureText, } from "../common/utils.js"; -import { langCardLocales } from "../translations.js"; +import { langCardLocales } from "../assets/translations.js"; const DEFAULT_CARD_WIDTH = 300; const MIN_CARD_WIDTH = 230; diff --git a/src/cards/wakatime-card.js b/src/cards/wakatime-card.js index e7af1df7..3407f7a5 100644 --- a/src/cards/wakatime-card.js +++ b/src/cards/wakatime-card.js @@ -8,8 +8,8 @@ import { getCardColors, lowercaseTrim, } from "../common/utils.js"; -import { getStyles } from "../getStyles.js"; -import { wakatimeCardLocales } from "../translations.js"; +import { getStyles } from "../common/getStyles.js"; +import { wakatimeCardLocales } from "../assets/translations.js"; /** Import language colors. * diff --git a/src/common/Card.js b/src/common/Card.js index 2f1d9c29..131ebfea 100644 --- a/src/common/Card.js +++ b/src/common/Card.js @@ -1,4 +1,4 @@ -import { getAnimations } from "../getStyles.js"; +import { getAnimations } from "./getStyles.js"; import { encodeHTML, flexLayout } from "./utils.js"; class Card { diff --git a/src/getStyles.js b/src/common/getStyles.js similarity index 100% rename from src/getStyles.js rename to src/common/getStyles.js diff --git a/src/calculateRank.js b/src/fetchers/helpers/calculateRank.js similarity index 100% rename from src/calculateRank.js rename to src/fetchers/helpers/calculateRank.js diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js index 7f6cb9e5..252127e0 100644 --- a/src/fetchers/stats-fetcher.js +++ b/src/fetchers/stats-fetcher.js @@ -1,7 +1,7 @@ // @ts-check import axios from "axios"; import githubUsernameRegex from "github-username-regex"; -import { calculateRank } from "../calculateRank.js"; +import { calculateRank } from "./helpers/calculateRank.js"; import { retryer } from "../common/retryer.js"; import { CustomError, diff --git a/tests/api.test.js b/tests/api.test.js index 0037bcdb..53c82177 100644 --- a/tests/api.test.js +++ b/tests/api.test.js @@ -2,7 +2,7 @@ import { jest } from "@jest/globals"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; import api from "../api/index.js"; -import { calculateRank } from "../src/calculateRank.js"; +import { calculateRank } from "../src/fetchers/helpers/calculateRank.js"; import { renderStatsCard } from "../src/cards/stats-card.js"; import { CONSTANTS, renderError } from "../src/common/utils.js"; diff --git a/tests/calculateRank.test.js b/tests/calculateRank.test.js index 235b1b5f..89059d3b 100644 --- a/tests/calculateRank.test.js +++ b/tests/calculateRank.test.js @@ -1,5 +1,5 @@ import "@testing-library/jest-dom"; -import { calculateRank } from "../src/calculateRank.js"; +import { calculateRank } from "../src/fetchers/helpers/calculateRank.js"; describe("Test calculateRank", () => { it("should calculate rank correctly", () => { diff --git a/tests/fetchStats.test.js b/tests/fetchStats.test.js index 192146ea..801934be 100644 --- a/tests/fetchStats.test.js +++ b/tests/fetchStats.test.js @@ -1,7 +1,7 @@ import "@testing-library/jest-dom"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; -import { calculateRank } from "../src/calculateRank.js"; +import { calculateRank } from "../src/fetchers/helpers/calculateRank.js"; import { fetchStats } from "../src/fetchers/stats-fetcher.js"; const data = {