0

I am new to gruntJS. Looking at the tutorials/presentations, I believe it is awesome. Currently, we are using batch scripts in our web + embedded project, which performs the following tasks:

  1. Merges all the JS file into one.
  2. Merges all the CSS file into one.
  3. Kills existing .EXE on which our project runs. It's basically a simulator's EXE which loads and runs our website. Our website is packaged in the form of ZIP file.
  4. Deletes existing ZIP file.
  5. Creates a new ZIP file which will contain some folders like "html", "lsp" (Lua Server Pages), images, JS(which will contain only one merged file), CSS(which will contain only one CSS file).
  6. Start the .EXE. Basically the EXE once loaded which pick up the zip file from a specified directory.

I understand, merging process can be achieved via gruntJS, but I am not sure about starting/killing the EXE. It would be great if somebody gives me pointers how to get started. Once being certain about the process, I can convince my boss.

Thanks for reading.

Anup Vasudeva
  • 871
  • 2
  • 12
  • 31
  • 1
    almost duplicate: http://stackoverflow.com/questions/10456865/running-a-command-in-a-grunt-task – olly_uk Dec 16 '13 at 13:53

1 Answers1

2

Having a grunt-like script that launch your server isn't good practice. In an ideal world, you would separate the build and package phase from the launch of the server.

But anyway, there are either grunt plugins to do that, or the vanilla child_process of node, assuming you use node to run grunt.

Using grunt-exec it would look like this:

exec: {
  start_server: {
    command: 'program.exe'
  }
}

Using the vanilla approach:

var spawn = require('child_process').spawn;
prog = spawn('program.exe');

prog.on('close', function (returnCode) {
  console.log('program.exe terminated with code', returnCode);
});
toasted_flakes
  • 2,502
  • 1
  • 23
  • 38
  • Is it possible via grunt to merge all the scripts file into a zip file? – Anup Vasudeva Dec 24 '13 at 12:45
  • 1
    @AnupVasudeva Yes. Quick googling, I found [`grunt-compress`](https://github.com/gruntjs/grunt-contrib-compress) which seems pretty cool (it supports various other formats), and there's also [`grunt-zip`](https://github.com/twolfson/grunt-zip). – toasted_flakes Dec 24 '13 at 13:07