diff --git a/npm2git.sh b/npm2git.sh index 67256cc..fdf31e3 100755 --- a/npm2git.sh +++ b/npm2git.sh @@ -5,11 +5,11 @@ set -e cd $(git rev-parse --show-toplevel) # get commit id -COMMIT_ID="$(git rev-parse HEAD)" +ORIG_COMMIT="$(git rev-parse HEAD)" # extract package name and version from package.json, remove scripts.prepare ORIG_PKG="$(cat package.json)" -read NAME VERSION < <(node -e ' +read PKG_NAME PKG_VERSION < <(node -e ' const fs = require("fs"); const pkg = JSON.parse(fs.readFileSync("package.json")); if (pkg.scripts && pkg.scripts.prepare) { @@ -21,19 +21,19 @@ read NAME VERSION < <(node -e ' # determine current branch name, and create new temporary branch ORIG_BRANCH=$(git symbolic-ref --short HEAD) -TEMP_BRANCH=RELEASE_${VERSION}_$(date +'%Y%m%d%H%M%S') +TEMP_BRANCH=RELEASE_${PKG_VERSION}_$(date +'%Y%m%d%H%M%S') git add . git checkout --orphan=${TEMP_BRANCH} # untrack all files, and track the files that should be included in the published package git rm --cached -r . npm pack -git add -f $(tar tf ${NAME}-${VERSION}.tgz | cut -c 9-) -rm ${NAME}-${VERSION}.tgz +git add -f $(tar tf ${PKG_NAME}-${PKG_VERSION}.tgz | cut -c 9-) +rm ${PKG_NAME}-${PKG_VERSION}.tgz # commit and tag -git commit -m "v${VERSION} @ ${COMMIT_ID}" -git tag v${VERSION} -a -m "v${VERSION} @ ${COMMIT_ID}" +git commit -m "v${PKG_VERSION} @ ${ORIG_COMMIT}" +git tag v${PKG_VERSION} -a -m "v${PKG_VERSION} @ ${ORIG_COMMIT}" # return to original state git reset ${ORIG_BRANCH}