You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a new block or plugin using the @create-block package we are limited to a certain number of parameters that we are prompted, it would be awesome if we could add more to the list, based on our custom configuration.
There is a getDefaultValues and getPrompts, maybe when someone defines params DefaultValues that are not predefined, we still prompt for them so they are later available in mustache when scaffolding the block?
@eduwass, great thinking. That has crossed my mind a few times to allow defining custom prompts in external templates. I'd be more than happy to see a proof of concept for how that would work best from the perspective of someone willing to offer additional customizations for the tool.
+1 to this idea. These additional prompts could be defined in the variants for the template being used. @eduwass do you have an example of a field that you'd want to add?
I think this contains a couple of examples of how I'd envision this working:
000445.mp4Heres the code for: my-template/index.js
/** * Dependencies */const{ join }=require("path");module.exports={defaultValues: {title: "My Template",description: "My Template Description",icon: "admin-post",// Default values for custom promptsanalyticsId: 'UA-11111-2',colorScheme: 'default',enableAdvancedFeatures: false,customCssPrefix: 'default-prefix-',},customPrompts: {analyticsId: {type: 'input',name: 'analyticsId',message: 'Enter your Google Analytics ID (optional, format: UA-XXXXX-Y):',validate(input){if(!input)returntrue;// Optionalif(!/^UA-\d+-\d+$/.test(input)){return'Invalid Google Analytics ID format. Should be like UA-XXXXX-Y';}returntrue;}},colorScheme: {type: 'list',name: 'colorScheme',message: 'Choose a color scheme for your block:',choices: [{name: 'Default Theme Colors',value: 'default'},{name: 'Custom Palette',value: 'custom'},{name: 'Monochrome',value: 'mono'}],default: 'default'},enableAdvancedFeatures: {type: 'confirm',name: 'enableAdvancedFeatures',message: 'Would you like to enable advanced block features?',default: false},customCssPrefix: {type: 'input',name: 'customCssPrefix',message: 'Enter a custom CSS prefix for your block (optional):',validate(input){if(!input)returntrue;// Optionalif(!/^[a-z][a-z0-9-]*$/.test(input)){return'CSS prefix must start with a letter and contain only lowercase letters, numbers, and hyphens';}returntrue;},filter(input){returninput.toLowerCase();}}},// Make sure template files are foundpluginTemplatesPath: join(__dirname,'files','plugin'),blockTemplatesPath: join(__dirname,'files','block'),};
So far...
Successfully got the prompts working and displaying in the CLI interface
Values populating into the .mustache template files
This is still barebones but just tried to get a working proof-of-concept as a starting point.
Open Questions/Challenges
Several areas still need investigation and testing:
blockAnswers vs pluginAnswers handling
How variants should be properly handled
Interactive mode behavior when no slug is provided
What do you think? Any thoughts on the above points?
Activity
gziolo commentedon Feb 7, 2023
@eduwass, great thinking. That has crossed my mind a few times to allow defining custom prompts in external templates. I'd be more than happy to see a proof of concept for how that would work best from the perspective of someone willing to offer additional customizations for the tool.
eduwass commentedon Feb 7, 2023
Thanks @gziolo appreciate it, if I have some free time from work to put aside into this I'll look into it.
ryanwelcher commentedon Dec 10, 2024
+1 to this idea. These additional prompts could be defined in the
variantsfor the template being used. @eduwass do you have an example of a field that you'd want to add?eduwass commentedon Dec 10, 2024
Hi @ryanwelcher
So I opened this a long time ago, but since you pinged me here and I had some time I've played around with the idea today in a POC.
You can see the fork here.
Quick Demo
I think this contains a couple of examples of how I'd envision this working:
000445.mp4
Heres the code for: my-template/index.js
So far...
This is still barebones but just tried to get a working proof-of-concept as a starting point.
Open Questions/Challenges
Several areas still need investigation and testing:
What do you think? Any thoughts on the above points?
Thanks!
ryanwelcher commentedon Dec 10, 2024
This is great start! I'd open a PR based on your fork and we can go from there.
eduwass commentedon Dec 10, 2024
@ryanwelcher OK great, I just created the initial PR here: #67806