Skip to content

Commit

Permalink
fix(build): issues/105 local run chroming update
Browse files Browse the repository at this point in the history
* build, branch checkout to chrome repo clone, expand messaging
* build, use NPM instead of yarn to build chrome to avoid errors
* readme requirements updated to include NPM
  • Loading branch information
cdcabrera committed Oct 14, 2019
1 parent ac5cb8e commit 150065f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A web user interface for subscription reporting, based on [Patternfly <img src="

## Requirements
Before developing for Curiosity Frontend, the basic requirements:
* Your system needs to be running [NodeJS version 10+](https://nodejs.org/)
* Your system needs to be running [NodeJS version 10+ and NPM](https://nodejs.org/)
* [Docker](https://docs.docker.com/engine/installation/)
* And [Yarn 1.16+](https://yarnpkg.com) for dependency and script management.

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@
"build:js": "react-scripts build",
"build:post": "bash ./scripts/post.sh",
"build:pre": "bash ./scripts/pre.sh",
"dev:chrome": "sh ./scripts/dev.chrome.sh",
"release": "standard-version",
"start": "sh ./scripts/dev.chrome.sh; run-p -l api:dev start:js",
"start": "run-s dev:chrome; run-p -l api:dev start:js",
"start:js": "react-scripts start",
"start:proxy": "sh -ac '. ./.env.proxy; open https://ci.foo.redhat.com:1337/beta/staging/subscriptions/; run-s api:proxy-hosts; run-p -l start:js api:proxy'",
"start:standalone": "rm ./.env.development.local; run-p -l api:dev start:js",
Expand Down
69 changes: 53 additions & 16 deletions scripts/dev.chrome.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,33 @@ gitRepo()
local GITREPO=$1
local DIR=$2
local DIR_REPO=$3
local GITBRANCH=$4
local CURRENT_DATE=$(date "+%s")
local EXPIRE=$(head -n 1 $DIR/expire.txt)

if [ ! -d $DIR_REPO/build ] || [ "${EXPIRE:-0}" -lt "${CURRENT_DATE}" ]; then
mkdir -p $DIR
rm -rf $DIR/temp
(cd $DIR && git clone --depth=1 $GITREPO temp > /dev/null 2>&1)

printf "\n${YELLOW}Accessing ${GITREPO}${NOCOLOR}\n"

if [ -z "$GITBRANCH" ]; then
(cd $DIR && git clone --depth=1 $GITREPO temp > /dev/null 2>&1)
else
(cd $DIR && git clone $GITREPO temp > /dev/null 2>&1)

printf "${YELLOW}Attempting to access branch \"${BRANCH}\" ...${NOCOLOR}"

if [ ! -z "$(cd $DIR/temp && git branch -a | grep $GITBRANCH)" ]; then
(cd $DIR/temp && git checkout $GITBRANCH > /dev/null 2>&1)
printf "${GREEN}SUCCESS${NOCOLOR}\n"
else
printf "${YELLOW}non-existant ...IGNORE, use default${NOCOLOR}\n"
fi
fi

if [ $? -eq 0 ]; then
printf "\n${GREEN}Checking ${GITREPO} ...${NOCOLOR}"
printf "${YELLOW}Confirm repository ...${NOCOLOR}"

rm -rf $DIR_REPO
cp -R $DIR/temp $DIR_REPO
Expand All @@ -27,7 +44,7 @@ gitRepo()

echo $(date -v +10d "+%s") > $DIR/expire.txt

printf "${GREEN}Clone SUCCESS${NOCOLOR}\n"
printf "${GREEN}SUCCESS${NOCOLOR}\n"

elif [ -d $DIR_REPO ]; then
printf "${YELLOW}Unable to connect, using cached ${GITREPO}...${NOCOLOR}\n"
Expand All @@ -52,35 +69,42 @@ cleanLocalDotEnv()
#
buildChrome()
{
local DIR_REPO=$1
local DIR_PUBLIC=$2
local SNIPPET_HEAD=$3
local SNIPPET_BODY=$4
local GITREPO=$1
local DIR_REPO=$2
local DIR_PUBLIC=$3
local SNIPPET_HEAD=$4
local SNIPPET_BODY=$5

if [ ! -d $DIR_REPO/build ]; then
printf "\n${GREEN}Building Chrome...${NOCOLOR}"

if [ -z "$(node -v)" ] || [ -z "$(yarn -v)" ]; then
printf "${YELLOW}Node and Yarn need to be installed in order to local run.${NOCOLOR}\n"
if [ -z "$(node -v)" ] || [ -z "$(npm -v)" ]; then
printf "${YELLOW}Node and NPM need to be installed in order to local run.${NOCOLOR}\n"
exit 0
fi

(cd $DIR_REPO && yarn && yarn build > /dev/null 2>&1)
(cd $DIR_REPO && npm install && npm run build > /dev/null 2>&1)
printf "\n${GREEN}Build SUCCESS${NOCOLOR}"
fi

printf "\n${GREEN}Setting up local chrome... ${NOCOLOR}"
printf "\n${YELLOW}Setting up local chrome ...${NOCOLOR}"

mkdir -p $DIR_PUBLIC
cp -R $DIR_REPO/build/ $DIR_PUBLIC

printf "${GREEN}dotenv includes... ${NOCOLOR}"
printf "${YELLOW}dotenv includes ...${NOCOLOR}"

HEADER_CONTENT=$(node -pe "require('fs').readFileSync('${SNIPPET_HEAD}').toString().replace(/\n/g, '').concat('<style>.pf-c-page__sidebar .ins-c-skeleton{display:none}</style>')")
BODY_CONTENT=$(node -pe "require('fs').readFileSync('${SNIPPET_BODY}').toString().replace(/\n/g,'').replace(/Logging in\.\.\./i, 'Development')")

echo "\nREACT_APP_INCLUDE_CONTENT_HEADER=${HEADER_CONTENT}\nREACT_APP_INCLUDE_CONTENT_BODY=${BODY_CONTENT}\n" > ./.env.development.local
printf "${GREEN}SUCCESS${NOCOLOR}\n"
if [[ ! -z "$HEADER_CONTENT" ]] && [[ ! -z "$BODY_CONTENT" ]]; then
echo "\nREACT_APP_INCLUDE_CONTENT_HEADER=${HEADER_CONTENT}\nREACT_APP_INCLUDE_CONTENT_BODY=${BODY_CONTENT}\n" > ./.env.development.local
printf "${GREEN}SUCCESS${NOCOLOR}\n"
else
printf "\n${RED}ERROR, include content doesn't exist${NOCOLOR}\n"
printf "${RED} This is most likely due to an alteration on the includes repository.${NOCOLOR}\n"
printf "${RED} You'll need to confirm the repository can still be accessed\n ${GITREPO}${NOCOLOR}\n\n"
fi
}
#
#
Expand All @@ -96,11 +120,24 @@ buildChrome()
REPO="https://github.com/RedHatInsights/insights-chrome.git"
DATADIR=./.chrome
DATADIR_REPO=./.chrome/insights-chrome
BRANCH="prod-stable"
PUBLICDIR=./public/apps/chrome
HEAD=./public/apps/chrome/snippets/head.html
BODY=./public/apps/chrome/snippets/body.html

gitRepo $REPO $DATADIR $DATADIR_REPO
while getopts u option;
do
case $option in
u ) UPDATE=true;;
esac
done

if [ "$UPDATE" = true ]; then
printf "${YELLOW}Updating chrome...${NOCOLOR}\n"
rm -rf $DATADIR
fi

gitRepo $REPO $DATADIR $DATADIR_REPO $BRANCH
cleanLocalDotEnv
buildChrome $DATADIR_REPO $PUBLICDIR $HEAD $BODY
buildChrome $REPO $DATADIR_REPO $PUBLICDIR $HEAD $BODY
}

0 comments on commit 150065f

Please sign in to comment.