From c685f86dc4828874ff396fe53a007223da4a0b14 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Mon, 12 Jun 2023 02:01:32 +0000 Subject: [PATCH] feat: mature build script --- .github/workflows/host.yml | 2 +- .vscode/settings.json | 1 + package.json | 7 ++----- scripts/build.js | 23 +++++++++++++++++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 scripts/build.js diff --git a/.github/workflows/host.yml b/.github/workflows/host.yml index 1f512bc5f..ea8e67c5b 100644 --- a/.github/workflows/host.yml +++ b/.github/workflows/host.yml @@ -44,4 +44,4 @@ jobs: run: yarn - name: Host - run: NODE_ENV=production DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} WARGAMING_APPLICATION_ID=${{ secrets.WARGAMING_APPLICATION_ID }} yarn dev --dev + run: NODE_ENV=production DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} WARGAMING_APPLICATION_ID=${{ secrets.WARGAMING_APPLICATION_ID }} yarn dev diff --git a/.vscode/settings.json b/.vscode/settings.json index 06a367ecb..e44870599 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "cleandist", "fuzzysort", "kranvagn", + "outfile", "ownedtanks", "Resvg", "searchplayers", diff --git a/package.json b/package.json index b48311bd6..17f8732d3 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,8 @@ "type": "module", "scripts": { "dev": "yarn build && yarn start", - "start": "node --enable-source-maps dist/server.cjs", - "cleandist": "rm -rf dist", - "build:raw": "npx esbuild src/index.ts --outfile=dist/server.cjs --platform=node --bundle --sourcemap --loader:.node=copy --loader:.ttf=file", - "build:package": "cp package.dist.json dist/package.json", - "build": "yarn cleandist && yarn build:raw && yarn build:package", + "start": "node --enable-source-maps dist/index.cjs", + "build": "node scripts/build", "lint": "tsc" }, "license": "MIT", diff --git a/scripts/build.js b/scripts/build.js new file mode 100644 index 000000000..975ff801b --- /dev/null +++ b/scripts/build.js @@ -0,0 +1,23 @@ +import { build } from 'esbuild'; +import { rmSync } from 'fs'; + +console.log('Removing dist...'); +rmSync('dist', { recursive: true, force: true }); + +console.log('Creating context...'); +build({ + entryPoints: ['src/index.ts'], + outfile: 'dist/index.cjs', + + platform: 'node', + loader: { + '.node': 'copy', + '.ttf': 'file', + }, + + bundle: true, + sourcemap: true, + minifyIdentifiers: false, // causes errors + minifySyntax: true, + minifyWhitespace: true, +});