From d2cde92592b76808328442e784e8c7b2bc72e011 Mon Sep 17 00:00:00 2001 From: Arpon Date: Mon, 4 Nov 2024 01:34:14 +0600 Subject: [PATCH] node_runner added --- .github/workflows/release.yml | 6 ++++++ bundler.js | 4 ++-- node_runner.js | 38 +++++++++++++++++++++++++++++++++++ package.json | 2 +- vercel.json | 4 ++-- 5 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 node_runner.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a592dfa..f2e1190 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,6 +38,12 @@ jobs: mv dist server fi + - name: Move node_runner.js to server folder + run: | + if [ -f "node_runner.js" ]; then + mv node_runner.js server/node_runner.js + fi + - name: Remove Src run: rm -rf src diff --git a/bundler.js b/bundler.js index ee2c789..108e07b 100644 --- a/bundler.js +++ b/bundler.js @@ -1,11 +1,11 @@ Bun.build({ entrypoints: ["./src/app.ts"], outdir: "./dist", - target: "bun", + target: "node", splitting: true, sourcemap: "external", minify: true, - format: "esm", + format: "cjs", }) .finally(() => { console.log("✅ Bundler finished") diff --git a/node_runner.js b/node_runner.js new file mode 100644 index 0000000..eb035fd --- /dev/null +++ b/node_runner.js @@ -0,0 +1,38 @@ +const { exec } = require("node:child_process") +const path = require("node:path") + +// Function to execute shell commands +function executeCommand(command, callback) { + exec(command, (error, stdout, stderr) => { + if (error) { + console.error(`exec error: ${error}`) + callback(false, stderr) + return + } + console.log(stdout) + callback(true, stdout) + }) +} + +// Step 1: Install Bun +const installBunCommand = "curl -fsSL https://bun.sh/install | bash" +console.log("Installing Bun...") +executeCommand(installBunCommand, (success, result) => { + if (!success) { + console.error("Failed to install Bun:", result) + process.exit(1) // Exit the process with a non-zero exit code + } + console.log("Bun installation completed.") + + // Step 2: Run ~/.bun/bin/bun run start + // Assuming the default installation path + const runBunCommand = "~/.bun/bin/bun run start" + console.log("Running ~/.bun/bin/bun run start...") + executeCommand(runBunCommand, (success, result) => { + if (!success) { + console.error("Failed to run the command with Bun:", result) + process.exit(1) // Exit the process with a non-zero exit code + } + console.log("Successfully ran the command with Bun:", result) + }) +}) diff --git a/package.json b/package.json index 5e7dbe8..f02dd16 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "main": "dist/app.js", "scripts": { "start": "bun run ./dist/app.js", - "vercel:prod": "bun run ./server/app.js", + "vercel:prod": "bun run ./server/node_runner.js", "start:multi": "bun run ./multi-threaded-server.js", "build": "rm -rf dist && bun run ./bundler.js", "dev": "bun run --hot --no-clear-screen src/app.ts", diff --git a/vercel.json b/vercel.json index b9e0f46..cd3a96f 100644 --- a/vercel.json +++ b/vercel.json @@ -1,7 +1,7 @@ { "builds": [ { - "src": "server/app.js", + "src": "server/node_runner.js", "use": "@vercel/node", "config": { "includeFiles": ["server/**"] @@ -12,7 +12,7 @@ "routes": [ { "src": "/(.*)", - "dest": "server/app.js", + "dest": "server/node_runner.js", "methods": ["GET", "POST", "PATCH", "PUT", "DELETE", "OPTIONS"], "headers": { "Access-Control-Allow-Origin": "*"