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

Add support for writing to / reading from specific fields in JSON / YAML files #26

Open
loreanvictor opened this issue Aug 8, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@loreanvictor
Copy link
Owner

write and from file commands can benefit from being able to specific fields in JSON / YAML files, specifically for recipes that want to alter an existing projects. For example, the following could read the name of the package:

read: package_name
from file: package.json
at: /name

Or the following could add dependencies:

write: '^6.0.1'
to: package.json
at: /dependencies/some-package

Write can support at, before and after properties to allow inserting to arrays as well. The field addressing syntax is JSON Pointer. It is important to not screw up files that are written to, maintaining their styling, for which packages such as json-source-map and mapped-yaml can be used (perhaps a separate package should be written for this specific purpose). Additionally, the filesystem object might want to do some caching of files that are read / written to, to save on processing costs (though this might be a later-on feature).

@loreanvictor loreanvictor added the enhancement New feature or request label Aug 8, 2023
@loreanvictor
Copy link
Owner Author

It generally is a nice idea to support more config formats. That said, JavaScript itself is used commonly as a config format and will be enforced on large projects such as eslint. Perhaps tools like recast can be used to handle JS code in a similar manner to JSON or YAML, however JS config files do not have a specific format, and this might result in flaky recipes that only work in particular scenarios. Can this be helped with additional helpers? If so, to which extent? Something to think about.

@loreanvictor
Copy link
Owner Author

a note on the flaky recipes of js configs: this will only result in flaky reusable recipes. templates can control the config format, so they wouldn't have issues with such shenanigans.

@fwextensions
Copy link

This would be very handy for updating a package.json file with variations on a name string entered by the user. Right now, I think I'll need to maintain a template package.json and keep it in sync with the real one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants