Skip to content

Instantly share code, notes, and snippets.

@DinoChiesa
Created August 31, 2017 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DinoChiesa/0cdf4d7a83ecc14fcadc7a050c662d43 to your computer and use it in GitHub Desktop.
Save DinoChiesa/0cdf4d7a83ecc14fcadc7a050c662d43 to your computer and use it in GitHub Desktop.
Produce a zip for an API Proxy bundle
$ ./ProduceApiProxyZip.sh ~/dev/community-examples/crypto-test
Creating the zip at apiproxy-crypto-test-20170831-164831.zip
zipping the node modules...
Archive: apiproxy-crypto-test-20170831-164831.zip
Length Date Time Name
--------- ---------- ----- ----
0 04-26-2017 11:11 apiproxy/
437 04-26-2017 11:11 apiproxy/crypto-test.xml
0 04-26-2017 11:24 apiproxy/policies/
619 04-26-2017 11:11 apiproxy/policies/AM-CleanResponseHeaders.xml
126 04-26-2017 11:11 apiproxy/policies/JS-MaybeFormatFault.xml
421 04-26-2017 11:11 apiproxy/policies/RF-UnknownRequest.xml
0 04-26-2017 11:24 apiproxy/proxies/
865 04-26-2017 11:24 apiproxy/proxies/default.xml
0 04-26-2017 11:11 apiproxy/resources/
0 04-26-2017 11:11 apiproxy/resources/jsc/
573 04-26-2017 11:11 apiproxy/resources/jsc/maybeFormatFault.js
0 08-31-2017 16:48 apiproxy/resources/node/
2265588 08-31-2017 16:48 apiproxy/resources/node/node_modules.zip
403 04-26-2017 11:15 apiproxy/resources/node/package.json
1520 04-26-2017 11:22 apiproxy/resources/node/testServer.js
0 04-26-2017 11:24 apiproxy/targets/
770 04-26-2017 11:24 apiproxy/targets/default.xml
--------- -------
2271322 17 files
zip: apiproxy-crypto-test-20170831-164831.zip
#!/bin/bash
# -*- mode:shell-script; coding:utf-8; -*-
#
# Created: <Thu Aug 31 16:39:21 2017>
# Last Updated: <2017-August-31 16:48:28>
#
verbosity=2
ProduceApiProxyZip() {
local apiproxydir="$1" zipout curdir=$(pwd) TIMESTAMP=$(date '+%Y%m%d-%H%M%S')
local apiproxy=$(basename "${apiproxydir}")
local zipname="apiproxy-${apiproxy}-${TIMESTAMP}.zip"
[[ $verbosity -gt 0 ]] && echo "Creating the zip at $zipname"
[[ ! -d "${apiproxydir}" ]] && echo "that directory does not exist." && exit 1
[[ ! -d "${apiproxydir}/apiproxy" ]] && echo "that directory does not exist." && exit 1
# check for package.json
if [[ -f "${apiproxydir}/apiproxy/resources/node/package.json" ]]; then
[[ $verbosity -gt 0 ]] && echo "zipping the node modules..."
cd "${apiproxydir}/apiproxy/resources/node"
[[ -d node_modules ]] && rm -rf node_modules
[[ -f node_modules.zip ]] && rm -rf node_modules.zip
npmout=`npm install 2>&1`
[[ -f npm-debug.log ]] && rm npm-debug.log
zipout=`zip node_modules.zip -r node_modules/ -x "*/Icon*" 2>&1`
[[ -d node_modules ]] && rm -rf node_modules
fi
cd "$curdir"
cd "${apiproxydir}"
otherfiles=""
for f in LICENSE License.txt README.md Readme.txt ; do
[[ -f "${f}" ]] && otherfiles="${otherfiles} ${f}"
done
zipout=$(zip -r "${zipname}" -r apiproxy $otherfiles -x "*/*.*~" -x "*/.tern-port" -x "*/.DS_Store" -x "*/Icon*" -x "*/#*.*#" -x "*/node_modules/*")
mv "${zipname}" "$curdir"
cd "$curdir"
[[ $verbosity -gt 1 ]] && unzip -l ${zipname} && echo
[[ $verbosity -gt 1 ]] && echo "zip: ${zipname}"
}
ProduceApiProxyZip $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment