diff --git a/bin/pm2 b/bin/pm2 index 08899d3cb..f96b85256 100755 --- a/bin/pm2 +++ b/bin/pm2 @@ -1,3 +1,11 @@ -#!/usr/bin/env node +#!/bin/sh -require('../lib/binaries/CLI.js'); +SCRIPT_PATH="$(dirname "$0")/../lib/binaries/CLI.js" + +# Check if 'bun' is available, otherwise use 'node' +if command -v bun >/dev/null 2>&1 +then + bun "$SCRIPT_PATH" "$@" +else + node "$SCRIPT_PATH" "$@" +fi diff --git a/bin/pm2-windows b/bin/pm2-windows new file mode 100644 index 000000000..08899d3cb --- /dev/null +++ b/bin/pm2-windows @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +require('../lib/binaries/CLI.js'); diff --git a/bun.lockb b/bun.lockb index 7cf9d895b..a5844f708 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 742a4bc3b..ca006783f 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,8 @@ "scripts": { "test:unit": "bash test/unit.sh", "test:e2e": "bash test/e2e.sh", - "test": "bash test/unit.sh && bash test/e2e.sh" + "test": "bash test/unit.sh && bash test/e2e.sh", + "preinstall": "node ./preinstall.js" }, "keywords": [ "cli", diff --git a/preinstall.js b/preinstall.js new file mode 100644 index 000000000..e466aa0fa --- /dev/null +++ b/preinstall.js @@ -0,0 +1,24 @@ +const fs = require('fs'); +const path = require('path'); + +// Determine platform +const isWindows = process.platform === 'win32'; + +if (!isWindows) + process.exit(0) + +const sourceFile = 'bin/pm2-windows'; +const destinationFile = 'bin/pm2'; + +// Resolve file paths +const sourcePath = path.resolve(__dirname, sourceFile); +const destinationPath = path.resolve(__dirname, destinationFile); + +// Copy the appropriate file based on the platform +fs.copyFile(sourcePath, destinationPath, (err) => { + if (err) { + console.error(`Error copying file from ${sourcePath} to ${destinationPath}:`, err); + process.exit(1); + } + console.log(`Successfully copied ${sourceFile} to ${destinationFile}`); +});