forked from nrwl/nx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.sh
executable file
·75 lines (60 loc) · 2.33 KB
/
publish.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
# This script will:
# - Run the package script
# - copy built packages into new directory, so as to not mutate in place
# - NOT change the version of the root package.json
# - set all built package versions to value provided in the command line OR the version in the root package.json
# - validate that the supplied version is a valid npm version according to the semver spec
# - check that npm does not already have this version published for ANY package
# - publish all packages in the build/packages directory to npm
# - publish to the provided tag OR `latest` by default
# i.e. ./scripts/publish.sh 1.0.0-beta.1 beta
VERSION=$1
TAG=$2
PACKAGE_SOURCE=build/packages
NPM_DEST=build/npm
ORIG_DIRECTORY=`pwd`
# Grab version from package.json if not provided as 1st arg
if [ -z "$VERSION" ]; then
VERSION=`node -e "console.log(require('./package.json').version)"`
fi
# Validate that the version is valid according to semver
VERSION=`node -e "console.log(require('semver').valid('${VERSION}'))"`
if [ "$VERSION" = "null" ]; then
echo "Version $VERSION is not valid semver"
exit 1
fi
if [ -z "$TAG" ]; then
TAG="latest"
fi
./scripts/package.sh $VERSION $VERSION
# Create working directory and copy over built packages
rm -rf $NPM_DEST
mkdir -p $NPM_DEST
cp -R $PACKAGE_SOURCE/* $NPM_DEST/
# Get rid of tarballs at top of copied directory (made with npm pack)
find $NPM_DEST -name *.tgz -maxdepth 1 -delete
for package in $NPM_DEST/*/
do
PACKAGE_DIR="$(basename ${package})"
cd $NPM_DEST/$PACKAGE_DIR
# Check that the new version for the package is not taken
PACKAGE_NAME=`node -e "console.log(require('./package.json').name)"`
echo "Preparing to publish ${PACKAGE_NAME}"
# Package might not exist yet, so suppress errors if so
PACKAGE_INFO=`npm view ${PACKAGE_NAME}@${VERSION} 2> /dev/null`
if [ -z "$PACKAGE_INFO"]; then
echo "Package ${PACKAGE_NAME} not yet published. Okay to proceed."
elif [ "$PACKAGE_INFO" = "undefined" ]; then
echo "Package ${PACKAGE_NAME} not yet published at ${VERSION}. Okay to proceed."
else
echo "package ${PACKAGE_NAME} has already been published at ${VERSION}"
exit 1
fi
# Set the package.json version for the package
npm version $VERSION
echo "Publishing ${PACKAGE_NAME}@${VERSION} --tag ${TAG}"
npm publish --tag $TAG
cd $ORIG_DIRECTORY
done
echo "Publishing complete"