Last active
August 29, 2015 14:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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