Is there any way to run a PowerShell script in Sitecore using Gulp? We are trying to integrate some content publishing to the build process automatically. All our JS/CSS is stored in the Media Library which needs to be manually published each time there is a new build so we want to automate this task.
1 Answer
PowerShell is a great choice for dealing with Sitecore items. Assume that you already have your somescript.ps1
script ready and want to run it from a Gulp task while building & deploying your project files. The below script will help you to achieve this:
gulp.task('your-task', function (cb) {
var psScriptPath = "your-script-path";
exec('powershell.exe -file ' + psScriptPath + 'somescript.ps1', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
-
Thanks Kate, do you know how the script could publish files to the website? If I run the ps1 file from the CMS it works fine, but I want to be able to run a script during development so that when I modify a JS file and its uploaded to the media library for instance, then it will Smart publish the respective Theme folder so the changes will be made live automatically. Thanks in advance Commented Oct 18, 2022 at 11:24
-
Did you consider creating an item:saved event handler if you want to do something extra while updating your asset? Commented Oct 18, 2022 at 19:27