Skip to content

Commit 69d722f

Browse files
committed
feat(yaml): adding yaml support
1 parent 017dcb6 commit 69d722f

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ npm run release -- --help
324324
standard-version --help
325325
```
326326

327+
### YAML support
328+
With CLI
329+
```sh
330+
# global bin
331+
standard-version --packageFiles path/to/your/file.yaml --bumpFiles path/to/your/file.yaml
332+
```
333+
Or using `.versionrc`, [see below](#can-i-use-standard-version-for-additional-metadata-files-languages-or-version-files)
334+
327335
## Code Usage
328336

329337
```js
@@ -390,7 +398,13 @@ As of version `7.1.0` you can configure multiple `bumpFiles` and `packageFiles`.
390398
"type": "json"
391399
},
392400
{
393-
"filename": "VERSION_TRACKER.json",
401+
"filename": "a/deep/package/dot/yaml/file/MY_VERSION_TRACKER.yaml",
402+
// The `yaml` updater assumes the version is available under a `version` key in the provided YAML document.
403+
// filename extension: yaml or yml
404+
"type": "yaml"
405+
},
406+
{
407+
"filename": "MY_VERSION_TRACKER.json",
394408
// See "Custom `updater`s" for more details.
395409
"updater": "standard-version-updater.js"
396410
}

lib/updaters/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const path = require('path')
22
const JSON_BUMP_FILES = require('../../defaults').bumpFiles
33
const updatersByType = {
44
json: require('./types/json'),
5-
'plain-text': require('./types/plain-text')
5+
'plain-text': require('./types/plain-text'),
6+
yaml: require('./types/yaml')
67
}
78
const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt']
89

@@ -21,6 +22,9 @@ function getUpdaterByFilename (filename) {
2122
if (PLAIN_TEXT_BUMP_FILES.includes(filename)) {
2223
return getUpdaterByType('plain-text')
2324
}
25+
if (/.ya?ml$/.test(filename)) {
26+
return getUpdaterByType('yaml')
27+
}
2428
throw Error(
2529
`Unsupported file (${filename}) provided for bumping.\n Please specify the updater \`type\` or use a custom \`updater\`.`
2630
)

lib/updaters/types/yaml.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const YAML = require('yaml')
2+
3+
module.exports.readVersion = function (contents) {
4+
return YAML.parse(contents).version
5+
}
6+
7+
module.exports.writeVersion = function (contents, version) {
8+
const yaml = YAML.parse(contents)
9+
yaml.version = version
10+
return YAML.stringify(yaml)
11+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"git-semver-tags": "^4.0.0",
5151
"semver": "^7.1.1",
5252
"stringify-package": "^1.0.1",
53+
"yaml": "^1.10.2",
5354
"yargs": "^16.0.0"
5455
},
5556
"devDependencies": {

test/core.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { Readable } = require('stream')
99
const mockFS = require('mock-fs')
1010
const mockery = require('mockery')
1111
const stdMocks = require('std-mocks')
12+
const YAML = require('yaml')
1213

1314
const cli = require('../command')
1415
const formatCommitMessage = require('../lib/format-commit-message')
@@ -545,6 +546,22 @@ describe('standard-version', function () {
545546
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('6.4.0')
546547
})
547548

549+
it('reads and writes to a custom `yaml` file', async function () {
550+
mock({
551+
bump: 'minor',
552+
fs: {
553+
'Chart.yaml': fs.readFileSync(
554+
'./test/mocks/Chart-9.2.0.yaml'
555+
)
556+
}
557+
})
558+
await exec({
559+
packageFiles: [{ filename: 'Chart.yaml', type: 'yaml' }],
560+
bumpFiles: [{ filename: 'Chart.yaml', type: 'yaml' }]
561+
})
562+
YAML.parse(fs.readFileSync('Chart.yaml', 'utf-8')).version.should.equal('9.3.0')
563+
})
564+
548565
it('allows same object to be used in packageFiles and bumpFiles', async function () {
549566
mock({
550567
bump: 'minor',

test/mocks/Chart-9.2.0.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: chart-project
3+
description: A Helm chart for Kubernetes
4+
type: application
5+
version: 9.2.0
6+
appVersion: 2021.04

0 commit comments

Comments
 (0)