LoginSignup
19
19

More than 5 years have passed since last update.

Gruntで任意のシェルコマンドを登録する

Last updated at Posted at 2013-03-01

Gruntfile.coffeeで任意のシェルのタスクを登録するサンプル


# in gruntfile.coffee

{exec} = require('child_process')
runCommand = (exp, done) ->
  exec exp, (error, stdout, stderr) ->
    return done(true) if error or stderr
    done(false,stdout)

grunt.registerMultiTask 'test', 'test command', ->
  conf = @
  done = conf.async()
  runCommand 'ls -l', (error, ret) =>
    if error
      grunt.log.writeln('error')
      return done(false)
    grunt.log.writeln('done);
    done(true)

同様のことをする grunt-execというのがすでにあります
jharding/grunt-exec · GitHub https://github.com/jharding/grunt-exec

ただ、このイディオムを覚えておくと任意のJSオブジェクトをインポートしたり、fsで制御したりできるので便利です

19
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
19