I'm starting a new project, and as part of its interface we have a whole bunch of "tokens", a recursive object with string values, like so:
const colors = {
accent: '#f90',
primary: {
active: '#fff',
inactive: 'silver'
}
};
We offer a utility for using those through string-based path (e.g., primary.active for #fff in this case). Extracting all possible paths into an array is easy enough, but what we'd like to offer is better autocomplete for the consumers of this package, so rather than 'string', a union or enum of these possible paths. Does anybody maybe have experience with this? My initial approach would be to write a simple script that takes an array and prints it as a union using a template or some such, but given that we want to do this more often and our use-cases will increase in complexity, I think generating and printing an AST is maybe a better approach. I've written babel and recast codemods before, I'm just looking for some guidance with regards to existing toolsets, examples etc. I've done a quick Google but couldn't find anything. Ideally these will recompile along with my normal "watch" process, but that's a stretch-goal ^_^.