Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'end' emitted multiple times on overwriting files. #302

Closed
thomasmattheussen opened this issue Jun 18, 2013 · 11 comments
Closed

'end' emitted multiple times on overwriting files. #302

thomasmattheussen opened this issue Jun 18, 2013 · 11 comments

Comments

@thomasmattheussen
Copy link

I'm trying to create my own generator, but I guess I'm missing something.

this.on('end', function () {
    this.installDependencies({ skipInstall: options['skip-install'] });
  });

gets executed multiple times, and I can not for the live of me figure out why that is.

This message is printed several times during the generation:

"I'm all done. Running bower install & npm install for you to install the required dependencies. If this fails, try running the command yourself."

I've narrowed down one of the extraneous firing of 'end' to these lines:

this.directory('sass', 'sass');
this.template('sass/style.scss', 'sass/style.scss');

If i comment out one of those lines, it works. Doesn't seem to matter which one. Does this have anything to do with the fact that the style.scss file gets overwritten? Because it's already residing in the sass folder.

Anyone care to elaborate?

@thomasmattheussen
Copy link
Author

Okay, definitely has something to do with overwriting files. I had a duplicate copy command somewhere, which triggered one extra 'end' event somehow.

Is this expected behavior? @addyosmani, @mklabs, @sindresorhus ?

@addyosmani
Copy link
Member

installDependencies will basically handle npm / bower install of dependencies for you. For the generator you're working on, did you fork an existing generator or have you started from scratch? A little more context about what you've done so far would help us understand if this is a bug.

@thomasmattheussen
Copy link
Author

I have started from the generator-generator and rolled my own from there.

In the templates folder, I've added a folder named sass. In that folder resides a file named style.scss. See this gist: https://gist.github.com/thomasmattheussen/5805708

So, I copy everything from the sass directory (including the style.scss), and then I try to template that style.scss (which overwrites the style.scss file that already got copied through the directory method in the previous line)

That somehow seems to trigger another 'end' event, and thus fires the installDependencies multiple times.

Same behavior occurs when you try this:

this.copy('file','file');
this.copy('file','file');

Am I making sense here?

@jdespatis
Copy link
Contributor

@thomasmattheussen you should try yeoman git master branch and see if it solves your problem
or try with yeoman tag 0.11.1

@thomasmattheussen
Copy link
Author

Hmmm... No dice, same problem occurs on both master and v0.11.1

@jdespatis
Copy link
Contributor

So @thomasmattheussen , maybe you've put badly the cb() function.
You need to have a var cb = this.async() at the beginning of each Generator.prototype, and call cb() when full operation is finished, and only when it's finished

@thomasmattheussen
Copy link
Author

I've updated my gist: https://gist.github.com/thomasmattheussen/5805708 to show my full index.js

I could be wrong, but I don't see it.. :/

@sindresorhus
Copy link
Member

0.12.1 is the latest. Can you reproduce the issue with it?

@thomasmattheussen
Copy link
Author

Yep. Same problem.

To reproduce, create a new generator with yo generator and just duplicate on of the copy methods, for instance:

  this.copy('_bower.json', 'bower.json');
  this.copy('_bower.json', 'bower.json');

(To be clear on testing with different versions: I cd into /usr/local/lib/node_modules/yo/node_modules/ and then clone the yeoman-generator repo in there and then do git checkout v0.12.1 and a new npm install That is the correct way to test, right?)

@nategood
Copy link

Have the same issue with 1.0.0-beta.7. Had the following in my generator and was getting multiple "end" events emitted.

this.directory('.', '.');
this.template('package.json', 'package.json');

@SBoudrias
Copy link
Member

Fixed in #402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants