Skip to content

Commit

Permalink
Merge pull request #28 from douglaseccker/task/usePowershellCore
Browse files Browse the repository at this point in the history
use powershell core when available
  • Loading branch information
trevorpower authored Dec 7, 2023
2 parents 0caf772 + 9b4a814 commit e2c8654
Show file tree
Hide file tree
Showing 3 changed files with 1,935 additions and 1,265 deletions.
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ const spawn = require('child_process').spawn;
const colors = require('ansi-colors');
const log = require('fancy-log');
const args = require('yargs').argv;
const commandExists = require('command-exists').sync;

const switches = [
'-NoProfile',
'-NoLogo',
'-NonInteractive',
'-File'
];
];

module.exports = function (gulp, file) {
module.exports = function (gulp, file, options = { runOnWindowsPowershell: false }) {

log('Importing Tasks', colors.magenta(file));

const result = run('powershell', switches.concat(file));
const powershellCommand = !options.runOnWindowsPowershell && commandExists('pwsh') ? 'pwsh' : 'powershell';

const result = run(powershellCommand, switches.concat(file));

if (result.stderr.length > 0)
log.error(result.stderr.toString());
Expand All @@ -26,7 +29,7 @@ module.exports = function (gulp, file) {
Object.keys(tasks).forEach(function (key) {
const task = () => {
const execSwitches = switches.concat(file, key, process.argv);
const taskProcess = spawn('powershell', execSwitches, { stdio: ['inherit', 'pipe', 'inherit'] });
const taskProcess = spawn(powershellCommand, execSwitches, { stdio: ['inherit', 'pipe', 'inherit'] });
const taskLabel = colors.cyan(key);
const debugOrVerbose = (args.debug || args.verbose);

Expand Down Expand Up @@ -78,4 +81,4 @@ function lineAsJson(line) {
message: line
};
}
}
}
Loading

0 comments on commit e2c8654

Please sign in to comment.