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

#inDir() should also accept a source path to preload a testing dir with contents #573

Closed
blai opened this issue May 30, 2014 · 8 comments
Closed

Comments

@blai
Copy link
Contributor

blai commented May 30, 2014

This will help testing scenarios of running a generator in a folder with existing project contents.

var temp = path.join(__dirname, 'temp');
var contentToBeUpdated = path.join(__dirname, 'fixtures', 'update-app');

helpers.run('../../generator-foo/app')
  .inDir(temp, contentToBeUpdated)
...
@eddiemonge
Copy link
Member

Im running into this problem as well but I think the second param should be a boolean which should mean: if true, don't delete the contents of the temp directory otherwise do.

@SBoudrias
Copy link
Member

Or maybe just giving control via a callback once the dir is cleaned? In this callback you manually copy or generates files or whatever really.

@eddiemonge
Copy link
Member

callback is better.

@blai
Copy link
Contributor Author

blai commented Jun 2, 2014

I'd prefer both callback and a function to automate it, and giving it a second thought, maybe the following is better?

helpers.run('../../generator-foo/app')
  .inDir(path.join(__dirname, 'temp'))
  .withContents(path.join(__dirname, 'fixtures', 'some-content-to-update'))
  .withContents(path.join(__dirname, 'fixtures', 'some-other-content'), path.join(__dirname, 'fixtures', 'some-more-content'))
...

@eddiemonge
Copy link
Member

I think the callback syntax is enough:

helpers.run('../../generator-foo/app')
  .inDir(path.join(__dirname, 'temp'), function (dir) {
    console.log(dir); // resolved directory
  });

You could just a npm module to move files and call it in the callback

@SBoudrias
Copy link
Member

@eddiemonge ++ I like that syntax and it is way more flexible than having too many predefined behavior.

We'd just need to handle async action too. this.async might make sense.

@blai
Copy link
Contributor Author

blai commented Jun 3, 2014

@eddiemonge cool, this is indeed clean and flexible, and I can take care of it after I clean up #570. On a side thought, do we want to handle the case when the callback is doing something async?

Without async, the change could be as simple as:

RunContext.prototype.inDir = function (dirPath, cb) {
  var release = this._holdExec();
  helpers.testDirectory(dirPath, _.compose(cb || _.noop, release));
  return this;
};

As you see, calling release will release the generator. But if my callback needs to handle an async task (most file operations are async), I really don't want to release it until I am done creating the contents in the temp folder.

Thoughts? @SBoudrias

blai pushed a commit to blai/yeoman.io that referenced this issue Jun 4, 2014
blai pushed a commit to blai/generator that referenced this issue Jun 4, 2014
… a chance to alter

the environment to the a specific way and expect `env` and `generator` reflects such
settings.

- Emits `ready` event right before calling `generator.run()` to allow any
last minute operation on the `generator`

- Deprecating `onEnd`, instead emits 'end' event as `generator.on('end')`

- Implement `withGenerator()` to mock generator dependencies

- accepts optional second parameter in `inDir` as a callback function.

fixes yeoman#564, yeoman#565, yeoman#573
@blai blai mentioned this issue Jun 4, 2014
7 tasks
blai pushed a commit to blai/generator that referenced this issue Jun 4, 2014
… a chance to alter

the environment to the a specific way and expect `env` and `generator` reflects such
settings.

- Emits `ready` event right before calling `generator.run()` to allow any
last minute operation on the `generator`

- Deprecating `onEnd`, instead emits 'end' event as `generator.on('end')`

- Implement `withGenerator()` to mock generator dependencies

- accepts optional second parameter in `inDir` as a callback function.

fixes yeoman#564, yeoman#565, yeoman#573
blai pushed a commit to blai/generator that referenced this issue Jun 4, 2014
… a chance to alter

the environment to the a specific way and expect `env` and `generator` reflects such
settings.

- Emits `ready` event right before calling `generator.run()` to allow any
last minute operation on the `generator`

- Deprecating `onEnd`, instead emits 'end' event as `generator.on('end')`

- Implement `withGenerator()` to mock generator dependencies

- accepts optional second parameter in `inDir` as a callback function.

fixes yeoman#564, yeoman#565, yeoman#573
@SBoudrias
Copy link
Member

Done!

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

3 participants