Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions scripts/npm/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/usr/bin/env node

const path = require('path')
const fs = require('fs')
const childProcess = require('child_process')
const os = require('os')
import { fileURLToPath } from 'url'
import { dirname, join } from 'path'
import { existsSync } from 'fs'
import { spawn } from 'child_process'
import { platform as _platform, arch as _arch } from 'os'

/**
* Run the platform-specific executable with the given arguments
* @param {string[]} args Arguments to pass to the executable
* @returns {Promise<number>} Returns a Promise that resolves to the exit code
*/
function runExecutable(args = []) {
export async function runExecutable(args = []) {
try {
// Check for verbose flag
const verbose = args.includes('--verbose')
Expand All @@ -22,10 +23,10 @@ function runExecutable(args = []) {
}
}

const packageJson = require('./package.json')
const { default: packageJson } = await import('./package.json', { with: { type: 'json' } });

const platform = os.platform()
const arch = os.arch()
const platform = _platform()
const arch = _arch()

verboseLog(`Detected platform: ${platform}`)
verboseLog(`Detected architecture: ${arch}`)
Expand All @@ -42,10 +43,10 @@ function runExecutable(args = []) {
verboseLog(`Found executable in package.json: ${execName}`)

// The platform-specific executable should be in the same folder
const execPath = path.join(__dirname, execName)
const execPath = join(dirname(fileURLToPath(import.meta.url)), execName);
verboseLog(`Executable path: ${execPath}`)

if (!fs.existsSync(execPath)) {
if (!existsSync(execPath)) {
console.error(`Executable "${execPath}" not found.`)
return Promise.resolve(1)
}
Expand All @@ -55,7 +56,7 @@ function runExecutable(args = []) {
// Remove verbose flag before passing args to the child process
const childArgs = args.filter(arg => arg !== '--verbose')

const child = childProcess.spawn(execPath, childArgs, {
const child = spawn(execPath, childArgs, {
stdio: 'inherit',
shell: false
})
Expand All @@ -76,12 +77,5 @@ function runExecutable(args = []) {
}
}

// Check if this file is being run directly
if (require.main === module) {
// Run the executable with command line args and exit with its code
runExecutable(process.argv.slice(2))
.then(code => process.exit(code))
} else {
// Export the function for consumers to use
module.exports = { runExecutable }
}
runExecutable(process.argv.slice(2))
.then(code => process.exit(code))
7 changes: 4 additions & 3 deletions scripts/npm/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@digitalocean/mcp",
"version": "1.0.11",
"description": "DigitalOcean MCP Implementation,",
"version": "1.0.12",
"description": "DigitalOcean MCP Implementation",
"author": "DigitalOcean",
"homepage": "https://github.com/digitalocean-labs/mcp-digitalocean?tab=readme-ov-file#mcp-digitalocean-integration",
"license": "MIT",
Expand Down Expand Up @@ -41,5 +41,6 @@
"x64",
"arm64"
],
"optionalDependencies": {}
"optionalDependencies": {},
"type": "module"
}