Skip to content

Commit

Permalink
chore: opensource
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepolo committed Jan 3, 2025
0 parents commit 2e6c777
Show file tree
Hide file tree
Showing 22 changed files with 5,080 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
56 changes: 56 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: ci

on:
push:
branches:
- "main"
workflow_dispatch:

jobs:
docker:
runs-on: ubuntu-latest
strategy:
matrix:
platform: [linux/amd64, linux/arm64]
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract platform info
id: platform
run: echo "arch=$(echo ${{ matrix.platform }} | cut -d'/' -f2)" >> $GITHUB_OUTPUT
- name: Build container image
uses: docker/build-push-action@v6
with:
push: true
platforms: ${{ matrix.platform }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/game-server-node:buildcache-${{ steps.platform.outputs.arch }}
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/game-server-node:buildcache-${{ steps.platform.outputs.arch }},mode=max
tags: |
ghcr.io/${{ github.repository_owner }}/game-server-node:${{ github.sha }}-${{ steps.platform.outputs.arch }}
ghcr.io/${{ github.repository_owner }}/game-server-node:latest-${{ steps.platform.outputs.arch }}
merge:
needs: docker
runs-on: ubuntu-latest
steps:
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push
run: |
docker buildx imagetools create -t ghcr.io/${{ github.repository_owner }}/game-server-node:latest \
ghcr.io/${{ github.repository_owner }}/game-server-node:latest-amd64 \
ghcr.io/${{ github.repository_owner }}/game-server-node:latest-arm64
docker buildx imagetools create -t ghcr.io/${{ github.repository_owner }}/game-server-node:${{ github.sha }} \
ghcr.io/${{ github.repository_owner }}/game-server-node:${{ github.sha }}-amd64 \
ghcr.io/${{ github.repository_owner }}/game-server-node:${{ github.sha }}-arm64
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lib
.DS_Store
node_modules
coverage
temp
explorations
TODOs.md
*.log
.idea
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npm test
npx lint-staged
3 changes: 3 additions & 0 deletions .huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ~/.huskyrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/lib/*
Empty file added .prettierrc
Empty file.
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:22-alpine AS deps

WORKDIR /build

COPY package*.json ./
COPY yarn.lock ./

RUN yarn install --frozen-lockfile

FROM node:22-alpine AS build

WORKDIR /build

COPY --from=deps /build/node_modules ./node_modules
COPY . .

RUN yarn build

FROM node:22-alpine

WORKDIR /opt/5stack

COPY --from=build /build/node_modules ./node_modules
COPY --from=build /build/dist ./dist

CMD [ "node", "dist/cjs/index.js" ]
7 changes: 7 additions & 0 deletions codepier.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespaces: [5stack]
image: node:22
deployment: dev-game-server-node-connector
sync:
- .:/opt/5stack
ignore:
- "/dist"
21 changes: 21 additions & 0 deletions configs/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"baseUrl": ".",
"incremental": true,
"sourceMap": true,
"moduleResolution": "node",
"isolatedModules": true,
"strict": true,
"importHelpers": true,
"noUnusedLocals": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"skipLibCheck": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"declaration": true
},
"include": ["../src/**/*"]
}
10 changes: 10 additions & 0 deletions configs/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"lib": ["es2019"],
"target": "es2019",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "../dist/cjs"
}
}
10 changes: 10 additions & 0 deletions configs/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"lib": ["esnext"],
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"outDir": "../dist/esm"
}
}
27 changes: 27 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const DOMGlobals = ["window", "document"];
const NodeGlobals = ["module", "require"];

module.exports = {
parser: "@typescript-eslint/parser",
extends: ["plugin:@typescript-eslint/recommended"],
parserOptions: {
sourceType: "module",
project: "tsconfig.json",
},
plugins: ["@typescript-eslint"],
rules: {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"no-unused-vars": [
"error",
// we are only using this rule to check for unused arguments since TS
// catches unused variables but not args.
{ varsIgnorePattern: ".*", args: "none" },
],
// most of the codebase are expected to be env agnostic
"no-restricted-globals": ["error", ...DOMGlobals, ...NodeGlobals],
},
};
17 changes: 17 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { JestConfigWithTsJest } from "ts-jest";

const jestConfig: JestConfigWithTsJest = {
roots: ["<rootDir>"],
preset: "ts-jest",
testEnvironment: "node",
transform: {
"^.+\\.tsx?$": [
"ts-jest",
{
tsconfig: "configs/tsconfig.base.json",
},
],
},
};

export default jestConfig;
53 changes: 53 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "@5stack/game-server-node",
"version": "0.0.2",
"main": "./lib/cjs/index.js",
"files": [
"src",
"dist/**/*"
],
"scripts": {
"start": "node dist/cjs/index.js",
"test": "jest --ci --collect-coverage",
"test:watch": "jest --watch",
"clean": "rimraf ./lib",
"build": "npm run clean && npm run build:cjs",
"build:esm": "tsc -p ./configs/tsconfig.esm.json && mv lib/esm/index.js lib/esm/index.mjs",
"build:cjs": "tsc -p ./configs/tsconfig.cjs.json",
"prepack": "npm run build",
"nodemon": "wait-on dist/cjs/index.js && nodemon --watch ./dist/cjs/index.js ./dist/cjs/index.js",
"watch": "npm-run-all -p \"build:cjs -- --watch\" nodemon",
"prepare": "husky"
},
"dependencies": {
"@kubernetes/client-node": "^0.22.0",
"vdf-parser": "^1.2.1",
"ws": "^8.18.0"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/node": "^22.8.7",
"eslint": "^9.6.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"lint-staged": "^15.2.7",
"nodemon": "^3.1.4",
"npm-run-all": "^4.1.5",
"prettier": "^3.3.2",
"pretty-quick": "^4.0.0",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.2",
"ts-node": "^10.9.2",
"typescript": "^5.5.3",
"wait-on": "^8.0.0"
},
"lint-staged": {
"*.js": [
"prettier --write"
],
"*.ts?(x)": [
"eslint",
"prettier --parser=typescript --write"
]
}
}
Loading

0 comments on commit 2e6c777

Please sign in to comment.