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

Yeoman: How to install dependencies sequentially

在我的生成器中,我想按顺序 运行 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 队列,但我想将它用于 post-安装代码,它有同样的问题(即 end 队列中的所有代码都是 运行 并行)。

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

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

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

注意你也可以使用this.spawnCommandSync