Skip to content

Commit 6ea5104

Browse files
committed
Merge pull request #27 from wilkinsona
* pr/27: Support multi-line yaml to properties conversion
2 parents 643bed2 + b67e181 commit 6ea5104

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/configuration-properties-extension.js

+10
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ class YamlToPropertiesConverter {
9797
if (type === Array) {
9898
return val.reduce((accum, it, idx) => accum.concat(this.toProperty(`${key}[${idx}]`, it, prefix, true)), [])
9999
}
100+
if ((typeof val === 'string' || val instanceof String) && val.includes('\n')) {
101+
const lines = val.split('\n').slice(0, -1)
102+
const lastIdx = lines.length - 1
103+
val = lines.reduce((accum, it, idx) => {
104+
accum = accum.concat(`${it}\\n`)
105+
if (idx !== lastIdx) accum = accum.concat('\\\n')
106+
if (idx === 0) accum = '\\\n'.concat(accum)
107+
return accum
108+
}, '')
109+
}
100110
return [`${propertyName}=${val}`]
101111
}
102112
}

test/configuration-properties-extension-test.js

+20
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,26 @@ describe('configuration-properties-extension', () => {
666666
expect(propertiesBlock.getSourceLines()).to.eql(expected)
667667
})
668668

669+
it('should convert multi-line property in configprops,yaml block to properties', () => {
670+
addConfigurationMetadataFixture()
671+
const input = heredoc`
672+
[configprops,yaml]
673+
----
674+
foo:
675+
bar:
676+
baz: |
677+
one
678+
two
679+
three
680+
----
681+
`
682+
expect(messages).to.be.empty()
683+
const actual = run(input)
684+
const propertiesBlock = actual.findBy({ context: 'listing' })[0]
685+
const expected = ['foo.bar.baz=\\', 'one\\n\\', 'two\\n\\', 'three\\n']
686+
expect(propertiesBlock.getSourceLines()).to.eql(expected)
687+
})
688+
669689
it('should only warn once if invalid property is used in multiple documents in configprops,yaml block', () => {
670690
const input = heredoc`
671691
[configprops,yaml]

0 commit comments

Comments
 (0)