Skip to content

Commit

Permalink
Merge pull request #82 from entando/ENG-702_static-resources-not-copi…
Browse files Browse the repository at this point in the history
…ed-in-final-bundle

Eng 702 static resources not copied in final bundle
  • Loading branch information
Kerruba authored Jun 26, 2020
2 parents aebbc0b + ebaab67 commit 5a05af6
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%# { "useBluePrint": true } -%>
REACT_APP_SERVICE_URL=http://localhost:<%= serverPort %>/services/<%= baseName %>/api
REACT_APP_KEYCLOAK_URL=http://localhost:9080/auth
REACT_APP_KEYCLOAK_REALM=jhipster
REACT_APP_KEYCLOAK_CLIENT_ID=web_app
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%# { "useBluePrint": true } -%>
REACT_APP_SERVICE_URL=http://localhost:<%= serverPort %>/services/<%= baseName %>/api
REACT_APP_KEYCLOAK_URL=http://localhost:9080/auth
REACT_APP_KEYCLOAK_REALM=jhipster
REACT_APP_KEYCLOAK_CLIENT_ID=web_app
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%# { "useBluePrint": true } -%>
REACT_APP_SERVICE_URL=http://localhost:<%= serverPort %>/services/<%= baseName %>/api
REACT_APP_KEYCLOAK_URL=http://localhost:9080/auth
REACT_APP_KEYCLOAK_REALM=jhipster
REACT_APP_KEYCLOAK_CLIENT_ID=web_app
2 changes: 2 additions & 0 deletions generators/server/phases/prompting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ function askForBundleName(meta) {
];
this.prompt(prompts).then(prompt => {
this.bundleName = prompt.bundleName;
this.config.set("bundleName", this.bundleName)
done();
});
}
Expand All @@ -471,6 +472,7 @@ function askForDockerOrganization(meta) {
];
this.prompt(prompts).then(prompt => {
this.dockerImageOrganization = prompt.dockerImageOrganization;
this.config.set("dockerOrganization", this.dockerImageOrganization)
done();
});
}
Expand Down
1 change: 1 addition & 0 deletions generators/server/phases/writing/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const serverFiles = {
templates: [
{ file: 'prepareMicrofrontends.sh', method: 'copy', noEjs: true },
{ file: 'prepareBundle.sh', method: 'copy', noEjs: true },
{ file: 'prepareDockerImage.sh', method: 'copy', noEjs: true },
{ file: 'buildBundle.sh', method: 'copy', noEjs: true },
],
},
Expand Down
22 changes: 20 additions & 2 deletions generators/server/templates/buildBundle.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
#!/bin/bash
set -e

while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
-d | --docker )
docker="true";
;;
esac; shift; done
if [[ "$1" == '--' ]]; then shift; fi

BUNDLE_NAME=$(awk -F':' 'NR==1 {gsub(/ /, "", $2); print $2}' ./bundle/descriptor.yaml)
STEP=1

echo "Generation of the $BUNDLE_NAME bundle"
echo "====================================="
echo ""

echo "Step 1. Preparing micro-frontends for inclusion in the bundle"

if [[ -n "$docker" ]]; then
echo "Step $STEP. Preparing docker image"
./prepareDockerImage.sh
echo "---"
STEP=$((STEP+1))
fi

echo "Step $STEP. Preparing micro-frontends for inclusion in the bundle"
./prepareMicrofrontends.sh
echo "---"
echo "Step 2. Including micro-frontends metadata and resources in the bundle package"
STEP=$((STEP+1))
echo "Step $STEP. Including micro-frontends metadata and resources in the bundle package"
./prepareBundle.sh
echo "---"
echo "All done! Bundle available in the $(pwd)/bundle folder"
Expand Down
1 change: 1 addition & 0 deletions generators/server/templates/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
},
"scripts": {
"populate-bundle": "./buildBundle.sh",
"build-all": "./buildBundle.sh -d",
"keycloak": "docker-compose -f src/main/docker/keycloak.yml up"
}
}
29 changes: 26 additions & 3 deletions generators/server/templates/prepareBundle.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
#!/bin/bash
function syncResources() {
local widgetFolder="$1"

echo "> Processing widgets $(echo $widgetFolder | cut -d/ -f3-)"

echo "- Preparing target folder structure"
mkdir -p bundle{,"/$widgetFolder"}/resources

echo "- Copying bundle descriptor"
rsync -a "$widgetFolder"/bundle/ bundle/"$widgetFolder"
if [ -d "$widgetFolder/build/static" ]; then
echo "- Copying bundle static resource"
rsync -a "$widgetFolder/build/static" bundle/resources 2>/dev/null
rsync -a "$widgetFolder/build/static" "bundle/$widgetFolder/resources" 2>/dev/null
else
echo " > no build/static folder found for $widgetFolder"
fi
}

function createFolderTree() {
local widgetFolder="$1"

Expand Down Expand Up @@ -32,7 +51,7 @@ function injectResource() {
local _NL=$'\\\n'

echo "- Injecting resource $resource in $destFile"
sed -i'.bak' 's|'"$INJECTION_POINT"'|'"$resource$_NL$INJECTION_POINT"'|g' "$destFile"
sed -i'' 's|'"$INJECTION_POINT"'|'"$resource$_NL$INJECTION_POINT"'|g' "$destFile"
}

function updateFTLTemplate() {
Expand All @@ -41,6 +60,7 @@ function updateFTLTemplate() {
local bundleCode="$2"

widgetName=$(basename "$dir")
echo ""
echo "> Updating ${widgetName} micro-frontend resources for $dir"

for ftlName in "$dir"/*.ftl;
Expand Down Expand Up @@ -72,14 +92,17 @@ function updateFTLTemplate() {
done

#Cleanup the resources that were copied into the widget folders specifically. They are now copied into the main bundle folder
rm -rf "$dir/resources"
echo ""
echo "> Cleaning temporary resource folders"
rm -rvf "$dir/resources"
shopt -u nullglob

}

export -f createFolderTree
export -f injectResource
export -f updateFTLTemplate
export -f syncResources
export INJECTION_POINT="<#-- entando_resource_injection_point -->"

BUNDLE_NAME=$(awk -F':' 'NR==1 {gsub(/ /, "", $2); print $2}' ./bundle/descriptor.yaml)
Expand All @@ -95,7 +118,7 @@ if [ $HAS_WIDGETS -eq 0 ]; then
echo "---"
echo "Generating the bundle folder tree for the micro-frontends"
echo ""
find "$WIDGET_FOLDER" -maxdepth 2 -mindepth 2 -type d -not -path "*utils*" -exec bash -c 'createFolderTree "$@"' bash {} \;
find "$WIDGET_FOLDER" -maxdepth 2 -mindepth 2 -type d -not -path "*utils*" -exec bash -c 'syncResources "$@"' bash {} \;
mkdir -p bundle/resources/static/{js,css}
echo ""

Expand Down
17 changes: 17 additions & 0 deletions generators/server/templates/prepareDockerImage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

echo ""
echo "Building project and Docker image "
export MY_IMAGE=$(./mvnw -Pprod clean package jib:dockerBuild | while read i
do
if [[ "$i" == *"Built image to Docker daemon"* ]]; then
echo "$i" | awk '{print $NF}'
fi
done
)
echo "Built $MY_IMAGE"

echo ""
echo "Uploading $MY_IMAGE to dockerhub"
docker push $MY_IMAGE
6 changes: 3 additions & 3 deletions generators/server/templates/prepareMicrofrontends.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ERROR_OUTPUT="./.bundle_build/errors"
PIDS=()

function getMicrofrontendsNumber() {
find "$WIDGET_FOLDER" -type d -name bundle | wc -l
find "$WIDGET_FOLDER" -mindepth 3 -maxdepth 3 -type d -name bundle | wc -l
}

function processWidget() {
Expand All @@ -22,7 +22,7 @@ function processWidget() {
echo "Installing micro-frontend dependencies"
npm install || return $?
echo "Building micro-frontend code"
npm run build | while read i
npm run build --production | while read i
do
if [[ "$i" == *"Failed to compile"* ]]; then
echo "$i" 1>&2
Expand Down Expand Up @@ -52,7 +52,7 @@ else
rm -fr "$ERROR_OUTPUT" && mkdir -p "$ERROR_OUTPUT"

# Get all entities
ALL_MFE_PATHS=$(find "$WIDGET_FOLDER" -type d -name bundle)
ALL_MFE_PATHS=$(find "$WIDGET_FOLDER" -mindepth 3 -maxdepth 3 -type d -name bundle)
ENTITIES=$(echo "$ALL_MFE_PATHS" | awk -F'/' '{print $3}' | sort -u)

for ENTITY in $ENTITIES; do
Expand Down

0 comments on commit 5a05af6

Please sign in to comment.