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 a write command #23

Closed
loreanvictor opened this issue Jul 31, 2023 · 2 comments
Closed

Add a write command #23

loreanvictor opened this issue Jul 31, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@loreanvictor
Copy link
Owner

loreanvictor commented Jul 31, 2023

The command would simply write to a file. This can be useful for creating files without source templates, however the main idea is to allow the command to write to specific parts of a file, if they are for example json or yaml files.

# create a file
write: some stuff
to: myfile.txt
# add a dependency
write: '^6.1.0'
to: package.json
at: 'devDependencies/@typescript-eslint~1eslint-plugin'
# add a workflow step
write: |
      - name: check code style
        run: npm run lint
to: .github/workflows/publish.yml
after: jobs/run/steps/4

JSON Pointer format is used here. I suspect json-source-map and mapped-yaml (or equivalent libraries) can be used to precisely alter some JSON or YAML file while maintaining its formatting as much as possible.

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

loreanvictor commented Aug 6, 2023

This command could also benefit from the proposed filtering of files if it were to support glob patterns, specifically to allow the content to also be evaluated per file. This could basically remove the need for the proposed append and prepend commands.

write: '{{ license }}\n{{ content }}'
to: **/*.(jsx?|tsx?|cpp|java)
where:
  steps:
    - read: content
      from file: __file__
  eval: '{{ content | not matches: /.../ }}'

@loreanvictor
Copy link
Owner Author

base command added via 8ce8644. additional proposals (filtering and JSON / YAML support) should be tracked in separate issues (as they also involve multiple commands).

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

1 participant