summaryrefslogtreecommitdiffstats
path: root/scripts/build/build.sh
blob: 9fd9fd2c08611d5989f28b7eac99424852090044 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash

###############################################################################
#
# UpdateFEwithExtensions
#
# Description:  Update files in the FE code based on the content of the 
#               extensions.  For this to work, extensions are required to fill 
#               some files.  The current script does not care too much about
#               their locations (other than being in the component 
#               nodes-modules) but the file name must match.
#
###############################################################################

UpdateFEwithExtensions(){

  # Append statements to src/app/extensibility/index.js
  echo "build.sh --- Appending to src/app/extensibility/index.js"
  extImports=`find -name "extIndex"`
  for i in $extImports; do
    cat $i | grep import > tmp.imports
    cat $i | grep 'components\[' > tmp.components

    sed -i '/Import section/ r tmp.imports' src/app/extensibility/index.js
    sed -i '/Components section/ r  tmp.components' src/app/extensibility/index.js
  done

  # Append Reducers to src/views/extensibility/ExtensibilityReducer.js
  echo "build.sh --- Appending to src/app/extensibility/ExtensibilityReducer.js"
  extRed=`find -name "extensibilityReducer"`
  for i in $extRed; do
    cat $i | grep import | grep -v '{combineReducers}' > tmp.imports.red
    cat $i | grep ".*:.*," > tmp.exports.red

    sed  -i '/import {combineReducers}/ r tmp.imports.red' src/app/extensibility/ExtensibilityReducer.js
    sed  -i '/export default combineReducers/ r  tmp.exports.red' src/app/extensibility/ExtensibilityReducer.js
  done

  # Get extensible json additions
  echo "build.sh --- Appending to resources/views/extensibleViews.json"
  extConfig=`find node_modules/ -name "extensibleViews.json"`
  if [ ! -z "$extConfig" ]; then 
    jq -n 'input | . +=[inputs]'  resources/views/extensibleViews.json $extConfig > tmp
    mv tmp resources/views/extensibleViews.json
  fi

  # Append statements to src/app/overlays/OverlayImports.js
  echo "build.sh --- Appending to src/app/overlays/OverlayImports.js"
  extImports=`find -name "OverlayImport.js"`
  for i in $extImports; do
    cat $i | grep import > tmp.overlay.imports
    cat $i | grep 'overlays\[' > tmp.overlays

    sed -i '/Import section/ r tmp.overlay.imports' src/app/overlays/OverlayImports.js
    sed -i '/Overlays section/ r  tmp.overlays' src/app/overlays/OverlayImports.js
  done

  # Get overlay json additions
  echo "build.sh --- Appending to resources/overlays/overlaysDetails.json"
  extConfig=`find node_modules/ -name "overlaysDetails.json"`
  if [ ! -z "$extConfig" ]; then 
    jq -n 'input | . +=[inputs]'  resources/overlays/overlaysDetails.json $extConfig > tmp
    mv tmp resources/overlays/overlaysDetails.json
  fi

  # Append scss statements
  echo "build.sh --- Appending to resources/scss/customViews.scss"
  touch resources/scss/customViews.scss
  extSCSS=`find -name "extensibility.scss"`
  for i in $extSCSS; do 
    cat $i >> resources/scss/customViews.scss
  done
  
  
}

updateStyle()
{
  echo "build.sh --- Updating style"

  echo "build.sh --- adding fonts"
  extFonts=`find extStyle/ -name "fonts"`
  for i in $extFonts; do
    cp -fr $i/* ./resources/fonts/
  done

  echo "build.sh --- adding scss"
  extScss=`find extStyle/ -name "scss"`
  for i in $extScss; do
    cp -fr $i/* ./resources/scss/
  done

  # Append style import to src/app/main.app.jsx
  echo "build.sh --- Append style import to src/app/main.app.jsx"
  extImports=`find extStyle/ -name "main.app.jsx"`
  for i in $extImports; do
    cat $i | grep import > tmp.style.imports
    sed -i '/Import Style Section/ r tmp.style.imports' src/app/main.app.jsx
  done

  if [ -f  tmp.style.imports ]; then
      sed -i /"import 'resources\/scss\/style\.scss';"/d src/app/main.app.jsx
  fi
  
  # Update bootstrap 
  echo "build.sh --- Update resources/scss/bootstrap.scss"
  bootImports=`find extStyle/ -name "bootstrap.scss"`
  for i in $bootImports; do
    cat $i | grep import > tmp.bootstrap.import
    sed -i '/Import Typography Section/ r tmp.bootstrap.import' resources/scss/bootstrap.scss
  done

  if [ -f  tmp.bootstrap.import ]; then
      sed -i /"@import \"common\/typography\";"/d resources/scss/bootstrap.scss
  fi
}

###############################################################################
#
# Main
#
###############################################################################

extensionList=$@

# npm install
echo "build.sh --- Running npm install"
npm install

# npm install extensions
echo "build.sh --- parameter provided $extensionList"
if [ -z "$extensionList" ]; then
  echo "build.sh --- No extension provided"
else
  echo "build.sh --- Running npm --save ${extensionList}"
  npm install --save ${extensionList}
  # copy content when there are extensions
  UpdateFEwithExtensions
fi

# Copy style
updateStyle

# npm run build
echo "build.sh --- Running npm run build"
npm run build