简体   繁体   中英

Yeoman generator after download call function

I'm trying to create a Yeoman generator. I need to know how is possibile to call a function after bowerInstall finished to download my package.

Here is my piece of code:

Generator.prototype.myFiles = function myFiles() {
    console.info('download');
    this.bowerInstall('my-package-name', { save: true });
};

Generator.prototype.moveFiles = function moveFiles() {
    console.info('move');
};

After download I need to move some files so I have to wait until all package is downloaded.

But function moveFiles is called immediately when the download start not when the download is finished.

Is there anyway to call moveFiles after download my package?

Thanks

First of all, you should read the documentation to understand how Yeoman generators works. For this question, you're asking about the task queue and the priorities: http://yeoman.io/authoring/running-context.html

Installation actions happens in the install . So to do anything after the installation complete, you need to add your tasks inside the end priority.

In your case, it'd look like:

Generator.prototype.install = function myFiles() {
    console.info('download');
    this.bowerInstall('my-package-name', { save: true });
};

Generator.prototype.end = function moveFiles() {
    console.info('move');
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM