あいつの日誌β

働きながら旅しています。

うっかり C 言語の入門をしたくなったときの Gruntfile

こうして

% npm init

こうして

% npm install --dev-save grunt-contrib-watch

こうして

% cat Gruntfile.coffee
module.exports = (grunt) ->

  grunt.initConfig
    watch:
      files: 'test.c'
      tasks: ['compile']

  grunt.loadNpmTasks 'grunt-contrib-watch'

  grunt.registerTask 'compile', 'my local task.', ()->
    exec = require('child_process').exec
    done = this.async()
    command = 'gcc -Wall test.c -o test.o && ./test.o'
    options = { timeout: 1000 }
    callback = (err, stdout, stderr)->
      console.error err if err
      console.log stdout
      do done
  
    exec(command, options, callback)

  grunt.registerTask 'default', ['compile', 'watch']

こうする

% grunt

きっと IDE 使ったほうがいいんだろうね。