Skip to content

Commit

Permalink
[dist api doc] Move vbump to its own git repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Jun 11, 2015
0 parents commit 4dda285
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2011 Charlie Robbins

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# vbump

```
usage: vbump options
This commits a version bump and tags it git, then published to npm.
OPTIONS:
-v [required] Target version to bump.
-t Tag only. Do not git commit.
-h Show this message.
-p Do not publish to npm.
-m Commit message you wish to use.
-d Dry-run. No nothing but echo commands.
```

##### Author: [Charlie Robbins](https://github.com/indexzero)
##### License: MIT
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "vbump",
"version": "0.0.0",
"description": "A script to bump versions of things to git, npm, etc.",
"preferGlobal": true,
"bin": "./vbump",
"scripts": {
"test": "echo \"No tests.\""
},
"keywords": [
"npm",
"versioning",
"vbump"
],
"author": "Charlie Robbins <[email protected]>",
"license": "MIT"
}
132 changes: 132 additions & 0 deletions vbump
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/bin/bash

# TODO: Use the parsed package.json script and check the git tags against it.
#[ -f "package.json" ] && VERSION=`pkgver package.json` || VERSION=

VERSION=
NO_NPM=
CHANGED=
DRY_RUN=
TAG_ONLY=
COMMIT_MSG=

#
# usage()
# Prints the usage for this script
#
usage()
{
cat << EOF
usage: vbump options
This commits a version bump and tags it git, then published to npm.
OPTIONS:
-v [required] Target version to bump.
-t Tag only. Do not git commit.
-h Show this message.
-p Do not publish to npm.
-m Commit message you wish to use.
-d Dry-run. No nothing but echo commands.
EOF
}

#
# checkgit()
# Ensures everything is up-to-date
#
checkgit() {
echo "Checking git for remote updates"
git pull --dry-run | grep -q -v 'Already up-to-date.' && CHANGED=1

if [ ! -z $CHANGED ]; then
echo "You need to pull from the remote before continuing"
echo "Run 'git pull origin master'"
exit 1
fi
}

# Setup colors
source $HOME/.functions
set_colors

while getopts "v:m:hpdt" OPTION; do
case $OPTION in
h)
usage
exit
;;
d)
echoc "-d: Executing dry-run..." "YELLOW"
DRY_RUN=1
;;
t)
echoc "-t: Skipping 'git commit'" "YELLOW"
TAG_ONLY=1
;;
p)
echoc "-p: Skipping 'npm publish'" "YELLOW"
NO_NPM=1
;;
m)
COMMIT_MSG=$OPTARG
;;
v)
VERSION=$OPTARG
;;
\?)
usage
exit
;;
esac
done

#
# If there is no version then exit; it is required.
#
if [ -z $VERSION ]; then
echoc "No version specified. Use -v VERSION" "YELLOW"
usage
exit
fi

#
# If no custom message was supplied then use
# the default message
#
if [ -z "$COMMIT_MSG" ]; then
COMMIT_MSG="[dist] Version bump. $VERSION"
fi

# Check git remote(s)
checkgit

#
# Run git commit only if `-t` is not set
#
if [ -z $TAG_ONLY ]; then
run git add .
run git commit -m "$COMMIT_MSG"
fi

#
# Always tag since we are version bumping.
#
run git tag -a "$VERSION" -m "Version $VERSION"
run git push --tags

#
# Push to `master` only if `-t` is not set
#
if [ -z $TAG_ONLY ]; then
run git push origin master
fi

# Check for a package.json
if [ -z $NO_NPM ]; then
if [ ! -f 'package.json' ]; then
echoc "No package.json file. Skipping 'npm publish'" "YELLOW"
else
run npm publish
fi
fi

0 comments on commit 4dda285

Please sign in to comment.