-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
Considering adding a "dry run" option #110
Comments
Hum, I think you'd need to modify the As you say, because we're using mem-fs, it should be relatively simple to skip the commit phase. If you're willing to give it a try, I'll be happy to help review the PR and make sure we can move this forward. |
Ok, I'll give it a try. I am not exactly a guru in node.js development, so I'll take my time ;o) |
@daaren-urthling you can ping me on our gitter channel; and maybe some other people can also jump in to give you a hand. |
Perfect! Let's do this way, thanks a lot. |
Hey did you try this? I need this feature in my application. I would like to give it a try if I get a bit help. :) |
No, I didn't progress with this project, I had other priorities |
I was also after this because it's a little faster than writing tests while prototyping generators. I ended up creating a "BaseGenerator" to extend that overrides In the constructor I added this: // Hi-jack fs module to add dry run and verbose support.
this.fs = new Proxy(this.fs, {
get: (target, propKey) => {
if (typeof target[propKey] !== 'function' || propKey.startsWith('exists') || propKey.startsWith('read')) {
return target[propKey];
}
// eslint-disable-next-line consistent-return
return (...fnArgs) => {
if (this._dryRun) {
this.log(this._verbose
? `${propKey} ${JSON.stringify(fnArgs, null, 2)}`
: `${propKey}(${fnArgs.join('", "')})`);
} else if (this._verbose) {
this.log(`${propKey}(${fnArgs.join('", "')})`);
}
if (!this._dryRun) {
return target[propKey](...fnArgs);
}
};
},
}); And replacing // Override to implement dry-run and verbose modes.
spawnCommand(command, args) {
if (this._dryRun) {
this.log(this._verbose
? `${command} ${JSON.stringify(args, null, 2)}`
: `${command}(${args.join('", "')})`);
} else if (this._verbose) {
this.log(`${command}(${args.join('", "')})`);
}
if (!this._dryRun) {
const { error } = super.spawnCommandSync(command, args);
if (error) throw error;
}
} Please forgive the dirty logging, etc. Hope this helps someone 🙂 |
It would be useful to have an option that allow to do almost everything but not committing the FS in the end (similar to --dry-run for Angular CLI).
This may allow to review the list of files added, changed and the eventual conflicts.
As far as the MemFS is used, it should be relative simple to skip the last "commit" phase.
Maybe this is already possible by tweaking in some way the generator ...
The text was updated successfully, but these errors were encountered: