From: Mike Frysinger Date: Sun, 5 Jan 2020 06:45:37 +0000 (+0545) Subject: dist: improve manifest & min steps X-Git-Tag: v3.0~2 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=cbf343ff26dde4a002f876276aa6c9df45885322;p=chrome-ext%2Fweb-power-switch.git dist: improve manifest & min steps Use Python for all JSON manipulation. Tweak the min logic to look for all .min files rather than .js.min & .css.min. --- diff --git a/makedist.sh b/makedist.sh index 482baf8..bbc02a5 100755 --- a/makedist.sh +++ b/makedist.sh @@ -12,12 +12,19 @@ esac json_value() { local key=$1 - sed -n -r \ - -e '/^[[:space:]]*"'"${key}"'"/s|.*:[[:space:]]*"([^"]*)",?$|\1|p' \ - manifest.json + python -c ' +import json, os, sys +path, key = sys.argv[1:] +with open(path) as fp: + data = json.load(fp) +print(data[key]) +' "manifest.json" "${key}" } -PN=$(json_value name | sed 's:[[:space:]]:_:g' | tr '[:upper:]' '[:lower:]') +PN=$(json_value name | sed 's:[[:space:]/]:_:g' | tr '[:upper:]' '[:lower:]') +if [[ ${PN} == "__msg_name__" ]] ; then + PN=$(basename "$(pwd)") +fi PV=$(json_value version) rev=${1:-0} PVR="${PV}.${rev}" @@ -34,13 +41,20 @@ cp Makefile manifest.files manifest.json "${P}/" make -C "${P}" -j {css,js}-min while read line ; do - mv "${line}.min" "${line}" -done < <(find "${P}" -name '*.js' -o -name '*.css') + mv "${line}" "${line%.min}" +done < <(find "${P}" -name '*.min') rm "${P}"/{manifest.files,Makefile} -sed -i \ - -e '/"version"/s:"[^"]*",:"'${PVR}'",:' \ - "${P}/manifest.json" +python -c ' +import json, os, sys +path, ver = sys.argv[1:] +with open(path) as fp: + data = json.load(fp) +data.pop("key", None) +data["version"] = ver +with open(path, "w") as fp: + json.dump(data, fp, separators=(",", ":")) +' "${P}/manifest.json" "${PVR}" zip="${P}.zip" rm -f "${zip}"