3 # ============LICENSE_START=======================================================
5 # ================================================================================
6 # Copyright (C) 2020 AT&T Intellectual Property. All rights
8 # ================================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END============================================
21 # ===================================================================
25 baseDir=$(git rev-parse --show-toplevel)
27 if [[ ! -d $baseDir ]]
29 echo "[ERROR] failed to determine git base directory"
33 tmpSrcFileList=/tmp/upldateLibIndex.$$.list
34 reactUiBaseDir="${baseDir}/ui-react"
35 reactLibIndexFile="ui-react-lib/libIndex.js"
36 exclusionList="ui-react-lib/libExportExclusions.dat"
39 if [[ ! -d "$reactUiBaseDir" ]]
41 echo "[ERROR] reacUiBaseDir=$reacUiBaseDir is not accessible"
45 if [[ ! -d "$baseDir/$reactLibBaseDir" ]]
47 echo "[ERROR] reactLibBaseDir=$baseDir/$reactLibBaseDir is not accessible"
51 if [[ ! -r "$baseDir/$reactLibIndexFile" ]]
53 echo "[ERROR] file reactLibIndexFile=$baseDir/$reactLibIndexFile is not accessible"
58 if ! cd $reactUiBaseDir
60 echo "[ERROR] could not cd to reactUiBaseDir=$reactUiBaseDir"
64 find ./src -name \*.js | egrep -v "__snapshot|\.test\." 2>/dev/null | sed 's/.js$//' > $tmpSrcFileList
66 if [[ ! -s $tmpSrcFileList ]]
68 echo "[ERROR] no source files found in reactUiBaseDir=$reactUiBaseDir"
75 # Verify that any .js file found within ui-react/src other than test related files
76 # is also referenced in ui-react-lib/libIndex.js
78 for srcFileName in `<$tmpSrcFileList`
80 if [[ -r "$baseDir/$exclusionList" ]]
82 if grep $srcFileName $baseDir/$exclusionList >/dev/null 2>&1
88 if ! grep $srcFileName "$baseDir/$reactLibIndexFile" > /dev/null 2>&1
90 echo "[ERROR] file=${srcFileName}.js is not declared in $reactLibIndexFile"
91 echo "[ERROR] and not found in exclsionList=${exclusionList}."
92 echo "[ERROR] Please either add it to $reactLibIndexFile"
93 echo "[ERROR] or to the exclusion list in ${exclusionList}."
99 # Verify for each entry in ui-react-lib/libIndex.js, that the referenced source file exists
100 # in ui-react/src; if not, developer probably forgot to remove it from libIndex.js.
102 egrep '^export ' $baseDir/$reactLibIndexFile |\
103 sed -e "s+.*\./src+./src+" -e "s+'.*+.js+" > $tmpSrcFileList
105 for srcFileName in `<$tmpSrcFileList`
107 if [[ ! -r "$srcFileName" ]]
109 echo "[ERROR] source file=$srcFileName in libIndex.js is not accessible"
114 rm -f $tmpSrcFileList
116 if (( nErrors == 0 ))
118 echo "[INFO] $reactLibIndexFile passes sanity check"