Yeoman:如何按顺序安装依赖项

时间:2015-11-23 01:05:53

标签: generator yeoman

在我的生成器中,我希望按顺序运行npm ijspm i,以便日志输出不会混合在一起。我该怎么做?

目前,如果我把它们放在一起:

install: function() {
    this.npmInstall();
    this.spawnCommand('jspm', ['install']);
}

install: {
    npm: function() { this.npmInstall(); },
    jspm: function() { this.spawnCommand('jspm', ['install']); }
}

将同时运行。

我知道我可以jspm i放在end队列中,但是我想将它用于安装后代码并且它有同样的问题(即end队列中的所有代码都是并行运行的。

1 个答案:

答案 0 :(得分:0)

Yeoman只是Node.js和JavaScript。您将以与处理任何异步操作相同的方式处理此问题。

在Yeoman中,您使用this.async()来定义异步任务:

install: {
    npm: function() {
        this.npmInstall();
    },
    jspm: function() {
        this.spawnCommand('jspm', ['install']).on('close', this.async());
    }
}

请注意,您也可以使用this.spawnCommandSync