diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 5b4905f..adba4f2 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - node-version: [10.x, 12.x, 14.x] + node-version: [20.x] steps: - uses: actions/checkout@v2 @@ -18,5 +18,9 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: npm ci - - run: npm run build --if-present - - run: npm test + - name: pester + run: | + Set-PSRepository psgallery -InstallationPolicy trusted + Install-Module -Name Pester -RequiredVersion 5.5.0 -Confirm:$false -Force + Invoke-Pester + shell: pwsh diff --git a/Gulp/Gulp.tests.ps1 b/Gulp/Gulp.tests.ps1 index 3e72aee..bce74f4 100644 --- a/Gulp/Gulp.tests.ps1 +++ b/Gulp/Gulp.tests.ps1 @@ -95,12 +95,13 @@ Describe "Publish-Tasks 'name'" { } $result = Publish-Tasks 'name' } - It "result should be like ""*\Gulp""" { - ($result | ConvertFrom-Json).Message | Should -BeLike "*\Gulp" + It "result should be like ""*\Gulp"" or ""*/Gulp""" { + ($result | ConvertFrom-Json).Message | Should -Match "[*\\/]*Gulp" } } Context "'name' writes 'fail' error" { BeforeEach { + $ErrorActionPreference = 'Continue' Add-Task "name" @() { Write-Error 'fail' } @@ -111,7 +112,7 @@ Describe "Publish-Tasks 'name'" { ) > $null) 3>&1 } It "result should be 'fail'" { - $result | Should -Match """fail""" + ($result | ConvertFrom-Json).Message | Should -Be "fail" } It "error stream should be null" { $errors | Should -Be $null diff --git a/index.js b/index.js index a397c42..b6f8928 100644 --- a/index.js +++ b/index.js @@ -12,18 +12,23 @@ const switches = [ '-NoLogo', '-NonInteractive', '-File' -]; +]; module.exports = function (gulp, file, options = { runOnWindowsPowershell: false }) { - log('Importing Tasks', colors.magenta(file)); - const powershellCommand = !options.runOnWindowsPowershell && commandExists('pwsh') ? 'pwsh' : 'powershell'; + const powershellCommand = !options.runOnWindowsPowershell ? 'pwsh' : 'powershell'; + + if (!commandExists(powershellCommand)) { + console.error(`Command ${powershellCommand} not found. Please make sure it is installed and accessible through the PATH envvar.`); + process.exit(1); + } const result = run(powershellCommand, switches.concat(file)); + const debugOrVerbose = (args.debug || args.verbose); - if (result.stderr.length > 0) - log.error(result.stderr.toString()); + if (result.error || result.stderr && result.stderr.length > 0) + log.error(result.error || result.stderr.toString()); else { const tasks = JSON.parse(result.stdout); Object.keys(tasks).forEach(function (key) { @@ -31,7 +36,6 @@ module.exports = function (gulp, file, options = { runOnWindowsPowershell: false const execSwitches = switches.concat(file, key, process.argv); const taskProcess = spawn(powershellCommand, execSwitches, { stdio: ['inherit', 'pipe', 'inherit'] }); const taskLabel = colors.cyan(key); - const debugOrVerbose = (args.debug || args.verbose); taskProcess.stdout.on('data', data => { data @@ -39,28 +43,7 @@ module.exports = function (gulp, file, options = { runOnWindowsPowershell: false .split(/\r?\n/) .filter(l => l !== '') .map(lineAsJson) - .forEach(l => { - switch (l.level) - { - case 'debug': - debugOrVerbose && log.info(taskLabel, l.message); - break; - case 'verbose': - args.verbose && log.info(taskLabel, l.message); - break; - case 'information': - log.info(taskLabel, l.message); - break; - case 'warning': - log.warn(taskLabel, l.message); - break; - case 'error': - log.error(taskLabel, l.message); - break; - default: - log(taskLabel, l.message); - } - }); + .forEach(l => logForLevel(l, taskLabel, debugOrVerbose)); }); return taskProcess; @@ -82,3 +65,27 @@ function lineAsJson(line) { }; } } + +function logForLevel(l, taskLabel, debugOrVerbose) { + switch (l.level) + { + case 'debug': + debugOrVerbose && log.info(taskLabel, l.message); + break; + case 'verbose': + args.verbose && log.info(taskLabel, l.message); + break; + case 'information': + log.info(taskLabel, l.message); + break; + case 'warning': + // this should use log.warn(), but for some reason when called via gulp and level is warning, stderr seems to be suppressed + log.info(taskLabel, l.message); + break; + case 'error': + log.error(taskLabel, l.message); + break; + default: + log(taskLabel, l.message); + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d89d6fa..1fd8c1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "posh-gulp", - "version": "3.1.0", + "version": "3.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "posh-gulp", - "version": "3.1.0", + "version": "3.1.1", "license": "ISC", "dependencies": { "ansi-colors": "^4.1.3", diff --git a/package.json b/package.json index 3488b45..c5534c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "posh-gulp", - "version": "3.1.0", + "version": "3.1.1", "description": "write gulp tasks in powershell", "keywords": [ "powershell",