diff --git a/.eslintrc.json b/.eslintrc.json index 8b2225b56..3552f6a7b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -102,6 +102,7 @@ // "@stylistic/multiline-ternary": "error", // not needed // "@stylistic/newline-per-chained-call": "error", // not sure if needed "@stylistic/new-parens": "error", + "@typescript-eslint/class-literal-property-style": "off", "@stylistic/no-confusing-arrow": "error", "@stylistic/wrap-iife": "error", "@stylistic/space-before-blocks": "error", diff --git a/.github/workflows/build-single-file.yml b/.github/workflows/build-single-file.yml new file mode 100644 index 000000000..93b1b77f4 --- /dev/null +++ b/.github/workflows/build-single-file.yml @@ -0,0 +1,31 @@ +name: build-single-file + +on: + workflow_dispatch: + +jobs: + build-and-bundle: + runs-on: ubuntu-latest + permissions: write-all + steps: + - name: Checkout repository + uses: actions/checkout@master + + - uses: actions/setup-node@v4 + with: + node-version: 22 + + - name: Install pnpm + uses: pnpm/action-setup@v4 + + - name: Install dependencies + run: pnpm install + + - name: Build single-file version - minecraft.html + run: pnpm build-single-file && mv dist/single/index.html minecraft.html + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: minecraft.html + path: minecraft.html diff --git a/.github/workflows/build-zip.yml b/.github/workflows/build-zip.yml new file mode 100644 index 000000000..cc4724768 --- /dev/null +++ b/.github/workflows/build-zip.yml @@ -0,0 +1,43 @@ +name: Make Self Host Zip + +on: + workflow_dispatch: + +jobs: + build-and-bundle: + runs-on: ubuntu-latest + permissions: write-all + steps: + - name: Checkout repository + uses: actions/checkout@master + + - uses: actions/setup-node@v4 + with: + node-version: 22 + + - name: Install pnpm + uses: pnpm/action-setup@v4 + + - name: Install dependencies + run: pnpm install + + - name: Build project + run: pnpm build + + - name: Bundle server.js + run: | + pnpm esbuild server.js --bundle --platform=node --outfile=bundled-server.js --define:process.env.NODE_ENV="'production'" + + - name: Create distribution package + run: | + mkdir -p package + cp -r dist package/ + cp bundled-server.js package/server.js + cd package + zip -r ../self-host.zip . + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: self-host + path: self-host.zip diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc54da4e6..92b7e7f3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: - run: pnpm build-storybook - run: pnpm test-unit - run: pnpm lint - - run: pnpm tsx scripts/buildNpmReact.ts + # - run: pnpm tsx scripts/buildNpmReact.ts - run: nohup pnpm prod-start & - run: nohup pnpm test-mc-server & - uses: cypress-io/github-action@v5 diff --git a/.github/workflows/next-deploy.yml b/.github/workflows/next-deploy.yml index 665abb30b..042302a41 100644 --- a/.github/workflows/next-deploy.yml +++ b/.github/workflows/next-deploy.yml @@ -32,6 +32,8 @@ jobs: echo "{\"latestTag\": \"$(git rev-parse --short $GITHUB_SHA)\", \"isCommit\": true}" > assets/release.json - name: Build Project Artifacts run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + env: + CONFIG_JSON_SOURCE: BUNDLED - run: pnpm build-storybook - name: Copy playground files run: | diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 18c80e8c7..4b755f7b3 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -52,6 +52,19 @@ jobs: with: node-version: 22 cache: "pnpm" + - name: Update deployAlwaysUpdate packages + run: | + if [ -f package.json ]; then + PACKAGES=$(node -e "const pkg = require('./package.json'); if (pkg.deployAlwaysUpdate) console.log(pkg.deployAlwaysUpdate.join(' '))") + if [ ! -z "$PACKAGES" ]; then + echo "Updating packages: $PACKAGES" + pnpm up -L $PACKAGES + else + echo "No deployAlwaysUpdate packages found in package.json" + fi + else + echo "package.json not found" + fi - name: Install Global Dependencies run: pnpm add -g vercel - name: Pull Vercel Environment Information @@ -61,6 +74,8 @@ jobs: echo "{\"latestTag\": \"$(git rev-parse --short ${{ github.event.pull_request.head.sha }})\", \"isCommit\": true}" > assets/release.json - name: Build Project Artifacts run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + env: + CONFIG_JSON_SOURCE: BUNDLED - run: pnpm build-storybook - name: Copy playground files run: | diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ce7f56b99..986bf6cc5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -30,6 +30,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: vercel build --token=${{ secrets.VERCEL_TOKEN }} --prod + env: + CONFIG_JSON_SOURCE: BUNDLED - run: pnpm build-storybook - name: Copy playground files run: | @@ -43,24 +45,43 @@ jobs: with: run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} --prod id: deploy + # publish to github + - run: cp vercel.json .vercel/output/static/vercel.json + - uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: .vercel/output/static + force_orphan: true + + - name: Build single-file version - minecraft.html + run: pnpm build-single-file && mv dist/single/index.html minecraft.html + - name: Build self-host version + run: pnpm build + - name: Bundle server.js + run: | + pnpm esbuild server.js --bundle --platform=node --outfile=bundled-server.js --define:process.env.NODE_ENV="'production'" + + - name: Create zip package + run: | + mkdir -p package + cp -r dist package/ + cp bundled-server.js package/server.js + cd package + zip -r ../self-host.zip . + - run: | pnpx zardoy-release node --footer "This release URL: ${{ steps.deploy.outputs.stdout }}" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # has possible output: tag id: release + # has output - - run: cp vercel.json .vercel/output/static/vercel.json - - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: .vercel/output/static - force_orphan: true - name: Set publishing config run: pnpm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}" env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - run: pnpm tsx scripts/buildNpmReact.ts ${{ steps.release.outputs.tag }} - if: steps.release.outputs.tag - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + # - run: pnpm tsx scripts/buildNpmReact.ts ${{ steps.release.outputs.tag }} + # if: steps.release.outputs.tag + # env: + # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index f2a0006e0..bd7743159 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ localSettings.mjs dist* .DS_Store .idea/ -world +/world data*.json out *.iml diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..1d085cacc --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +** diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fb0ae55e6..aa7c0a38f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,8 +5,6 @@ After forking the repository, run the following commands to get started: 0. Ensure you have [Node.js](https://nodejs.org) installed. Enable corepack with `corepack enable` *(1). 1. Install dependencies: `pnpm i` 2. Start the project in development mode: `pnpm start` or build the project for production: `pnpm build` -3. Read the [Tasks Categories](#tasks-categories) and [Workflow](#workflow) sections below -4. Let us know if you are working on something and be sure to open a PR if you got any changes. Happy coding! *(1): If you are getting `Cannot find matching keyid` update corepack to the latest version with `npm i -g corepack`. *(2): If still something doesn't work ensure you have the right nodejs version with `node -v` (tested on 22.x) @@ -95,7 +93,7 @@ Also there are [src/generatedClientPackets.ts](src/generatedClientPackets.ts) an - Use `start-prod` script to start the project in production mode after running the `build` script to build the project. - If CI is failing on the next branch for some reason, feel free to use the latest commit for release branch. We will update the base branch asap. Please, always make sure to allow maintainers do changes when opening PRs. -## Tasks Categories +## Tasks Categories (from usptream repo. not relevant to Kradle) (most important for now are on top). @@ -166,7 +164,7 @@ Most of the tasks are straightforward to implement, just be sure to use a debugg New React components, improve UI (including mobile support). -## Workflow +## Workflow (from usptream repo. not relevant to Kradle) 1. Locate the problem on the public test server & make an easily reproducible environment (you can also use local packets replay server or your custom server setup). Dm me for details on public test server / replay server 2. Debug the code, find an issue in the code, isolate the problem diff --git a/Dockerfile b/Dockerfile index 4769141f7..346413536 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ RUN npm i -g pnpm@9.0.4 # Build arguments ARG DOWNLOAD_SOUNDS=false ARG DISABLE_SERVICE_WORKER=false +ARG CONFIG_JSON_SOURCE=REMOTE # TODO need flat --no-root-optional RUN node ./scripts/dockerPrepare.mjs RUN pnpm i @@ -22,8 +23,8 @@ RUN if [ "$DOWNLOAD_SOUNDS" = "true" ] ; then node scripts/downloadSoundsMap.mjs # ENTRYPOINT ["pnpm", "run", "run-all"] # only for prod -RUN GITHUB_REPOSITORY=zardoy/minecraft-web-client \ - DISABLE_SERVICE_WORKER=$DISABLE_SERVICE_WORKER \ +RUN DISABLE_SERVICE_WORKER=$DISABLE_SERVICE_WORKER \ + CONFIG_JSON_SOURCE=$CONFIG_JSON_SOURCE \ pnpm run build # ---- Run Stage ---- diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..530b77b93 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +REGION=us-central1 +PROJECT_ID=mckradle-3c267 +DOCKER_URL=${REGION}-docker.pkg.dev/${PROJECT_ID}/${env}-arenas/web-viewer-client +IMAGE_TAG=${DOCKER_URL}:$(shell git rev-parse --short HEAD) +SERVICE_NAME=web-proxy + +ifndef env + override env = dev +endif + +docker/login: + gcloud auth configure-docker ${REGION}-docker.pkg.dev + +docker/build: + docker buildx build --platform linux/amd64,linux/arm64 . -f Dockerfile --load -t ${IMAGE_TAG} + +docker/push: + docker push ${IMAGE_TAG} + +deploy: + gcloud run deploy ${SERVICE_NAME} --image ${IMAGE_TAG} --region ${REGION} \ No newline at end of file diff --git a/README.MD b/README.MD index 922984d19..0f4b05f9d 100644 --- a/README.MD +++ b/README.MD @@ -1,6 +1,70 @@ # Minecraft Web Client -![banner](./docs-assets/banner.jpg) +This is a browser implementation of Minecraft we embed inside the Kradle frontend to view session. This repo contains 2 parts - + +## First: A Web Client + +The web client is [deployed to Vercel](https://vercel.com/kradle-f5bad6db/minecraft-web-client) and is accessible at https://mcraft.kradle.ai. The Kradle frontend at https://app.kradle.ai uses an `