Skip to content

Commit

Permalink
build: create npm package
Browse files Browse the repository at this point in the history
This commit makes sure that the common modules of the GRS package can be
imported as a npm package.
  • Loading branch information
rickstaa committed Oct 7, 2022
1 parent 15620a1 commit efa8b2c
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
themes: themes/index.js
doc-translation: docs/*
card-i18n: src/translations.js
card-i18n: src/assets/translations.js
2 changes: 1 addition & 1 deletion api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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";

dotenv.config();

Expand Down
2 changes: 1 addition & 1 deletion api/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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";

dotenv.config();

Expand Down
2 changes: 1 addition & 1 deletion api/wakatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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";

dotenv.config();

Expand Down
18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
{
"name": "github-readme-stats",
"version": "1.0.0",
"description": "Dynamically generate stats for your github readmes",
"main": "index.js",
"description": "Dynamically generate stats for your GitHub readme",
"keywords": [
"github-readme-stats",
"readme-stats",
"cards",
"card-generator"
],
"main": "src/index.js",
"type": "module",
"homepage": "https://github.com/anuraghazra/github-readme-stats",
"bugs": {
"url": "https://github.com/anuraghazra/github-readme-stats/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/anuraghazra/github-readme-stats.git"
},
"scripts": {
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
"test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
Expand Down
2 changes: 1 addition & 1 deletion src/translations.js → src/assets/translations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { encodeHTML } from "./common/utils.js";
import { encodeHTML } from "../common/utils.js";

const statCardLocales = ({ name, apostrophe }) => {
const encodedName = encodeHTML(name);
Expand Down
2 changes: 1 addition & 1 deletion src/cards/repo-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
parseEmojis,
wrapTextMultiline,
} from "../common/utils.js";
import { repoCardLocales } from "../translations.js";
import { repoCardLocales } from "../assets/translations.js";

/**
* @param {string} label
Expand Down
4 changes: 2 additions & 2 deletions src/cards/stats-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/cards/top-languages-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/cards/wakatime-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/common/Card.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getAnimations } from "../getStyles.js";
import { getAnimations } from "./getStyles.js";
import { encodeHTML, flexLayout } from "./utils.js";

class Card {
Expand Down
File renamed without changes.
29 changes: 29 additions & 0 deletions src/common/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export { blacklist } from "./blacklist.js";
export { Card } from "./Card.js";
export { createProgressNode } from "./createProgressNode.js";
export { getStyles, getAnimations } from "./getStyles.js";
export { i18n } from "./i18n.js";
export { icons } from "./icons.js";
export { retryer } from "./retryer.js";
export {
renderError,
kFormatter,
encodeHTML,
isValidHexColor,
request,
parseArray,
parseBoolean,
fallbackColor,
flexLayout,
getCardColors,
clampValue,
wrapTextMultiline,
measureText,
logger,
CONSTANTS,
CustomError,
MissingParamError,
lowercaseTrim,
chunkArray,
parseEmojis,
} from "./utils.js";
File renamed without changes.
2 changes: 1 addition & 1 deletion src/fetchers/stats-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import axios from "axios";
import * as dotenv from "dotenv";
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,
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./common/index.js";
2 changes: 1 addition & 1 deletion tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion tests/calculateRank.test.js
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/fetchStats.test.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down

0 comments on commit efa8b2c

Please sign in to comment.