jkcfg / jk

Configuration as Code with ECMAScript
https://jkcfg.github.io
Apache License 2.0
404 stars 30 forks source link

Transform doesn't write streams back again #332

Closed squaremo closed 4 years ago

squaremo commented 4 years ago

If you give jk transform a file input with multiple documents, it'll transform each individually; but, when it goes to write them out, it has separate entries for each value using the same filename, and the generate code will complain that you're trying to overwrite a file.

For example,

$ cat > values.yaml <<EOF
foo: 1
---
foo: 4
EOF
$ jk transform -c '({ foo }) => ({ foo: foo * 2 })' values.yaml -o doubled/
Promise rejected at @jkcfg/std/write.js 0:0
Error: file doubled/values.yaml already exists
    at Module.write (@jkcfg/std/write.js:57:11)
    at Promise.all.then (@jkcfg/std/cmd/generate.js:210:25)

There's two problems in the code: firstly, transform correctly transforms each value, but gives each its own entry, rather than giving them back as an array; second, it needs to give them the stream format, so they will be written as multiple values, rather than as an array, in the file.