plopjs / plop

Consistency Made Simple
http://plopjs.com
MIT License
7.14k stars 278 forks source link

Why not extend existing fs-promise lib? #44

Closed kristianmandrup closed 8 years ago

kristianmandrup commented 8 years ago

Notice you have written your own helper library fs-promise but such a lib already exists. Why not extend the existing one!?

amwmedia commented 8 years ago

Well, when I originally wrote this I didn't see much use in extending an existing library because I wasn't sure how generic my implementations would end up being. Also most of what I needed was easily achieved just using the q.denodeify function so I preferred using what was already available (because I was already using q heavily), rather than adding another dependency. I actually just re-factored this code in node-plop (which will soon be powering plop directly. The result is 26 lines of code and I'm not sure it warrants a PR to any other repo or using another dependency. Is there a benefit that you can see to using something like fs-promise vs this approach?

kristianmandrup commented 8 years ago

Is fs.exist still valid? I thought it was deprecated and we had to use fs.stat instead. Besides that you could refactor your code to half that size if you really wanted since you are repeating the same pattern... on another note, fs-promise denodifies all the same + some extras from fs-extra? Take a look...

kristianmandrup commented 8 years ago

On yet another note, I'd like to see a json-operator module, for delete, set, merge on paths in json structures, sinilar to your regex string replace for text files. Then ideally also an AST equivalent... :) Looking forward to more improvements! I really like this lib over Yeoman and Slush!

kristianmandrup commented 8 years ago

I plan to work on such a json-operator later this week... Would be nice in combination with node-jq. I created master-inquisitor today, inquirer all in one... Check out inquirer-test and mock-fs for testing generators ;)

kristianmandrup commented 8 years ago

The regex json "equivalent" is json-path ;)

amwmedia commented 8 years ago

I'll look at dropping in fs-promise and see how that goes. Might make sense now that I'm no longer using q for promises and I need to either depend on denodeify or something like fs-promise.

as far as the json action type, I'd be interested in seeing how you would envision that interface working. Also having a code modification action that uses esprima or the like is an interesting idea, I can't think of a great use case for it right now, but that's probably because it's late... and I'm tired haha.

amwmedia commented 8 years ago

side note, if you're looking to contribute to these types of features you'll want to look at contributing to node-plop. As I mentioned before I'm working up to integrating it into plop. Been setting up unit test coverage and such.

I tried to get unit tests running using mock-fs and mountfs but was not able to make it work well. currently I'm just using a temp directory that gets thrown away and it's working nicely.

kristianmandrup commented 8 years ago

I created this json operator lib this morning: https://www.npmjs.com/package/json-operator I will look into node-plop next :)

amwmedia commented 8 years ago

json-operator looks interesting, I'd be interested to see what type of action object could be created using it. Seems like this would be very handy in custom action functions at least.

kristianmandrup commented 8 years ago

Exactly why I created it. My main use case ;) Now I will learn esprima and estraverse!

amwmedia commented 8 years ago

they are a lot of fun ;-) used them recently for a work project.

amwmedia commented 8 years ago

FYI, one of the features I'm planning to implement soon is pluggable actions. So you could develop action pluggins that people can require() and use in their plopfiles

amwmedia commented 8 years ago

so stay tuned ;-)

kristianmandrup commented 8 years ago

Sounds great! I thought that was already part of plop, one of the main reasons I was drawn to it. A "no brainer". I'm about to develop a much more powerful way of prompting for user input... Using categories of questions, and allowing the context to be fed into each question in order that they reflect the current choices... Also adding a better way of mapping choices to modules to be installed. I think we need to move way beyond using template files, but have a more dynamic generator approach :)

Stay tuned indeed...

https://github.com/kristianmandrup/master-inquisitor https://www.npmjs.com/package/powerdash

amwmedia commented 8 years ago

right now plop supports custom action functions, but this would allow you to essentially publish a custom action function that could be run using a small config object. Similar to how you run the add or modify actions. You would be able to attach your 3rd party actions and just use them by specifying action objects with the corresponding type.

I'd be interested to hear your thoughts on "moving way beyond template files". :-)

kristianmandrup commented 8 years ago

Template files are too static and very limited what you can do IMO. Better to install modules dynamically via f.ex https://www.npmjs.com/package/yarn-install and do file operations, like with json-operator or soon to be code-operator (using esprima and AST transforms etc.) I have loads of ideas for better tooling ;) All just a matter of time and effort! Let's see where we can take this... Looking forward to see you pluggable actions for sure! Cheers!

amwmedia commented 8 years ago

AST driven tooling is really powerful, I think the main challenge there is to also make it simple to understand and implement with.