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?
Yeoman doesn't change directory for the user.
You might be able to do it manually by using process.chdir()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With