From 50dc96cd0840b5f8ce8c267dafca409245218973 Mon Sep 17 00:00:00 2001 From: Emil Kosz Date: Wed, 21 Aug 2024 12:54:48 +0200 Subject: [PATCH] Basic script --- README.md | 7 ++++--- chopin.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100755 chopin.sh diff --git a/README.md b/README.md index e37b855..83bea54 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # Usage -To create a full development environment, go into your project -directory and run: ```./chopin.sh [PROJECT_NAME]```. The rest will be -taken of by the tool. +Go into your project directory, copy `chopin.sh` there. If you want to +pack the application, use `./chopin.sh -p`. It will automatically get +a name from manifest.toml if it exists. Use `./chopin.sh -g` to create +a pre-commit hook. # Features ## Optimizing WebXDC packing script The packing script generated by `chopin.sh` optimizes every part of diff --git a/chopin.sh b/chopin.sh new file mode 100755 index 0000000..a0fba73 --- /dev/null +++ b/chopin.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env sh + +name="Application" +EXCLUDE_FILES="webxdc.js *.sh *.xdc *~" + +function usage () { + echo "Usage: ${0} [-hgp]" + echo " -h Display this message" + echo " -g Add pre-commit hook which formats and lints code" + echo " -p Optimize all files and pack the project as a WebXDC" + exit -1 +} + +function add_pre_commit_hook () { + : +} + +# $1 - filename +function extract_toml () { + while IFS='= ' read -r lhs rhs; do + if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then + rhs="${rhs%%\#*}" + rhs="${rhs%%*( )}" + rhs="${rhs%\"*}" + rhs="${rhs#\"*}" + declare -g $lhs="$rhs" + fi + done < $1 +} + +function webxdc_create () { + echo "Creating WebXDC package." + echo "Removing all existing XDC packages." + rm -f *.xdc + + echo "Extracting name from manifest.toml." + [[ -f ./manifest.toml ]] && extract_toml manifest.toml + + echo "Packing project into an XDC package." + zip -9 --recurse-paths "${name}.xdc" --exclude $EXCLUDE_FILES -- * > /dev/null +} + +[[ "$#" -eq 0 ]] && usage +while getopts ":hgp" option; do + case ${option} in + h) + usage + ;; + g) + add_pre_commit_hook + ;; + p) + webxdc_create + ;; + \?) + echo "Invalid option -${OPTARG}" + usage + ;; + esac +done