From bf222031fbc440473483c0bf3bf90497a2b1196f Mon Sep 17 00:00:00 2001 From: Marvin Mieth Date: Sun, 28 May 2017 07:01:27 +0200 Subject: [PATCH 1/2] fix subcommand in windows --- lib/utils.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index a10c26f..eb998e9 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,6 +1,7 @@ 'use strict'; const spawn = require('child_process').spawn; +const path = require('path'); const pkginfo = require('pkginfo'); const camelcase = require('camelcase'); const stringSimilarity = require('string-similarity'); @@ -275,10 +276,10 @@ module.exports = { } // Generate full name of binary - const full = - this.binary + - '-' + - (Array.isArray(details.usage) ? details.usage[0] : details.usage); + const subCommand = Array.isArray(details.usage) + ? details.usage[0] + : details.usage; + let full = this.binary + '-' + subCommand; const args = process.argv; let i = 0; @@ -288,10 +289,22 @@ module.exports = { i++; } - // Run binary of sub command - this.child = spawn(full, args, { - stdio: 'inherit' - }); + if (process.platform === 'win32') { + const binaryExt = path.extname(this.binary); + if (path.extname(this.binary)) { + full = `${this.binary.replace(binaryExt, '')}-${subCommand}${binaryExt}`; + } + // Run binary of sub command on windows + args.unshift(full); + this.child = spawn(process.execPath, args, { + stdio: 'inherit' + }); + } else { + // Run binary of sub command + this.child = spawn(full, args, { + stdio: 'inherit' + }); + } // Throw an error if something fails within that binary this.child.on('error', err => { From 0a813fc1dec6e88480e46d002c52d866cc1b8d18 Mon Sep 17 00:00:00 2001 From: ntwcklng Date: Fri, 6 Oct 2017 11:19:42 +0200 Subject: [PATCH 2/2] fix subcommand when running in another dir --- lib/utils.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index d9b5414..6e0bc6c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -217,9 +217,10 @@ module.exports = { initial = items[item].init; } - usage += initial && isVersion === -1 - ? ' ' + this.handleType(initial)[0] - : ''; + usage += + initial && isVersion === -1 + ? ' ' + this.handleType(initial)[0] + : ''; } } @@ -245,7 +246,9 @@ module.exports = { // Add some space around it as well if (typeof defaultValue !== 'undefined') { if (typeof defaultValue === 'boolean') { - description += ` (${defaultValue ? 'enabled' : 'disabled'} by default)`; + description += ` (${defaultValue + ? 'enabled' + : 'disabled'} by default)`; } else { description += ` (defaults to ${JSON.stringify(defaultValue)})`; } @@ -291,8 +294,12 @@ module.exports = { if (process.platform === 'win32') { const binaryExt = path.extname(this.binary); + const mainModule = process.mainModule.filename; + + full = `${mainModule}-${subCommand}`; + if (path.extname(this.binary)) { - full = `${this.binary.replace(binaryExt, '')}-${subCommand}${binaryExt}`; + full = `${mainModule.replace(binaryExt, '')}-${subCommand}${binaryExt}`; } // Run binary of sub command on windows args.unshift(full);