UNPKG

postman-cli

Version:

Official Postman CLI - Command-line companion for API development, testing, and automation

38 lines (31 loc) 1.05 kB
const { execFileSync } = require('child_process'), PLATFORM_PACKAGES = { 'darwin-arm64': 'pm-bin-macos-arm64', 'darwin-x64': 'pm-bin-macos-x64', 'win32-x64': 'pm-bin-windows-x64', 'linux-x64': 'pm-bin-linux-x64' }; function locateBinary () { const platformKey = `${process.platform}-${process.arch}`, packageName = PLATFORM_PACKAGES[platformKey]; if (!packageName) { throw new Error(`Unsupported platform: ${platformKey}`); } // eslint-disable-next-line one-var const binaryName = process.platform === 'win32' ? 'postman.exe' : 'postman'; try { return require.resolve(`@postman/${packageName}/bin/${binaryName}`); } catch (error) { throw new Error( `Binary not found for ${platformKey}. ` + `Make sure @postman/${packageName} is installed. ` ); } } module.exports = function run (...args) { return execFileSync(locateBinary(), args, { stdio: 'inherit', encoding: 'utf8' }); };