Execute OS specific script in node / Grunt
gruntjs, node.js, operating-system, shell
Solution
You could take advantage of node's process.platform:
process.platform What platform you're running on: 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'
console.log('This platform is ' + process.platform);
Then within the code, optionally add the file extensions based on that:
if (process.platform === "win32") {
ext = ".cmd";
} else {
ext = ".sh";
}
Problem
I have a Grunt task which executes .cmd file on the local machine to do its thing. I need to use this task on the CI server, which is a Linux machine. I have the relevant .sh (shell script for Linux) for that. I need a way to execute these two without changing my Gruntfile. Currently I have to change my Gruntfile to make it work locally for windows and remote file uses .sh. Any solution to do same is welcome. Detecting underlying OS? Or a way to call same command which internally calls the OS specific command?