Skip to content

Instantly share code, notes, and snippets.

@blakeembrey
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blakeembrey/8bad897ad8a434773b7c to your computer and use it in GitHub Desktop.
Save blakeembrey/8bad897ad8a434773b7c to your computer and use it in GitHub Desktop.
Replace source file version automagically with https://www.npmjs.com/package/pre-commit
{
"scripts": {
"bump-version": "FILE=\"src/typescript-node.ts\"; if [ \"$(git status --porcelain | grep \"^ M \"$FILE)\" = \"\" ]; then VERSION=$(node -p \"require('./package.json').version\") && sed \"s/VERSION = '\\([0-9]*\\.[0-9]*\\.[0-9]*\\)'/VERSION = '\"$VERSION\"'/\" $FILE > .tmp.ts && mv .tmp.ts $FILE && git add $FILE; fi"
},
"pre-commit": [
"bump-version",
"# test"
],
"devDependencies": {
"pre-commit": "^1.0.10"
}
}
# First, we want to make sure that the file we're updating is clean using git.
# Next, replace a string (here it's "VERSION = '0.0.6'") with the current package version from `package.json`.
FILE="src/typescript-node.ts"; if [ "$(git status --porcelain | grep "^ M "$FILE)" = "" ]; then VERSION=$(node -p "require('./package.json').version") && sed "s/VERSION = '\([0-9]*\.[0-9]*\.[0-9]*\)'/VERSION = '"$VERSION"'/" $FILE > .tmp.ts && mv .tmp.ts $FILE && git add $FILE; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment