-
Notifications
You must be signed in to change notification settings - Fork 245
Open
Description
Hi,
At this time, I use a build script to generate a one sourced file for the all framework features with the following code.
You can build latest release (with no args), right now 2.1 but also the master one (just master when calling).
It could be improved to base the including source from the package.json (with command cat package.json| grep lib | sed 's/^ *"lib\///; s/",\?$//g'when defining the input_files array variable, but the order mismatch in the json file.
Here is the code (which can be used for your ./build/build.sh):
#!/usr/bin/env bash
# Note: Order in package.json does not work
set -e
latest() {
local repo="$1"
curl --silent \
"https://api.github.com/repos/$repo/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
download() {
local repo="$1"
local release="$2"
local project="$(cut -d '/' -f2 <<<"$repo")"
rm -rf /tmp/${project}-*
if [ "$release" = "master" ]; then
curl -sL --output /tmp/$project.zip \
https://github.com/$repo/archive/refs/heads/master.zip
unzip -qq /tmp/$project.zip -d /tmp
rm /tmp/$project.zip
else
curl -sL --output /tmp/$project.tar.gz \
https://github.com/$repo/archive/refs/tags/$release.tar.gz
tar -C /tmp -xvf /tmp/$project.tar.gz
rm /tmp/$project.tar.gz
fi
echo "/tmp/${project}-${release}"
}
build() {
local oo_framework_file="$1"
local oo_framework_release="$2"
local oo_framework_repo="niieani/bash-oo-framework"
local oo_framework_tmp_dir
[ -z "$oo_framework_release" ] \
&& oo_framework_release="$(latest "$oo_framework_repo")"
local -a input_files=(
oo-bootstrap
util/log
Array/Contains
util/namedParameters
util/variable
util/command
util/class
util/type
util/bash4
String/SanitizeForVariable
util/pipe
TypePrimitives/array
TypePrimitives/boolean
TypePrimitives/integer
TypePrimitives/map
TypePrimitives/string
Array/Intersect
Array/List
Array/Reverse
String/GetSpaces
String/IsNumber
String/SlashReplacement
String/UUID
util/exception
util/tryCatch
UI/Color
UI/Console
UI/Cursor
util/test
)
oo_framework_tmp_dir="$(download "$oo_framework_repo" "$oo_framework_release")"
# prefix '\$__oo__libPath' for __oo__importedFiles
__oo__importedFiles=("${input_files[@]/#/\$__oo__libPath/}")
# suffix '.sh' foreach items
# prefix '$oo_framework_tmp_dir' for catfiles
input_files=("${input_files[@]/%/.sh}")
input_files=("${input_files[@]/#/$oo_framework_tmp_dir\/lib/}")
# Min runtime
echo '#!/usr/bin/env bash
# oo-framework version: '"$oo_framework_release"'
# generated at: '$( date )'
# on not declared variables, let script uses "alias" internaly
shopt -s expand_aliases
' | sed -e 's/^\( \)\{8\}//' > "$oo_framework_file"
cat "${input_files[@]}" | \
sed -e '/^System::Bootstrap$/d;/^#!\/.*$/d;/^import .*$/d;' \
-e 's/^System::Bootstrap(/System::Bootstrap2(/' \
-e 's/^System::SourceFile(/System::SourceFile2(/' >> "$oo_framework_file"
echo '# ---- patch
__oo__importedFiles=('"${__oo__importedFiles[@]}"')
System::SourceFile() {
[[ ${__oo__importedFiles[@]} =~ $1 ]] || \
System::SourceFile2 "$1"
}
System::ClassPath() {
__oo__path="$1"
}
System::Bootstrap() {
which tput >/dev/null || {
echo "oo-bootstrap require tput. Please install first ..."
exit 1
}
System::Bootstrap2
}
System::Bootstrap
# ---- end' | sed -e 's/^\( \)\{8\}//' >> "$oo_framework_file"
rm -rf "$oo_framework_tmp_dir"
}
build ./oo-framework.sh "$@"
Metadata
Metadata
Assignees
Labels
No labels