mirror of
https://github.com/Aviortheking/codestats-readme.git
synced 2025-04-22 02:32:09 +00:00
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:
parent
7be0ac3957
commit
3938dc98fc
@ -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
5
.gitattributes
vendored
@ -1 +1,4 @@
|
||||
dist/* linguist-vendored=false
|
||||
* text=auto eol=lf
|
||||
*.png binary
|
||||
*.jpg binary
|
||||
*.jpeg binary
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ node_modules
|
||||
.vscode/
|
||||
coverage
|
||||
yarn-error.log
|
||||
dist/
|
@ -1,3 +0,0 @@
|
||||
.env
|
||||
package-lock.json
|
||||
coverage
|
50
Dockerfile
Normal file
50
Dockerfile
Normal 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"]
|
98
README.md
98
README.md
@ -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
|
||||
[](https://github.com/Aviortheking/codestats-readme)
|
||||
[](https://github.com/Aviortheking/codestats-readme)
|
||||
```
|
||||
|
||||
[](https://github.com/Aviortheking/codestats-readme)
|
||||
[](https://github.com/Aviortheking/codestats-readme)
|
||||
|
||||
### Options
|
||||
|
||||
| Option Name | Preview | Description |
|
||||
| ----------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
|
||||
| hide |  | Hide specific line, ex: `&hide=xp` or `&hide=xp,recent_xp` |
|
||||
| show_icons |  | shows icons before each lines ex: `&show_icons` |
|
||||
| hide_rank |  | hide the rank circle ex: `&hide_rank` |
|
||||
| line_height |  | change the line Height of each lines, ex: `&line_height=45` |
|
||||
| icon_color |  | change the icons color, ex: `&icon_color=123456&show_icons` |
|
||||
| text_color |  | change the text colors, ex: `&text_color=123456` |
|
||||
| hide |  | Hide specific line, ex: `&hide=xp` or `&hide=xp,recent_xp` |
|
||||
| show_icons |  | shows icons before each lines ex: `&show_icons` |
|
||||
| hide_rank |  | hide the rank circle ex: `&hide_rank` |
|
||||
| line_height |  | change the line Height of each lines, ex: `&line_height=45` |
|
||||
| icon_color |  | change the icons color, ex: `&icon_color=123456&show_icons` |
|
||||
| text_color |  | 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
|
||||
[](https://github.com/aviortheking/codestats-readme)
|
||||
[](https://github.com/aviortheking/codestats-readme)
|
||||
```
|
||||
|
||||
[](https://github.com/aviortheking/codestats-readme)
|
||||
[](https://github.com/aviortheking/codestats-readme)
|
||||
|
||||
### Options
|
||||
|
||||
| Option Name | Preview | Description |
|
||||
| -------------- | ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
||||
| layout |  | Change the layout to the horizontal one<br />ex: `&layout=horizontal` |
|
||||
| height |  | Change the height of the card _Only on horizontal layout_<br />ex: `&height=400`<br />Default: `300` |
|
||||
| width |  | Change the width of the card _Only on vertical layout_<br />ex: `&width=TypeScript`<br />Default: `500` |
|
||||
| title |  | Change the title of the card<br />ex: `&title=History` |
|
||||
| days_count |  | Change the number of days shown<br />ex: `&days_count=7` <br />Default: `14` |
|
||||
| reverse_order |  | Reverse the order of the days<br />ex: `&reverse_order` |
|
||||
| hide |  | Hide specifics languages and put them in Others<br />ex: `&hide=TypeScript` |
|
||||
| language_count |  | Change the number of languages shown before going to Others<br />ex: `&language_count=3`<br />defaults: `8` |
|
||||
| text_color |  | change the text colors<br />ex: `&text_color=654321` |
|
||||
| layout |  | Change the layout to the horizontal one<br />ex: `&layout=horizontal` |
|
||||
| height |  | Change the height of the card _Only on horizontal layout_<br />ex: `&height=400`<br />Default: `300` |
|
||||
| width |  | Change the width of the card _Only on vertical layout_<br />ex: `&width=TypeScript`<br />Default: `500` |
|
||||
| title |  | Change the title of the card<br />ex: `&title=History` |
|
||||
| days_count |  | Change the number of days shown<br />ex: `&days_count=7` <br />Default: `14` |
|
||||
| reverse_order |  | Reverse the order of the days<br />ex: `&reverse_order` |
|
||||
| hide |  | Hide specifics languages and put them in Others<br />ex: `&hide=TypeScript` |
|
||||
| language_count |  | Change the number of languages shown before going to Others<br />ex: `&language_count=3`<br />defaults: `8` |
|
||||
| text_color |  | 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
|
||||
[](https://github.com/aviortheking/codestats-readme)
|
||||
[](https://github.com/aviortheking/codestats-readme)
|
||||
```
|
||||
|
||||
[](https://github.com/aviortheking/codestats-readme)
|
||||
[](https://github.com/aviortheking/codestats-readme)
|
||||
|
||||
### Options
|
||||
|
||||
| Option Name | Preview | Description |
|
||||
| -------------- | ---------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
||||
| hide |  | Hide Specific language<br />ex: `&hide=TypeScript` or `&hide=TypeScript,TypeScript%20(JSX)` |
|
||||
| language_count |  | Change the number of languages shown before going to Others<br />ex: `&language_count=3`<br />defaults: `8` |
|
||||
| card_width |  | hide the rank circle<br />ex: `&card_width=600`<br />defaults: `300` |
|
||||
| layout |  | make the layout more compact<br />ex: `&layout=compact` |
|
||||
| text_color |  | change the text colors<br />ex: `&text_color=654321` |
|
||||
| hide |  | Hide Specific language<br />ex: `&hide=TypeScript` or `&hide=TypeScript,TypeScript%20(JSX)` |
|
||||
| language_count |  | Change the number of languages shown before going to Others<br />ex: `&language_count=3`<br />defaults: `8` |
|
||||
| card_width |  | hide the rank circle<br />ex: `&card_width=600`<br />defaults: `300` |
|
||||
| layout |  | make the layout more compact<br />ex: `&layout=compact` |
|
||||
| text_color |  | change the text colors<br />ex: `&text_color=654321` |
|
||||
|
||||
# Common Options
|
||||
|
||||
| Options Name | Preview | Description |
|
||||
| ------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
||||
| title_color |  | Change the title color<br />ex: `&title_color=654321` |
|
||||
| bg_color |  | Change the background color<br />ex: `&bg_color=654321` |
|
||||
| hide_border |  | Hide the border<br />ex: `&hide_border` |
|
||||
| hide_title |  | Hide the title<br />ex: `&hide_border` |
|
||||
| theme |  | See [#themes](Themes) |
|
||||
| cache_seconds |  | set the cache header manually _(min: 1800, max: 86400)_<br />ex: `&cache_seconds=86400`<br />Default: `1800` or 30 minutes |
|
||||
| title_color |  | Change the title color<br />ex: `&title_color=654321` |
|
||||
| bg_color |  | Change the background color<br />ex: `&bg_color=654321` |
|
||||
| hide_border |  | Hide the border<br />ex: `&hide_border` |
|
||||
| hide_title |  | Hide the title<br />ex: `&hide_border` |
|
||||
| theme |  | See [#themes](Themes) |
|
||||
| cache_seconds |  | 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
|
||||

|
||||

|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
#### 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
|
||||
|
||||
[](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`
|
||||

|
||||
3. Sign in with GitHub by pressing `Continue with GitHub`
|
||||

|
||||
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`
|
||||

|
||||
8. Select `Import Git Repository`
|
||||

|
||||
9. Select root and keep everything as is (leave everything as is, just name it something, it can be anything you want)
|
||||

|
||||
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>
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
Contributions are welcomed! <3
|
||||
|
||||
Made with :heart: and Typescript.
|
||||
|
@ -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())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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
19
index.ts
Normal 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
4556
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
39
package.json
39
package.json
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
]
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"redirects": [
|
||||
{
|
||||
"source": "/",
|
||||
"destination": "https://github.com/aviortheking/codestats-readme"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user