Skip to content

Commit

Permalink
node_runner added
Browse files Browse the repository at this point in the history
  • Loading branch information
a4arpon committed Nov 3, 2024
1 parent 9053248 commit d2cde92
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions bundler.js
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
38 changes: 38 additions & 0 deletions node_runner.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"builds": [
{
"src": "server/app.js",
"src": "server/node_runner.js",
"use": "@vercel/node",
"config": {
"includeFiles": ["server/**"]
Expand All @@ -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": "*"
Expand Down

0 comments on commit d2cde92

Please sign in to comment.