Skip to content

Commit

Permalink
change bin if windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Nov 13, 2024
1 parent 9d4d600 commit 2b154e3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
12 changes: 10 additions & 2 deletions bin/pm2
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions bin/pm2-windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../lib/binaries/CLI.js');
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 24 additions & 0 deletions preinstall.js
Original file line number Diff line number Diff line change
@@ -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}`);
});

0 comments on commit 2b154e3

Please sign in to comment.