7af49cdc046dcfcb5f551f40d7f693c90446fb39
[aai/sparky-fe.git] / scripts / build / build.sh
1 #!/bin/bash
2
3 ###############################################################################
4 #
5 # UpdateFEwithExtensions
6 #
7 # Description:  Update files in the FE code based on the content of the
8 #               extensions.  For this to work, extensions are required to fill
9 #               some files.  The current script does not care too much about
10 #               their locations (other than being in the component
11 #               nodes-modules) but the file name must match.
12 #
13 ###############################################################################
14
15 UpdateFEwithExtensions(){
16
17   # Append statements to src/app/extensibility/index.js
18   echo "build.sh --- Appending to src/app/extensibility/index.js"
19   extImports=`find -name "extIndex"`
20   for i in $extImports; do
21     cat $i | grep import > tmp.imports
22     cat $i | grep 'components\[' > tmp.components
23
24     sed -i '/Import section/ r tmp.imports' src/app/extensibility/index.js
25     sed -i '/Components section/ r  tmp.components' src/app/extensibility/index.js
26   done
27
28   # Append Reducers to src/views/extensibility/ExtensibilityReducer.js
29   echo "build.sh --- Appending to src/app/extensibility/ExtensibilityReducer.js"
30   extRed=`find -name "extensibilityReducer"`
31   for i in $extRed; do
32     cat $i | grep import | grep -v '{combineReducers}' > tmp.imports.red
33     cat $i | grep ".*:.*," > tmp.exports.red
34
35     sed  -i '/import {combineReducers}/ r tmp.imports.red' src/app/extensibility/ExtensibilityReducer.js
36     sed  -i '/export default combineReducers/ r  tmp.exports.red' src/app/extensibility/ExtensibilityReducer.js
37   done
38
39   # Get extensible json additions
40   echo "build.sh --- Appending to resources/views/extensibleViews.json"
41   extConfig=`find node_modules/ -name "extensibleViews.json"`
42   if [ ! -z "$extConfig" ]; then
43     jq -n 'input | . +=[inputs]'  resources/views/extensibleViews.json $extConfig > tmp
44     mv tmp resources/views/extensibleViews.json
45   fi
46
47   # Append statements to src/app/overlays/OverlayImports.js
48   echo "build.sh --- Appending to src/app/overlays/OverlayImports.js"
49   extImports=`find -name "OverlayImport.js"`
50   for i in $extImports; do
51     cat $i | grep import > tmp.overlay.imports
52     cat $i | grep 'overlays\[' > tmp.overlays
53
54     sed -i '/Import section/ r tmp.overlay.imports' src/app/overlays/OverlayImports.js
55     sed -i '/Overlays section/ r  tmp.overlays' src/app/overlays/OverlayImports.js
56   done
57
58   # Get overlay json additions
59   echo "build.sh --- Appending to resources/overlays/overlaysDetails.json"
60   extConfig=`find node_modules/ -name "overlaysDetails.json"`
61   if [ ! -z "$extConfig" ]; then
62     jq -n 'input | . +=[inputs]'  resources/overlays/overlaysDetails.json $extConfig > tmp
63     mv tmp resources/overlays/overlaysDetails.json
64   fi
65
66   # Append scss statements
67   echo "build.sh --- Appending to resources/scss/customViews.scss"
68   touch resources/scss/customViews.scss
69   extSCSS=`find -name "extensibility.scss"`
70   for i in $extSCSS; do
71     cat $i >> resources/scss/customViews.scss
72   done
73
74
75 }
76
77 updateStyle()
78 {
79   echo "build.sh --- Updating style"
80
81   echo "build.sh --- adding fonts"
82   extFonts=`find extStyle/ -name "fonts"`
83   for i in $extFonts; do
84     cp -fr $i/* ./resources/fonts/
85   done
86
87   echo "build.sh --- adding scss"
88   extScss=`find extStyle/ -name "scss"`
89   for i in $extScss; do
90     cp -fr $i/* ./resources/scss/
91   done
92
93   # Append style import to src/app/main.app.jsx
94   echo "build.sh --- Append style import to src/app/main.app.jsx"
95   extImports=`find extStyle/ -name "main.app.jsx"`
96   for i in $extImports; do
97     cat $i | grep import > tmp.style.imports
98     sed -i '/Import Style Section/ r tmp.style.imports' src/app/main.app.jsx
99   done
100
101   if [ -f  tmp.style.imports ]; then
102       sed -i /"import 'resources\/scss\/style\.scss';"/d src/app/main.app.jsx
103   fi
104
105   # Update bootstrap
106   echo "build.sh --- Update resources/scss/bootstrap.scss"
107   bootImports=`find extStyle/ -name "bootstrap.scss"`
108   for i in $bootImports; do
109     cat $i | grep import > tmp.bootstrap.import
110     sed -i '/Import Typography Section/ r tmp.bootstrap.import' resources/scss/bootstrap.scss
111   done
112
113   if [ -f  tmp.bootstrap.import ]; then
114       sed -i /"@import \"common\/typography\";"/d resources/scss/bootstrap.scss
115   fi
116 }
117
118 UpdateFEWithCustomViews(){
119   # Append statements to src/app/configurableViews/index.js
120   echo "build.sh --- Appending to src/app/configurableViews/index.js"
121   custViewImports=`find -name "confViewIndex"`
122   for i in $custViewImports; do
123     cat $i | grep import > tmp.imports
124     cat $i | grep 'components\[' > tmp.components
125
126     sed -i '/Import section/ r tmp.imports' src/app/configurableViews/index.js
127     sed -i '/Components section/ r  tmp.components' src/app/configurableViews/index.js
128   done
129 }
130
131 ###############################################################################
132 #
133 # Main
134 #
135 ###############################################################################
136
137 extensionList=$@
138
139 # npm install
140 echo "build.sh --- Running npm install"
141 npm install
142
143 # npm install extensions
144 echo "build.sh --- parameter provided $extensionList"
145 if [ -z "$extensionList" ]; then
146   echo "build.sh --- No extension provided"
147 else
148   echo "build.sh --- Running npm --save ${extensionList}"
149   npm install --save ${extensionList}
150   # copy content when there are extensions
151   UpdateFEwithExtensions
152 fi
153
154 # Copy style
155 updateStyle
156
157 # npm run build
158 echo "build.sh --- Running npm run build"
159 npm run build