Reputation: 19803
I want to scaffold a project into same named directory and after generator finished with its job i want consumer to be redirected to that folder.
So I'm accepting project name as an argument: this.argument('name', { type: String, required: false });
and then create that folder and change destinationRoot
to it:
if (this.name) {
mkdirp(this.name);
this.destinationRoot(this.destinationPath(this.name));
}
After all I want to make kinda cd this.name
at the end stage of runContext cycle. I tried to change destinationRoot
to parent directory and then cd
to to it, and it supposed to work, but it doesn't:
end: function () {
if (this.name) {
console.log('BEFORE', ls('.'))
this.destinationRoot('..');
console.log('AFTER', ls('.'))
cd(this.name);
}
},
Here is log:
BEFORE [ 'README.md', 'index.js', 'package.json', 'test.js' ]
AFTER [ 'meow' ]
But It doesn't work because once yeoman finish it's job I’m still in the currrent folder and not in the meow
folder. Does anybody know how to fix that?
Upvotes: 3
Views: 989
Reputation: 44669
Yeoman doesn't change directory for the user.
You might be able to do it manually by using process.chdir()
Upvotes: 3