Я не проверял это, но если вы объедините два, это будет выглядеть примерно так. просто запустите задачу по умолчанию, которая использует последовательность выполнения для управления порядком зависимостей.
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)
});
});
Powershell file.ps1 в корень вашего решения
Write-Host 'hello'
EDIT 2
ОК, еще одна попытка. Можете ли вы поместить параметры/аргументы в file.ps1?
function Write-Stuff($arg1, $arg2){
Write-Output $arg1;
Write-Output $arg2;
}
Write-Stuff -arg1 "hello" -arg2 "See Ya"
EDIT 3
Проходят Params от задачи глотком ::
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)
});
});
Update file.ps1 удалить
function Write-Stuff([string]$arg1, [string]$arg2){
Write-Output $arg1;
Write-Output $arg2;
}
Вы можете просто использовать узел. Возможный дубликат: http://stackoverflow.com/a/10181488/197472 – Barryman9000
@ Barryman9000, могу ли я добавить код после моей задачи сборки? –
вы можете запустить еще одну задачу после 'build', которая запускает код powershell/node – Barryman9000