-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.sh
64 lines (51 loc) · 1.83 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
#!/bin/sh
DIRECTORY="assets"
BRANCH="dist/frontend"
CURRENT_BRANCH=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
# Check if the environment is ready for publishing ===========================
if [ "$CURRENT_BRANCH" != "master" ]
then
echo "⚠️ Please run this script from master branch"
exit 1;
fi
if [[ $(git status -s) ]]
then
echo "⚠️ The working directory is dirty. Please commit any pending changes."
exit 1;
fi
if [ $2 ]
then
npm whoami || { echo "⚠️ You must be logged in to NPM to push a new release" ; exit 1; }
fi
jq --version || { echo "⚠️ You have jq installed on your machine (brew install jq)" ; exit 1; }
# Proceed =====================================================================
echo "rebuild frontend assets"
yarn build
echo "update package.json version to $1 and write a copy for publishing"
npm version $1
cp package.json $DIRECTORY/package.json
jq -e ".dependencies = {} | .devDependencies = {}" $DIRECTORY/package.json > $DIRECTORY/package.json.tmp && cp $DIRECTORY/package.json.tmp $DIRECTORY/package.json && rm $DIRECTORY/package.json.tmp
echo "backup dist content"
mkdir "$DIRECTORY-tmp"
cp -r $DIRECTORY/* "$DIRECTORY-tmp/"
echo "Deleting dist"
rm -rf $DIRECTORY
mkdir $DIRECTORY
git worktree prune
rm -rf .git/worktrees/$DIRECTORY/
echo "Checking out $BRANCH branch into dist"
git worktree add -B $BRANCH $DIRECTORY
echo "Removing existing files"
rm -rf $DIRECTORY/*
echo "Generating dist using the backup"
cp -r "$DIRECTORY-tmp"/* $DIRECTORY/
rm -rf "$DIRECTORY-tmp"
echo "Updating $BRANCH branch"
if [ $2 ]
then
cd $DIRECTORY && git add --all && git commit -m "Publishing to $BRANCH (publish.sh)"
git push --force origin $BRANCH --tags && npm publish
else
cd $DIRECTORY && git add --all && git commit -m "Publishing to $BRANCH (publish.sh)"
git push --force origin $BRANCH --tags
fi