feat: Remove Vercel dependencies (#21)

This PR remove the need to use Vercel to setup the server, currently it can still be used as such using the api folder
This commit is contained in:
Florian Bouillon 2022-12-05 11:47:18 +01:00 committed by GitHub
parent 7be0ac3957
commit 3938dc98fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 4703 additions and 5298 deletions

View File

@ -1,73 +1,5 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"root": true,
"ignorePatterns": [
"out",
".next",
"node_modules",
"*.js"
],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"google",
"plugin:@typescript-eslint/recommended",
"plugin:sonarjs/recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"settings": {
"react": {
"version": "detect"
},
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
}
}
},
"plugins": [
"react",
"@typescript-eslint",
"sonarjs",
"import"
],
"rules": {
"indent": ["error", "tab"],
"@typescript-eslint/quotes": ["error", "single", { "avoidEscape": true }],
"semi": ["error", "never"],
"no-tabs": "off",
"require-jsdoc": "off",
"no-invalid-this": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"max-len": ["warn", { "code": 120 }],
"object-curly-spacing": ["error", "always"],
"comma-dangle": ["error", "never"],
"padded-blocks": ["error", { "classes": "always" }],
"import/order": ["error"],
"import/no-named-as-default-member": "off",
"import/no-named-as-default": "off",
"camelcase": "off",
"valid-jsdoc": "off"
}
}
"./node_modules/@dzeio/config/eslint/react-typescript"
]
}

5
.gitattributes vendored
View File

@ -1 +1,4 @@
dist/* linguist-vendored=false
* text=auto eol=lf
*.png binary
*.jpg binary
*.jpeg binary

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ node_modules
.vscode/
coverage
yarn-error.log
dist/

View File

@ -1,3 +0,0 @@
.env
package-lock.json
coverage

50
Dockerfile Normal file
View File

@ -0,0 +1,50 @@
# Production Dockerfile
FROM docker.io/node:alpine as BUILD_IMAGE
# Build ENVS
# ENV TEST=YES
# External deps (for node-gyp add: "python3 make g++")
# git is used to install the npm packages with git deps
# RUN apk add --no-cache git
USER node
WORKDIR /home/node
ADD --chown=node:node package.json package-lock.json ./
# install dependencies
RUN npm ci
# Add project files
ADD --chown=node:node . .
# build
RUN npm run build
# remove dev dependencies
RUN npm ci --omit=dev
# go to another VM
FROM node:alpine AS PROD_IMAGE
# Production ENVS
ENV NODE_ENV=production
USER node
# go to folder
WORKDIR /home/node
# copy from build image
COPY --chown=node:node --from=BUILD_IMAGE /home/node/package.json ./package.json
COPY --chown=node:node --from=BUILD_IMAGE /home/node/dist ./dist
COPY --chown=node:node --from=BUILD_IMAGE /home/node/node_modules ./node_modules
# Expose port
EXPOSE 3000
# run it !
CMD ["npm", "run", "start"]

View File

@ -19,21 +19,21 @@ Copy paste this into your markdown content, and that's it. Simple!
Change the `?username=` value to your GitHub's username.
```md
[![Avior's code::stats stats](https://codestats-readme.vercel.app/api?username=aviortheking)](https://github.com/Aviortheking/codestats-readme)
[![Avior's code::stats stats](https://codestats-readme.avior.me/api?username=aviortheking)](https://github.com/Aviortheking/codestats-readme)
```
[![Avior's code::stats stats](https://codestats-readme.vercel.app/api?username=aviortheking)](https://github.com/Aviortheking/codestats-readme)
[![Avior's code::stats stats](https://codestats-readme.avior.me/api?username=aviortheking)](https://github.com/Aviortheking/codestats-readme)
### Options
| Option Name | Preview | Description |
| ----------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| hide | ![](https://codestats-readme.vercel.app/api?username=aviortheking&hide=xp) | Hide specific line, ex: `&hide=xp` or `&hide=xp,recent_xp` |
| show_icons | ![](https://codestats-readme.vercel.app/api?username=aviortheking&show_icons) | shows icons before each lines ex: `&show_icons` |
| hide_rank | ![](https://codestats-readme.vercel.app/api?username=aviortheking&hide_rank) | hide the rank circle ex: `&hide_rank` |
| line_height | ![](https://codestats-readme.vercel.app/api?username=aviortheking&line_height=45) | change the line Height of each lines, ex: `&line_height=45` |
| icon_color | ![](https://codestats-readme.vercel.app/api?username=aviortheking&icon_color=123456&show_icons) | change the icons color, ex: `&icon_color=123456&show_icons` |
| text_color | ![](https://codestats-readme.vercel.app/api?username=aviortheking&text_color=123456) | change the text colors, ex: `&text_color=123456` |
| hide | ![](https://codestats-readme.avior.me/api?username=aviortheking&hide=xp) | Hide specific line, ex: `&hide=xp` or `&hide=xp,recent_xp` |
| show_icons | ![](https://codestats-readme.avior.me/api?username=aviortheking&show_icons) | shows icons before each lines ex: `&show_icons` |
| hide_rank | ![](https://codestats-readme.avior.me/api?username=aviortheking&hide_rank) | hide the rank circle ex: `&hide_rank` |
| line_height | ![](https://codestats-readme.avior.me/api?username=aviortheking&line_height=45) | change the line Height of each lines, ex: `&line_height=45` |
| icon_color | ![](https://codestats-readme.avior.me/api?username=aviortheking&icon_color=123456&show_icons) | change the icons color, ex: `&icon_color=123456&show_icons` |
| text_color | ![](https://codestats-readme.avior.me/api?username=aviortheking&text_color=123456) | change the text colors, ex: `&text_color=123456` |
# History Card
@ -44,24 +44,24 @@ Copy-paste this code into your readme and change the links.
Endpoint: `api/history?username=Aviortheking`
```md
[![History](https://codestats-readme.vercel.app/api/history/?username=Aviortheking)](https://github.com/aviortheking/codestats-readme)
[![History](https://codestats-readme.avior.me/api/history/?username=Aviortheking)](https://github.com/aviortheking/codestats-readme)
```
[![History](https://codestats-readme.vercel.app/api/history/?username=Aviortheking)](https://github.com/aviortheking/codestats-readme)
[![History](https://codestats-readme.avior.me/api/history/?username=Aviortheking)](https://github.com/aviortheking/codestats-readme)
### Options
| Option Name | Preview | Description |
| -------------- | ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| layout | ![](https://codestats-readme.vercel.app/api/history?username=Aviortheking&layout=horizontal) | Change the layout to the horizontal one<br />ex: `&layout=horizontal` |
| height | ![](https://codestats-readme.vercel.app/api/history?username=Aviortheking&height=400&layout=horizontal) | Change the height of the card _Only on horizontal layout_<br />ex: `&height=400`<br />Default: `300` |
| width | ![](https://codestats-readme.vercel.app/api/history?username=Aviortheking&width=400) | Change the width of the card _Only on vertical layout_<br />ex: `&width=TypeScript`<br />Default: `500` |
| title | ![](https://codestats-readme.vercel.app/api/history?username=Aviortheking&title=History) | Change the title of the card<br />ex: `&title=History` |
| days_count | ![](https://codestats-readme.vercel.app/api/history?username=Aviortheking&days_count=7) | Change the number of days shown<br />ex: `&days_count=7` <br />Default: `14` |
| reverse_order | ![](https://codestats-readme.vercel.app/api/history?username=Aviortheking&reverse_order) | Reverse the order of the days<br />ex: `&reverse_order` |
| hide | ![](https://codestats-readme.vercel.app/api/history?username=Aviortheking&hide=Typescript) | Hide specifics languages and put them in Others<br />ex: `&hide=TypeScript` |
| language_count | ![](https://codestats-readme.vercel.app/api/history?username=Aviortheking&language_count=3) | Change the number of languages shown before going to Others<br />ex: `&language_count=3`<br />defaults: `8` |
| text_color | ![](https://codestats-readme.vercel.app/api/history?username=Aviortheking&text_color=654321) | change the text colors<br />ex: `&text_color=654321` |
| layout | ![](https://codestats-readme.avior.me/api/history?username=Aviortheking&layout=horizontal) | Change the layout to the horizontal one<br />ex: `&layout=horizontal` |
| height | ![](https://codestats-readme.avior.me/api/history?username=Aviortheking&height=400&layout=horizontal) | Change the height of the card _Only on horizontal layout_<br />ex: `&height=400`<br />Default: `300` |
| width | ![](https://codestats-readme.avior.me/api/history?username=Aviortheking&width=400) | Change the width of the card _Only on vertical layout_<br />ex: `&width=TypeScript`<br />Default: `500` |
| title | ![](https://codestats-readme.avior.me/api/history?username=Aviortheking&title=History) | Change the title of the card<br />ex: `&title=History` |
| days_count | ![](https://codestats-readme.avior.me/api/history?username=Aviortheking&days_count=7) | Change the number of days shown<br />ex: `&days_count=7` <br />Default: `14` |
| reverse_order | ![](https://codestats-readme.avior.me/api/history?username=Aviortheking&reverse_order) | Reverse the order of the days<br />ex: `&reverse_order` |
| hide | ![](https://codestats-readme.avior.me/api/history?username=Aviortheking&hide=Typescript) | Hide specifics languages and put them in Others<br />ex: `&hide=TypeScript` |
| language_count | ![](https://codestats-readme.avior.me/api/history?username=Aviortheking&language_count=3) | Change the number of languages shown before going to Others<br />ex: `&language_count=3`<br />defaults: `8` |
| text_color | ![](https://codestats-readme.avior.me/api/history?username=Aviortheking&text_color=654321) | change the text colors<br />ex: `&text_color=654321` |
# Top Languages Card
@ -69,44 +69,44 @@ Top languages card shows user's top languages.
Copy-paste this code into your readme and change the links.
Endpoint: `api/top-langs?username=anuraghazra`
Endpoint: `api/top-langs?username=aviortheking`
```md
[![Top Langs](https://codestats-readme.vercel.app/api/top-langs/?username=aviortheking)](https://github.com/aviortheking/codestats-readme)
[![Top Langs](https://codestats-readme.avior.me/api/top-langs/?username=aviortheking)](https://github.com/aviortheking/codestats-readme)
```
[![Top Langs](https://codestats-readme.vercel.app/api/top-langs/?username=aviortheking)](https://github.com/aviortheking/codestats-readme)
[![Top Langs](https://codestats-readme.avior.me/api/top-langs/?username=aviortheking)](https://github.com/aviortheking/codestats-readme)
### Options
| Option Name | Preview | Description |
| -------------- | ---------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| hide | ![](https://codestats-readme.vercel.app/api/top-langs?username=aviortheking&hide=TypeScript) | Hide Specific language<br />ex: `&hide=TypeScript` or `&hide=TypeScript,TypeScript%20(JSX)` |
| language_count | ![](https://codestats-readme.vercel.app/api/top-langs?username=aviortheking&language_count=3) | Change the number of languages shown before going to Others<br />ex: `&language_count=3`<br />defaults: `8` |
| card_width | ![](https://codestats-readme.vercel.app/api/top-langs?username=aviortheking&card_width=250) | hide the rank circle<br />ex: `&card_width=600`<br />defaults: `300` |
| layout | ![](https://codestats-readme.vercel.app/api/top-langs?username=aviortheking&layout=compact) | make the layout more compact<br />ex: `&layout=compact` |
| text_color | ![](https://codestats-readme.vercel.app/api/top-langs?username=aviortheking&text_color=654321) | change the text colors<br />ex: `&text_color=654321` |
| hide | ![](https://codestats-readme.avior.me/api/top-langs?username=aviortheking&hide=TypeScript) | Hide Specific language<br />ex: `&hide=TypeScript` or `&hide=TypeScript,TypeScript%20(JSX)` |
| language_count | ![](https://codestats-readme.avior.me/api/top-langs?username=aviortheking&language_count=3) | Change the number of languages shown before going to Others<br />ex: `&language_count=3`<br />defaults: `8` |
| card_width | ![](https://codestats-readme.avior.me/api/top-langs?username=aviortheking&card_width=250) | hide the rank circle<br />ex: `&card_width=600`<br />defaults: `300` |
| layout | ![](https://codestats-readme.avior.me/api/top-langs?username=aviortheking&layout=compact) | make the layout more compact<br />ex: `&layout=compact` |
| text_color | ![](https://codestats-readme.avior.me/api/top-langs?username=aviortheking&text_color=654321) | change the text colors<br />ex: `&text_color=654321` |
# Common Options
| Options Name | Preview | Description |
| ------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| title_color | ![](https://codestats-readme.vercel.app/api?username=aviortheking&title_color=654321) | Change the title color<br />ex: `&title_color=654321` |
| bg_color | ![](https://codestats-readme.vercel.app/api?username=aviortheking&bg_color=654321) | Change the background color<br />ex: `&bg_color=654321` |
| hide_border | ![](https://codestats-readme.vercel.app/api?username=aviortheking&hide_border) | Hide the border<br />ex: `&hide_border` |
| hide_title | ![](https://codestats-readme.vercel.app/api?username=aviortheking&hide_title) | Hide the title<br />ex: `&hide_border` |
| theme | ![](https://codestats-readme.vercel.app/api?username=aviortheking&theme=radical) | See [#themes](Themes) |
| cache_seconds | ![](https://codestats-readme.vercel.app/api?username=aviortheking&cache_seconds=86400) | set the cache header manually _(min: 1800, max: 86400)_<br />ex: `&cache_seconds=86400`<br />Default: `1800` or 30 minutes |
| title_color | ![](https://codestats-readme.avior.me/api?username=aviortheking&title_color=654321) | Change the title color<br />ex: `&title_color=654321` |
| bg_color | ![](https://codestats-readme.avior.me/api?username=aviortheking&bg_color=654321) | Change the background color<br />ex: `&bg_color=654321` |
| hide_border | ![](https://codestats-readme.avior.me/api?username=aviortheking&hide_border) | Hide the border<br />ex: `&hide_border` |
| hide_title | ![](https://codestats-readme.avior.me/api?username=aviortheking&hide_title) | Hide the title<br />ex: `&hide_border` |
| theme | ![](https://codestats-readme.avior.me/api?username=aviortheking&theme=radical) | See [#themes](Themes) |
| cache_seconds | ![](https://codestats-readme.avior.me/api?username=aviortheking&cache_seconds=86400) | set the cache header manually _(min: 1800, max: 86400)_<br />ex: `&cache_seconds=86400`<br />Default: `1800` or 30 minutes |
With inbuilt themes you can customize the look of the card without doing any [manual customization](#customization).
Use `?theme=THEME_NAME` parameter like so :-
```md
![Aviortheking's Code::Stats stats](https://codestats-readme.vercel.app/api?username=aviortheking&show_icons=true&theme=nightowl)
![Aviortheking's Code::Stats stats](https://codestats-readme.avior.me/api?username=aviortheking&show_icons=true&theme=nightowl)
```
![Aviortheking's Code::Stats stats](https://codestats-readme.vercel.app/api?username=aviortheking&show_icons=true&theme=nightowl)
![Aviortheking's Code::Stats stats](https://codestats-readme.avior.me/api?username=aviortheking&show_icons=true&theme=nightowl)
#### All inbuilt themes :-
@ -122,42 +122,26 @@ You usually won't be able to layout the images side by side. To do that you can
```md
<a href="https://github.com/aviortheking/codestats-readme">
<img align="center" src="https://codestats-readme.vercel.app/api?username=aviortheking" />
<img align="center" src="https://codestats-readme.avior.me/api?username=aviortheking" />
</a>
<a href="https://github.com/aviortheking/codestats-readme">
<img align="center" src="https://codestats-readme.vercel.app/api/top-langs/?username=aviortheking" />
<img align="center" src="https://codestats-readme.avior.me/api/top-langs/?username=aviortheking" />
</a>
```
## Deploy on your own Vercel instance
## Deploy on your own Server
[![Deploy to Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/Aviortheking/codestats-readme/)
<details>
<summary><b> Guide on setting up Vercel 🔨 </b></summary>
1. Go to [vercel.com](https://vercel.com/)
2. Click on `Log in`
![](https://files.catbox.moe/tct1wg.png)
3. Sign in with GitHub by pressing `Continue with GitHub`
![](https://files.catbox.moe/btd78j.jpeg)
4. Sign into GitHub and allow access to all repositories, if prompted
5. Fork this repo
6. Go back to your [Vercel dashboard](https://vercel.com/dashboard)
7. Select `Import Project`
![](https://files.catbox.moe/qckos0.png)
8. Select `Import Git Repository`
![](https://files.catbox.moe/pqub9q.png)
9. Select root and keep everything as is (leave everything as is, just name it something, it can be anything you want)
![](https://files.catbox.moe/0ez4g7.png)
10. Click deploy, and you're good to go. See your domains to use the API!
1. Build the Docker image `docker build . --tag your-tag`
2. run the Docker image `docker run your-tag`
3. Profit on the port 3000!
</details>
---
![https://vercel.com](https://res.cloudinary.com/anuraghazra/image/upload/v1597827714/powered-by-vercel_1_ug4uro.svg)
Contributions are welcomed! <3
Made with :heart: and Typescript.

View File

@ -53,7 +53,7 @@ export default async (req: Request<unknown, unknown, unknown, query>, res: Respo
try {
const data = await fetchHistory(username, clampValue(parseNumber(days_count) || 14, 1, 30))
setCache(res, parseInt(cache_seconds || ''))
setCache(res, parseInt(cache_seconds || '', 10))
return res.send(ReactDOMServer.renderToStaticMarkup(
new HistoryCard(username, data, {
@ -73,7 +73,7 @@ export default async (req: Request<unknown, unknown, unknown, query>, res: Respo
))
} catch (err) {
return res.send(
ReactDOMServer.renderToStaticMarkup(new Error(err).render())
ReactDOMServer.renderToStaticMarkup(new Error(err as any).render())
)
}
}

View File

@ -49,7 +49,7 @@ export default async (req: Request<unknown, unknown, unknown, query>, res: Respo
try {
const data = await fetchProfile(username)
setCache(res, parseInt(cache_seconds || ''))
setCache(res, parseInt(cache_seconds || '', 10))
return res.send(ReactDOMServer.renderToStaticMarkup(
new ProfileCard(data.username, data.xp, data.recentXp, {
@ -68,7 +68,7 @@ export default async (req: Request<unknown, unknown, unknown, query>, res: Respo
))
} catch (err) {
return res.send(
ReactDOMServer.renderToStaticMarkup(new Error(err).render())
ReactDOMServer.renderToStaticMarkup(new Error(err as any).render())
)
}
}

View File

@ -43,7 +43,7 @@ export default async (req: Request<unknown, unknown, unknown, query>, res: Respo
try {
const topLangs = await fetchTopLanguages(username)
setCache(res, parseInt(cache_seconds || ''))
setCache(res, parseInt(cache_seconds || '', 10))
return res.send(ReactDOMServer.renderToStaticMarkup(
new TopLanguagesCard(username, topLangs.langs, {
@ -61,7 +61,7 @@ export default async (req: Request<unknown, unknown, unknown, query>, res: Respo
))
} catch (err) {
return res.send(
ReactDOMServer.renderToStaticMarkup(new Error(err).render())
ReactDOMServer.renderToStaticMarkup(new Error(err as any).render())
)
}
}

19
index.ts Normal file
View File

@ -0,0 +1,19 @@
import express from 'express'
import api from './api'
import history from './api/history'
import topLangs from './api/top-langs'
const app = express()
app.use('/api', api)
app.use('/api/history', history)
app.use('/api/top-langs', topLangs)
app.get('/', (_, res) => {
res.redirect(301, 'https://github.com/aviortheking/codestats-readme')
})
app.listen(3000, () => {
console.log('server launched!')
})

4556
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,33 +4,30 @@
"description": "Dynamically generate stats for your github readmes",
"main": "index.js",
"scripts": {
"start": "vercel dev",
"dev": "ts-node ./index.ts",
"build": "tsc --project ./tsconfig.json",
"start": "node dist/index.js",
"theme-readme-gen": "ts-node scripts/generate-theme-doc"
},
"author": "Anurag Hazra",
"license": "MIT",
"devDependencies": {
"@types/express": "^4.17.8",
"@types/node-fetch": "^2.5.7",
"@types/react": "^16.9.49",
"@types/react-dom": "^16.9.8",
"@typescript-eslint/eslint-plugin": "^4.1.1",
"@typescript-eslint/parser": "^4.1.1",
"eslint": "^7.9.0",
"eslint-config-google": "^0.14.0",
"eslint-import-resolver-typescript": "^2.3.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-sonarjs": "^0.5.0",
"jest": "^26.1.0",
"ts-node": "^9.0.0",
"vercel": "^20.1.0"
"@types/express": "^4",
"@types/node-fetch": "^2",
"@types/react": "^18",
"@types/react-dom": "^18",
"@typescript-eslint/eslint-plugin": "^5",
"@typescript-eslint/parser": "^5",
"eslint": "^8",
"ts-node": "^10"
},
"dependencies": {
"node-fetch": "^2.6.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"typescript": "^4.0.2",
"word-wrap": "^1.2.3"
"@dzeio/config": "^1.1.8",
"express": "^4",
"node-fetch": "^2",
"react": "^18",
"react-dom": "^18",
"typescript": "^4",
"word-wrap": "^1"
}
}

View File

@ -5,11 +5,15 @@
"allowJs": true,
"checkJs": true,
"jsx": "react",
"outDir": "dist",
"strict": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
},
"files": [
"index.ts"
]
}

View File

@ -1,8 +0,0 @@
{
"redirects": [
{
"source": "/",
"destination": "https://github.com/aviortheking/codestats-readme"
}
]
}

5130
yarn.lock

File diff suppressed because it is too large Load Diff