3

だから、私は以下のgruntファイルを持っています。ノードアプリを起動し、ディレクトリ内の変更を監視して再起動するタスクを追加したいと思います。私はスーパーバイザー、node-dev(これは素晴らしいです)を使用していますが、1つのコマンドを実行してアプリ全体を起動したいと思います。これを行う簡単な方法が必要ですが、私はそれを見逃しています。それはコーヒースクリプトでも書かれています(それが物事を変えるかどうかはわかりません)...

module.exports = function(grunt) {
  grunt.initConfig({
    /*exec: {
        startApi: {
            command: "npm run-script start-api"
        }
    },*/
    //static server
    server: {
        port: 3333,
        base: './public',
        keepalive: true
    },

    // Coffee to JS compilation
    coffee: {
        compile: {
            files: {
                './public/js/*.js': './src/client/app/**/*.coffee'
            },
            options: {
                //basePath: 'app/scripts'
            }
        }
    },


    mochaTest: {
        all: ['test/**/*.*']
    },


    watch: {
        coffee: {
            files: './src/client/app/**/*.coffee',
            tasks: 'coffee'
        },
        mochaTest: {
            files: 'test/**/*.*',
            tasks: 'mochaTest'
        }
    }
});

grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-mocha-test');
//grunt.loadNpmTasks('grunt-exec');

grunt.registerTask( 'default', 'server coffee mochaTest watch' );
};

コメントからわかるように、grunt-execを試しますが、nodeコマンドは他のタスクの実行を停止します。

4

1 に答える 1

8

ノードアプリを起動するときに、デフォルトのタスクと監視タスクを実行するようにgruntを設定できます。

app.jsで

var cp = require('child_process');
var grunt = cp.spawn('grunt', ['--force', 'default', 'watch'])

grunt.stdout.on('data', function(data) {
    // relay output to console
    console.log("%s", data)
});

その後node app、通常どおり実行します。

クレジット

于 2013-01-09T19:14:54.617 に答える