2016-03-24 32 views
3

私はgulpを使ってアプリケーションをビルドして配備しています。gulpからPowerShellスクリプトを実行する方法を教えてください。

var msbuild = require('gulp-msbuild'); 
gulp.task('build', ['clean'], function() { 
return gulp.src('../../*.sln') 
    .pipe(msbuild({ 
     toolsVersion: 14.0, 
     targets: ['Rebuild'], 
     errorOnFail: true, 
     properties: { 
      DeployOnBuild: true, 
      DeployTarget: 'Package', 
      PublishProfile: 'Development' 
     }, 
     maxBuffer: 2048 * 1024, 
     stderr: true, 
     stdout: true, 
     fileLoggerParameters: 'LogFile=Build.log;Append;Verbosity=detailed', 
    })); 
}); 

は、しかし、ビルドした後、私は一口でそれを呼び出すことができますどのように、「publish.ps1」PowerShellスクリプトファイルを呼び出す必要がありますか?

+0

を削除する

gulp.task('powershell', function (callback) { exec("Powershell.exe -executionpolicy remotesigned . .\\file.ps1; Write-Stuff -arg1 'My first param' -arg2 'second one here'" , function(err, stdout, stderr){ console.log(stdout); callback(err) }); }); 

更新file.ps1を。可能な複製:http://stackoverflow.com/a/10181488/197472 – Barryman9000

+0

@ Barryman9000、ビルドタスクの後にコードを追加できますか? –

+0

powershell/nodeコード – Barryman9000

答えて

9

私はこれをテストしていませんが、2つを組み合わせると、このようになります。実行順序を使用して依存関係の順序を管理するデフォルトタスクを実行するだけです。

var gulp = require('gulp'), 
     runSequence = require('run-sequence'), 
     msbuild = require('gulp-msbuild'), 
     spawn = require("child_process").spawn, 
     child; 

    gulp.task('default', function(){ 
     runSequence('clean', 'build', 'powershell'); 
    }); 

    gulp.task('build', ['clean'], function() { 
     return gulp.src('../../*.sln') 
      .pipe(msbuild({ 
       toolsVersion: 14.0, 
       targets: ['Rebuild'], 
       errorOnFail: true, 
       properties: { 
        DeployOnBuild: true, 
        DeployTarget: 'Package', 
        PublishProfile: 'Development' 
       }, 
       maxBuffer: 2048 * 1024, 
       stderr: true, 
       stdout: true, 
       fileLoggerParameters: 'LogFile=Build.log;Append;Verbosity=detailed', 
      })); 
    }); 

    gulp.task('powershell', function(callback){ 
     child = spawn("powershell.exe",["c:\\temp\\helloworld.ps1"]); 
     child.stdout.on("data",function(data){ 
      console.log("Powershell Data: " + data); 
     }); 
     child.stderr.on("data",function(data){ 
      console.log("Powershell Errors: " + data); 
     }); 
     child.on("exit",function(){ 
      console.log("Powershell Script finished"); 
     }); 
     child.stdin.end(); //end input 
     callback(); 
    }); 

EDIT

コールパラメータでPowerShellのファイル

var exec = require('child_process').exec; 

gulp.task('powershell', function (callback) { 
    exec('Powershell.exe -executionpolicy remotesigned -File file.ps1', function(err, stdout, stderr){ 
    console.log(stdout); 
    callback(err) 
}); 

})。あなたのソリューション

Write-Host 'hello'

EDIT 2

OK、もう一つの試みのルートで

のPowershell file.ps1。あなたはparams/argumentsをfile.ps1に入れることができますか?

function Write-Stuff($arg1, $arg2){ 
    Write-Output $arg1; 
    Write-Output $arg2; 
} 
Write-Stuff -arg1 "hello" -arg2 "See Ya" 

EDIT 3

は一気タスクからのparamsを渡す::あなただけのノードを使用することができます

function Write-Stuff([string]$arg1, [string]$arg2){ 
    Write-Output $arg1; 
    Write-Output $arg2; 
} 
+0

私のPowerShellスクリプトには引数としていくつかのパラメータが必要です。どのようにそれに対処するか分からない。 –

+0

これらのパラメータをタスクに追加することができます。 – Barryman9000

+0

は、私は、このような '機能パブリッシュ・AspNetDocker { [cmdletbinding(SupportsShouldProcess = $真)] のparamを( [パラメータ(必須= $ trueの場合、位置= 0)] [ALLOWNULL()] $などの引数を意味し、私の編集を参照してください。 publishProperties、 [パラメータ(必須= $ trueの場合、位置= 1)] $ packOutput、 [パラメータ(必須= $ falseの場合、ポジション= 2)]で私の弱さのために申し訳ありませんが、素晴らしいです $ pubxmlFile ) ' –

関連する問題