npm package: @modea/modea-increment-version
Description: Increments version and build numbers in specified files
Author: Jacob Heuman
Latest version: 0.6.2

# Modea Increment Version Library

A npm package that increments build and version numbers.

## What it does

Increments version and build numbers in specified files.

Optionally it can also follow git flow on a bitbucket repo.

For example: you have just finished a new feature and pushed that onto your dev branch.
If you run this script, it can create a new branch, increment build and version numbers and then PR that branch onto master and dev and merge those PR's if no conflicts arise.

## Install

```
npm install @modea/modea-increment-version
```

## Usage

Once installed create a file at the base of your repo with the file name `.incrementrc`

In that file enter a valid json list of files you want changed and where, and optionally git information if you want the script to push to git

You can then run

```
increment [major | minor | patch | build]
```

Where major increments the first version number, minor the second, and patch the third

so

```
increment -t patch
```

on version 1.9.3 build 27 would increment to 1.9.4 and 28

```
increment -t build
```

on version 1.9.3 build 27 would increment to 1.9.3 and 28

### File Object:

```
{
 "colloquialName": "the colloquial name for this file",
 "path": "path from repo root of the file you want changed",
 "changes": [
   {
     "type": "wether this is a [build] number or [version] code",
     "startIdentifier": "the text right before the build or version code that uniquely identifies it",
     "endIdentifier": "the text right after"
   }
 ]
}
```

### Git Object

```
{
  "branchName": "the name of the branch you want to push the changes to. You can include version and build numbers in this by writting {{fileColloquialName.[version | build]}}",
  "pr": {
    "createUrl": "url to curl to for creating a PR",
    "mergeUrl": "url to curl to for merging a PR",
    "branches": A list of branches you want to PR onto [
      {
        "name": "branch name",
        "mergeStrategy": "which merge strategy to use for merging the PR"
      },
    ]
  },
  "user": {
    "name": "git username to use in curl request",
    "password": "git password to use in curl request"
  }}
```

### Ticket Prefix

Optionally if you want the increment script to add ticket id's since last increment triggered sync merge from master onto development you can include the ticket prefix attribute to the json object
This prefix is the part before the dash in your jira ticket id's

```
ticketPrefix: 'BH23'
```

### Example

Sample .incrementrc file for changing version and build number in build.gradle for android
and version and build number in info.plist for ios

```
{
  "files": [
    {
      "colloquialName": "android",
      "path": "android/app/build.gradle",
      "changes": [
        {
          "type": "version",
          "startIdentifier": "versionName '",
          "endIdentifier": "'\n"
        },
        {
          "type": "build",
          "startIdentifier": "versionCode ",
          "endIdentifier": "\n"
        }
      ]
    },
    {
      "colloquialName": "ios",
      "path": "ios/App/App.xcodeproj/project.pbxproj",
      "changes": [
        {
          "type": "version",
          "startIdentifier": "RELEASE_MARKETING_VERSION = ",
          "endIdentifier": ";"
        },
        {
          "type": "build",
          "startIdentifier": "RELEASE_PROJECT_VERSION = ",
          "endIdentifier": ";"
        },
        {
          "type": "version",
          "startIdentifier": "DEBUG_MARKETING_VERSION = ",
          "endIdentifier": ";"
        },
        {
          "type": "build",
          "startIdentifier": "DEBUG_PROJECT_VERSION = ",
          "endIdentifier": ";"
        }
      ]
    },
    {
      "colloquialName": "package.json",
      "path": "package.json",
      "changes": [
        {
          "type": "version",
          "startIdentifier": "\"version\": \"",
          "endIdentifier": "\","
        }
      ]
    }
  ],
  "git": {
    "branchName": "release/v{{ios.version}}",
    "pr": {
      "branches": [
        {
          "name": "development",
          "mergeStrategy": "squash"
        },
        {
          "name": "master",
          "mergeStrategy": "squash"
        }
      ]
    },
    "packageLocation": "/usr/local/lib/node_modules/"
  },
  "ticketPrefix": "BH23"
}



```

What the build.gradle file looks like:

```
...
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1568
        versionName '10.4.3'
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
...
```

What the info.plist file looks like:

```
...
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.9.3</string>
	<key>CFBundleURLTypes</key>
...
	</array>
	<key>CFBundleVersion</key>
	<string>27</string>
	<key>FIREBASE_ANALYTICS_COLLECTION_ENABLED</key>
...

```

bitbucket-pipelines.yml

```
  custom:
    increment-patch-version:
      - step:
          image: node:10
          script:
            - increment patch
    increment-minor-version:
      - step:
          image: node:10
          script:
            - increment minor
    increment-major-version:
      - step:
          image: node:10
          script:
            - increment major
```

## Future Work

- Command line options for
  - path to config file
  - changing only specified files out of the ones in the config file
  - turning git on or off
- git changes
  - Use with github ci as well as bitbucket pipeline
  - custom commit messages
  - tagging support
  - just pushing straight back to specified branch (no PR's)