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

Support for creating files dynamically #316

Open
buremba opened this issue Nov 17, 2022 · 3 comments
Open

Support for creating files dynamically #316

buremba opened this issue Nov 17, 2022 · 3 comments

Comments

@buremba
Copy link

buremba commented Nov 17, 2022

I'm working on a Superplate plugin that will automatically generate the CRUD pages based on the value the user enters for a config defined in prompt.js. In order to be able to create the CRUD pages, I'm looking for a way to create Typescript files/directories in a dynamic way and I couldn't figure out how I can do that. Is it something on the roadmap?

@aliemir
Copy link
Contributor

aliemir commented Nov 17, 2022

Hey @buremba, that's a good idea really, and can inspire for more ideas around that. Unfortunately this is not planned in our roadmap due to limitations on SAO. We use SAO for compiling the templates in the files and moving etc and it does not support such dynamic structure. (I guess it won't be because its archived already by the owner of the project 😅)

Still, I think we can do a workaround here, we already have extend.js for the plugins which allows them to pass conditional values and ignore files conditionally.

We can add some field like files with type Array<{ path: string; filename: string; content: string; encoding: string; }> which can be created dynamically by the answers to the prompts.

Then, we should create those files inside the plugin file (already stored in a temporary directory after cloning). This way we can trick SAO to handle those files like the regular plugin files (compiling and moving to the target).

As the result, we can create files dynamically. 🎉 🎉

While doing so, we might need to check and update our code for handling prompts, for dynamic files we might want to support wider range of prompt types 🤔

Currently, this is not planned but hypothetically it looks like something achievable 😅 If you want to give it a try, We'll be happy to help 🙏

@buremba
Copy link
Author

buremba commented Nov 17, 2022

Thanks for the quick answer @aliemir! I understand the limitation and I feel like this is not Refine/Superplate's focus and the solution that you suggested makes sense.

What would you think about implementing something more generic such as a post_hook in ArrayPromptOptions? It can be a function with the following signature:

{ choice: Choice; path: string; }

Superplate can call this callback function/hook when the user selects a choice and the template files are generated automatically. That way, the post_hook can generate files or do something else as it's just a function. My assumption is that this is easier to implement and also generic enough to cover different use cases. WDYT?

@aliemir
Copy link
Contributor

aliemir commented Nov 23, 2022

Hey @buremba sorry for the late response 🙏 post_hook is a better generic to handle 🚀 I think there's no limitation on the current codebase to conflict with this implementation 🤔 We might need to provide a richer context to post_hook to enable wider range of use cases maybe? (Just thinking out loud 😅)

Thanks again for the issue, I'll definitely try to spare some time for this. This can provide a great flexibility to plugins 💪

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

2 participants