1
Fork 0

node: add modified npmg.sh script

This commit is contained in:
Alan Faubert 2019-05-29 22:36:28 -04:00
parent e9e55d8004
commit c696c94eb7
1 changed files with 27 additions and 0 deletions

27
node/npmg.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/sh
set -e
cd "$(git rev-parse --show-toplevel)"
ORIG_HEAD="$(git symbolic-ref HEAD)"
cp package.json package.json.bak
PKG_VERSION="$(node -e '
const fs = require("fs");
const str = fs.readFileSync("package.json").toString();
const m = str.match(/\n([\t ]+)/);
const indent = m ? m[1] : "\t";
const pkg = JSON.parse(str);
pkg.scripts && delete pkg.scripts.prepare;
fs.writeFileSync("package.json", JSON.stringify(pkg, null, indent) + (str.endsWith("\n") ? "\n" : ""));
console.log(pkg.version);
')"
TEMP_BRANCH="NPMG-$PKG_VERSION-$(date +%Y%m%d%H%M%S)"
git checkout -b "$TEMP_BRANCH"
git rm --cached -rf .
PKG_TAR="$(npm pack | tail -n 1)"
tar tf "$PKG_TAR" | cut -c 9- | xargs -d '\n' git add -f
git commit -nm "release version $PKG_VERSION"
rm "$PKG_TAR"
mv -f package.json.bak package.json
git symbolic-ref HEAD "$ORIG_HEAD"
git reset
git tag "v$PKG_VERSION" "$TEMP_BRANCH" -am ""
git branch -D "$TEMP_BRANCH"