File tree Expand file tree Collapse file tree 6 files changed +55
-2
lines changed Expand file tree Collapse file tree 6 files changed +55
-2
lines changed Original file line number Diff line number Diff line change @@ -324,6 +324,14 @@ npm run release -- --help
324
324
standard-version --help
325
325
```
326
326
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
+
327
335
## Code Usage
328
336
329
337
``` js
@@ -390,7 +398,13 @@ As of version `7.1.0` you can configure multiple `bumpFiles` and `packageFiles`.
390
398
" type" : " json"
391
399
},
392
400
{
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" ,
394
408
// See "Custom `updater`s" for more details.
395
409
" updater" : " standard-version-updater.js"
396
410
}
Original file line number Diff line number Diff line change @@ -2,7 +2,8 @@ const path = require('path')
2
2
const JSON_BUMP_FILES = require ( '../../defaults' ) . bumpFiles
3
3
const updatersByType = {
4
4
json : require ( './types/json' ) ,
5
- 'plain-text' : require ( './types/plain-text' )
5
+ 'plain-text' : require ( './types/plain-text' ) ,
6
+ yaml : require ( './types/yaml' )
6
7
}
7
8
const PLAIN_TEXT_BUMP_FILES = [ 'VERSION.txt' , 'version.txt' ]
8
9
@@ -21,6 +22,9 @@ function getUpdaterByFilename (filename) {
21
22
if ( PLAIN_TEXT_BUMP_FILES . includes ( filename ) ) {
22
23
return getUpdaterByType ( 'plain-text' )
23
24
}
25
+ if ( / .y a ? m l $ / . test ( filename ) ) {
26
+ return getUpdaterByType ( 'yaml' )
27
+ }
24
28
throw Error (
25
29
`Unsupported file (${ filename } ) provided for bumping.\n Please specify the updater \`type\` or use a custom \`updater\`.`
26
30
)
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 50
50
"git-semver-tags" : " ^4.0.0" ,
51
51
"semver" : " ^7.1.1" ,
52
52
"stringify-package" : " ^1.0.1" ,
53
+ "yaml" : " ^1.10.2" ,
53
54
"yargs" : " ^16.0.0"
54
55
},
55
56
"devDependencies" : {
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ const { Readable } = require('stream')
9
9
const mockFS = require ( 'mock-fs' )
10
10
const mockery = require ( 'mockery' )
11
11
const stdMocks = require ( 'std-mocks' )
12
+ const YAML = require ( 'yaml' )
12
13
13
14
const cli = require ( '../command' )
14
15
const formatCommitMessage = require ( '../lib/format-commit-message' )
@@ -545,6 +546,22 @@ describe('standard-version', function () {
545
546
fs . readFileSync ( 'VERSION_TRACKER.txt' , 'utf-8' ) . should . equal ( '6.4.0' )
546
547
} )
547
548
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
+
548
565
it ( 'allows same object to be used in packageFiles and bumpFiles' , async function ( ) {
549
566
mock ( {
550
567
bump : 'minor' ,
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments