-
Notifications
You must be signed in to change notification settings - Fork 5
/
publish-component.sh
executable file
·62 lines (52 loc) · 2.04 KB
/
publish-component.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
#!/usr/bin/env bash
### License MIT
### 2017 AdTechMedia.io (c)
### Author: AlexanderC <[email protected]>
function fail () {
echo >&2 "[FAILED] $1!"
exit 1
}
function require_clean_work_tree () {
# Update the index
git update-index -q --ignore-submodules --refresh
err=0
# Disallow unstaged changes in the working tree
if ! git diff-files --quiet --ignore-submodules --
then
echo >&2 "You have unstaged changes."
git diff-files --name-status -r --ignore-submodules -- >&2
err=1
fi
# Disallow uncommitted changes in the index
if ! git diff-index --cached --quiet HEAD --ignore-submodules --
then
echo >&2 "Your index contains uncommitted changes."
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
err=1
fi
if [ $err = 1 ]
then
fail "Pre-checking git status"
fi
}
function validate_input () {
if [ -z "$1" ]
then
fail "Please provide a valid semver function (https://github.com/npm/node-semver#functions)"
fi
if [ -z "$2" ]
then
fail "Please provide a component name"
fi
}
validate_input "$@"
require_clean_work_tree
cd "components/$2" || fail "No such component $2 found"
rm -rf node_modules || fail "Cleaning up recink-$2 node_modules"
npm install --no-shrinkwrap || fail "Installing recink-$2 dependencies"
npm version "$1" --no-git-tag-version || fail "Updating $1 version of recink-$2 package"
npm publish || fail "Publishing recink-$2 package on npmjs.com"
cd ../../
(git diff-files --quiet --ignore-submodules -- || (git add . && git commit -a -m"Publish recink-$2 package on npmjs.com"))
git push
echo '[OK] Done.'