syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
How to Quickstart grunt-shell?

The plugin, grunt-shell, is useful to developers who like using the Linux shell as an administrative UI for Node.js apps.

To quickstart grunt-shell in a lightweight app, I follow the list below:
  • Install Node.js. On Ubuntu I prefer this software:
    https://nodejs.org/dist/v0.12.7/node-v0.12.7-linux-x64.tar.gz
    More info:
    http://www.syntax.us/posts/nodejs_install
  • mkdir ~/myapp
  • cd ~/myapp
  • echo hello world > readme.txt
  • npm init
    (answer simple questions)
  • npm install -g grunt-cli
  • npm install grunt --save-dev
  • npm install grunt-shell --save-dev
  • vi Gruntfile.js
    demo:
    
    // ~/myapp/Gruntfile.js
    module.exports = function(grunt) {
      grunt.loadNpmTasks('grunt-shell');
      grunt.registerTask('default', ['shell']);
      grunt.initConfig({
        shell: {
          options: {
            stderr: false},
          target: {
            command: 'echo hello > /tmp/hello.txt'}}});}
    
    
  • I test Gruntfile.js by running 'grunt' shell command:
    dan@nia110 ~/myapp $ 
    dan@nia110 ~/myapp $ 
    dan@nia110 ~/myapp $ cat /tmp/hello.txt
    cat: /tmp/hello.txt: No such file or directory
    dan@nia110 ~/myapp $ 
    dan@nia110 ~/myapp $ 
    dan@nia110 ~/myapp $ ll
    total 28
    drwxrwxr-x  4 dan dan 4096 Aug 30 22:35 ./
    drwxr-xr-x 53 dan dan 4096 Aug 30 22:32 ../
    drwxrwxr-x  8 dan dan 4096 Aug 30 22:32 .git/
    -rw-rw-r--  1 dan dan  285 Aug 30 22:35 Gruntfile.js
    drwxrwxr-x  4 dan dan 4096 Aug 30 22:34 node_modules/
    -rw-rw-r--  1 dan dan  291 Aug 30 22:34 package.json
    -rw-rw-r--  1 dan dan   12 Aug 30 22:31 readme.txt
    dan@nia110 ~/myapp $ 
    dan@nia110 ~/myapp $ 
    dan@nia110 ~/myapp $ cat Gruntfile.js 
    
    // ~/myapp/Gruntfile.js
    module.exports = function(grunt) {
      grunt.loadNpmTasks('grunt-shell');
      grunt.registerTask('default', ['shell']);
      grunt.initConfig({
        shell: {
          options: {
            stderr: false},
          target: {
            command: 'echo hello > /tmp/hello.txt'}}});}
    dan@nia110 ~/myapp $ 
    dan@nia110 ~/myapp $ grunt
    Running "shell:target" (shell) task
    
    Done, without errors.
    dan@nia110 ~/myapp $ 
    dan@nia110 ~/myapp $ 
    dan@nia110 ~/myapp $ cat /tmp/hello.txt 
    hello
    dan@nia110 ~/myapp $ 
    dan@nia110 ~/myapp $ 
    dan@nia110 ~/myapp $ 
    

So, if grunt works, I consider grunt-shell to be both packaged with my new app and ready for action.


syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me