Sunday, June 12, 2016

Run Powershell script from Gulp.js

Installation Requirement

  1. If your Visual Studio is 2013 or order install Task Runner Explorer - Download and install- https://visualstudiogallery.msdn.microsoft.com/8e1b4368-4afb-467a-bc13-9650572db708
  2. Node.js- Recommended for most users-Check this download link-https://nodejs.org/en/
 
  • Run from the cmd command from this solution or class library location.
  • Ensure you keep the gulp.js in location where the actions /events are required.
  • Run command below from Class Library or website folder: Npm I gulp -g

Change Environment variable path

Gulp .js can be run from Task Runner VS2015

var gulp = require("gulp");
var childProcess = require('child_process');

gulp.task('deploy-static-files', function (callback) {
    console.log("---------Start--------------------------");
    return childProcess.exec('Powershell.exe  -executionpolicy remotesigned -File  DeployStaticFiles.ps1', function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);
        if (err) console.log(err);

        console.log("Finished");
    });
})

Powershell script :Deploy Static file code

####----Copy files from source to destination-----
$publishPathDestination      =   "Some Path"
$scriptpathSource            = Split-Path $MyInvocation.MyCommand.Path
Copy-Item  "$scriptpath"     $publishPathDestination   -Recurse -Force;


Post a Comment