Skip to content

Commit

Permalink
(#197) - Rework release.sh to also issue browser builds
Browse files Browse the repository at this point in the history
  • Loading branch information
loic authored and marten-de-vries committed Jan 25, 2018
1 parent 83152b0 commit e451a6d
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 46 deletions.
61 changes: 59 additions & 2 deletions bin/release.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
#!/usr/bin/env bash

set -e

if [ ! -z $DRY_RUN ]; then
echo "Doing a dry run release..."
elif [ ! -z $BETA ]; then
echo "Doing a beta release to npm..."
else
echo "Doing a real release! Use DRY_RUN=1 for a dry run instead."
fi

#make sure deps are up to date
#rm -fr node_modules
npm install

# get current version
VERSION=$(node --eval "console.log(require('./package.json').version);")

# Create a temporary build directory
SOURCE_DIR=$(git name-rev --name-only HEAD)
BUILD_DIR=build_"${RANDOM}"
git checkout -b $BUILD_DIR

# Update dependency versions inside each package.json (replace the "*")
node bin/update-package-json-for-publish.js

# Publish all modules with Lerna
for pkg in $(ls packages/node_modules); do
if [ ! -d "packages/node_modules/$pkg" ]; then
continue
Expand All @@ -8,8 +34,39 @@ for pkg in $(ls packages/node_modules); do
fi
cd packages/node_modules/$pkg
echo "Publishing $pkg..."
npm publish
if [ ! -z $DRY_RUN ]; then
echo "Dry run, not publishing"
elif [ ! -z $BETA ]; then
npm publish --tag beta
else
npm publish
fi
cd -
done

git checkout -- packages/node_modules/*/package.json
# Build browser packages
for pkg in $(ls packages/node_modules); do
if [ "false" = $(node --eval "console.log(!!require('./package.json').browserPackages['$pkg']);") ]; then
continue
fi
module_name=$(node --eval "console.log(require('./package.json').browserPackages['$pkg']);")
browserify packages/node_modules/$pkg -o packages/node_modules/$pkg/dist/$pkg.js -s $module_name
uglifyjs packages/node_modules/$pkg/dist/$pkg.js -o packages/node_modules/$pkg/dist/$pkg.min.js
done

# Create git tag, which is also the Bower/Github release
git add -f ./packages/node_modules/*/dist
git commit -m "build $VERSION"

# Only "publish" to GitHub/Bower if this is a non-beta non-dry run
if [ -z $DRY_RUN ]; then
if [ -z $BETA ]; then
# Tag and push
git tag $VERSION
git push --tags git@github.com:pouchdb/pouchdb-server.git $VERSION

# Cleanup
git checkout $SOURCE_DIR
git branch -D $BUILD_DIR
fi
fi
8 changes: 5 additions & 3 deletions bin/prerelease.js → bin/update-package-json-for-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ modules.forEach(function (mod) {
dep = dep.split('/')[0]; // split colors/safe to be colors

if (topPkg.dependencies[dep]) {
deps.dependencies[dep] = topPkg.dependencies[dep];
if (modules.indexOf(dep) !== -1) { // core pouchdb-* module
deps.dependencies[dep] = topPkg.version;
} else {
deps.dependencies[dep] = topPkg.dependencies[dep];
}
} else if (topPkg.optionalDependencies[dep]) {
deps.optionalDependencies[dep] = topPkg.optionalDependencies[dep];
} else if (modules.indexOf(dep) !== -1) { // core pouchdb-* module
deps.dependencies[dep] = topPkg.version;
} else {
throw new Error('Unknown dependency ' + dep);
}
Expand Down
Loading

0 comments on commit e451a6d

Please sign in to comment.