-
Notifications
You must be signed in to change notification settings - Fork 1
/
do-npm.sh
65 lines (55 loc) · 2.06 KB
/
do-npm.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
#!/bin/bash
# -----------------------------------------------------------------------------
# Internal function, validates whether we have all prerequisites.
# -----------------------------------------------------------------------------
function VALIDATE_NPM
{
if [ ! -f "package.json" ]; then
FAILURE "Look's like that repository doesn't contain 'package.json' file."
fi
}
# -----------------------------------------------------------------------------
# Deploys node package using npm. Script is executed in ${REPO_DIR}
# Parameters:
# $1 - version
# $2 - deploy command (push | prepare)
#
# Expected global variables
# DEPLOY_NPM_BEFORE_PREPARE - optional script run before npm publish --dry-run
# DEPLOY_NPM_BEFORE_PUBLISH - optional script run before npm publish
# -----------------------------------------------------------------------------
function DO_DEPLOY
{
local VER=$1
local DEPLOY_COMMAND=$2
local VERBOSE_SWITCH=""
if [ x$VERBOSE == x2 ]; then
VERBOSE_SWITCH="--verbose"
fi
if [ x$ALLOW_WARNINGS == x1 ]; then
VERBOSE_SWITCH="${VERBOSE_SWITCH} --allow-warnings"
fi
# validate variables and input parameters
VALIDATE_NPM
if [ "$DEPLOY_COMMAND" == "prepare" ]; then
LOG "----- Validating..."
[[ ! -z "${DEPLOY_NPM_BEFORE_PREPARE}" ]] && npm run $DEPLOY_NPM_BEFORE_PREPARE
npm publish --dry-run
elif [ "$DEPLOY_COMMAND" == "deploy" ]; then
LOG "----- Publishing..."
[[ ! -z "${DEPLOY_NPM_BEFORE_PUBLISH}" ]] && npm run $DEPLOY_NPM_BEFORE_PUBLISH
npm publish
else
FAILURE "do-npm.sh doesn't support '$DEPLOY_COMMAND' command"
fi
}
# -----------------------------------------------------------------------------
# Prepares tag message for library. Script is executed in ${REPO_DIR}
# Parameters:
# $1 - version
# -----------------------------------------------------------------------------
function DO_PREPARE_TAG_MESSAGE
{
VALIDATE_NPM
DEPLOY_TAG_MESSAGE="Version $1"
}