Search code examples
javascriptnode.jsyeomanyeoman-generator

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


Solution

  • 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');
    };