Execute shell script in gruntfile and assign result to variable

梦想的初衷 提交于 2019-12-05 04:26:29
Clandestine

Although I'm still unclear on why the method above is not working, and welcome any feedback, after a bit of research, I found shelljs, which I was able to use to solve my problem. Since shelljs can exec shell commands synchronously, I don't have to work with callbacks when I really want things to block:

module.exports = (grunt) ->
  shell = require 'shelljs'
  envvar = shell.exec('./bin/get_envvar.sh', {'silent':true}).output

  grunt.initConfig
    pkg: grunt.file.readJSON('package.json')

    env:
      dev:
        ENV_VAR: envvar

    simplemocha:
      options:
        timeout: 30000
        reporter: 'spec'
        compilers: 'coffee:coffee-script'
      all:
        src: ['Tests/**/*.coffee']

  grunt.registerTask 'test', ['env', 'simplemocha']

A lot cleaner, too!

References:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!