gulp:如何按顺序执行node.js任务

时间:2016-09-26 06:57:00

标签: gulp gulp-watch

我有几个gulp子任务,可以监控文件更新。我需要它们按顺序启动。

gulp.task('production', ['update-build-info/production:live', 'build-resources/production:live', 'npm-start', 'simulator'], () => {
  console.log('finished!!!');
});

我的问题是:

  1. 我使用gulp-watch来跟踪实时更新的文件。这将导致顺序启动失败,因为这些子任务将在完成启动之前返回并变为空闲。
  2. 我如何安排这样的子任务:

    [start main task]-->[1. update-build-info]
                              |
                        start watching files
                              |
                        update matched files
                              |
                        idle (keep watching)-->[2. build-resources]
                              |                     |
                        update new changes     start watching files
                                                    |
                                               update matched files
                                                    |
                                               idle (keep watching)-->[3. run npm start]
                                                    |                     |                                                            
                                               update new changes     finish launching, idle --> [4. build and launch iOS app]
                                                                          |
                                                                      update new changes
    
    1. 执行shell脚本npm start将导致子任务永不结束,并导致永远不会调用回调(print finished!!!)。如果我删除此子任务,将再次调用回调。如何让子任务发送completed信号以触发回调?
    2. npm startbabel-node node_modules/react-native/local-cli/cli.js start

      编辑:

      我已经证明了为什么这个主题"How to run Gulp tasks sequentially one after the other"对我不起作用。我使用gulp-watch会导致异步任务,我不知道在初始工作完成后如何同步它们。

      使用node.js的另一种观察机制是npm start,它将阻止任务并永不结束。

      如果无法解决此问题,我想我需要使用RxJS来完成这项工作。

0 个答案:

没有答案
相关问题