bp

A package for semver bumping
git clone https://git.sr.ht/~ychbn/bp
Log | Files | Refs | README

README.md (3617B)


      1 # bpv - BumP Version
      2 
      3 Bpv is a package that helps you to increase
      4 semver versions in your project. It takes the current
      5 version, increases it, and then updates all matches
      6 in the specified files with the new version.
      7 
      8 ## Installation
      9 
     10 ```
     11 npm i -D bpv
     12 ```
     13 
     14 Or, you may want to install it globally:
     15 
     16 ```
     17 npm i -g bpv
     18 ```
     19 
     20 ## Configuration
     21 
     22 Bpv expects a `bpv.conf.json` file, which
     23 looks like this:
     24 
     25 ```
     26 {
     27 	"currentVersion": "20.0.3",
     28         "commitMessage": "chore: bump version",
     29 	"rules": [
     30 		{"file": "bpv.conf.json", "version": "\"currentVersion\": \"{{version}}\""},
     31 		{"file": "manifest.xml", "version": "\"version\": \"{{version}}\""}
     32 	]
     33 }
     34 ```
     35 - `currentVersion` holds current software's version.
     36 - `rules` is an array of objects with information about files that contain version
     37   strings and how version strings look. `{{version}}` in the "version" property
     38   is an actual semver version. Use `\"` to escape quotes.
     39 - `commitMessage`(**optional**) is a commit message that will be used if  `--commit` flag is provided
     40 
     41 ### Example
     42 
     43 If we have a `build.gradle` file:
     44 
     45 ```
     46     android {
     47       namespace 'com.example.testapp'
     48       compileSdk 33
     49 
     50       defaultConfig {
     51           applicationId "com.example.testapp"
     52           minSdk 24
     53           targetSdk 33
     54           versionCode 1
     55           versionName "1.0.3"
     56           ...
     57       }
     58     }
     59     ...
     60 
     61 ```
     62 
     63 And we want to increment version only in this file, our
     64 `bpv.conf.json` should look so:
     65 
     66 
     67 ```
     68 {
     69 	"currentVersion": "1.0.3",
     70 	"rules": [
     71 		{"file": "bpv.conf.json", "version": "\"currentVersion\": \"{{version}}\""},
     72 		{"file": "android/build.gradle", "version": "versionName \"{{version}}\""}
     73 	]
     74 }
     75 ```
     76 
     77 Note that bpv.conf.json is also presented in the config file.
     78 
     79 
     80 
     81 ## Usage
     82 
     83 ### Increment version
     84 
     85 Use `bump` command with a version number to increment (major, minor, or patch),
     86 for example:
     87 
     88 ```
     89 npx bpv bump --major
     90 ```
     91 
     92 There're also a few optional flags:
     93 
     94 - `--commit`, `-c` - if set, bpv creates
     95   a commit with the "Bump version" message. Under the hood
     96   `bpv` uses `git add -u` or `hg ci` commands to add files, so *files that are not
     97   in the git index won't be commited*. **Supports git and mercurial.**
     98 - `--tag`, `-t` - create a tag after version increment with new version as
     99   annotate message
    100 - `--verbose`, `-v` - print the list of files and the result of version replacement
    101   in them.
    102 
    103 Bump version and create a "Bump version" commit:
    104 
    105 ```
    106 npx bpv bump --patch --commit
    107 ```
    108 
    109 ### Set version
    110 
    111 Use the `set` command to set a version directly:
    112 
    113 ```
    114 npx bpv set "1.0.0-beta.0"
    115 ```
    116 
    117 The `set` command also accepts `--commit`, `--tag` and `--verbose` flags.
    118 
    119 ### Test version bump
    120 
    121 You can check how a command will work without
    122 any real changes with a `--dry` (`-d`) option.
    123 It prints a new version and the list of files that will be changed:
    124 
    125 ```
    126 npx bpv bump --major --dry
    127 ```
    128 
    129 Output:
    130 
    131 ```
    132 DRY RUN MODE IS ON. NO FILES WILL BE ACTUALLY MODIFIED
    133 
    134 New version is: 2.0.0
    135 File: bpv.conf.json changed: true
    136 File: app/last_changelog.md changed: true
    137 ```
    138 
    139 You can use `--dry` option with `--commit` or `--tag` options as well.
    140 No files will be committed and no tags will be created, but you can
    141 see any potential issues:
    142 
    143 ```
    144 npx bpv bump --major -dct
    145 ```
    146 
    147 Output:
    148 
    149 ```
    150 Can't commit because the repository has modified files
    151 ```
    152 
    153 
    154 ## TODO
    155 
    156 - [x] Use `bp.conf.json` config file instead of `bpv.conf.json`
    157 - [x] Check if git is available before commit/tag
    158 - [x] Add support for other VCS (mercurial)
    159 - [x] Get rid of `replace-in-file` package dependency
    160 - [x] Add `set` command to manually set the version
    161 - [x] Create tags in git, not only commits