Skip to content

Commit

Permalink
refactor: use chakijs studio
Browse files Browse the repository at this point in the history
  • Loading branch information
themightychris committed Aug 24, 2019
1 parent 995b84d commit a698716
Showing 1 changed file with 3 additions and 134 deletions.
137 changes: 3 additions & 134 deletions .studiorc
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
#!/bin/bash


caddy_port="7081"
caddy_root="http://localhost:${caddy_port}"


# install additional packages
echo
echo "--> Installing additional studio packages for slate-cbl development..."
hab pkg install emergence/studio jarvus/sencha-cmd/6.5.2.15 core/caddy core/git jarvus/underscore jarvus/cadaver
hab pkg binlink jarvus/sencha-cmd sencha
hab pkg binlink core/caddy caddy
hab pkg binlink core/git git
hab pkg binlink jarvus/underscore underscore


# load emergence studio
hab pkg install emergence/studio chakijs/studio
source "$(hab pkg path emergence/studio)/studio.sh"
source "$(hab pkg path chakijs/studio)/studio.sh"


# setup sencha cmd
echo
echo "--> Setting up Sencha CMD..."

echo " * Use 'build-app AppName' to build an app for testing"
build-app() {
app_name="$1"
[ -z "$app_name" ] && { echo >&2 "Usage: build-app AppName"; return 1; }

echo
echo "--> Building ${app_name}..."

pushd "/src/sencha-workspace/${app_name}" > /dev/null

echo " Running: sencha app refresh"
sencha app refresh

echo " Running: sencha app build development"
sencha app build development

popd > /dev/null

echo " Done: Open app at ${caddy_root}/${app_name}"
}

# declare shortcuts for this repository's applications
echo " * Use 'build-demos-student' to build SlateDemonstrationsStudent for testing"
build-demos-student() {
build-app SlateDemonstrationsStudent
Expand Down Expand Up @@ -83,98 +44,6 @@ build-all() {
build-tasks-manager
}

echo " * Use 'config-get AppName key.path' to read a config key from an app"
config-get() {
app_name="$1"
config_key="$2"
[ -z "$app_name" ] || [ -z "$config_key" ] && { echo >&2 "Usage: config-get AppName key.path"; return 1; }

underscore \
extract "${config_key}" \
--outfmt text \
--in "/src/sencha-workspace/${app_name}/app.json"
}

echo " * Use 'publish-app pkg/ident http://myhost.org' to publish a build to a server"
publish-app() {
pkg_ident="$1"
server_host="$2"
[ -z "$pkg_ident" ] || [ -z "$server_host" ] && { echo >&2 "Usage: publish-app pkg/ident http://myhost.org"; return 1; }

pkg_path=$(hab pkg path "${pkg_ident}")
[ -z "$pkg_path" ] && { echo >&2 "Path not found for ${pkg_ident}"; return 1; }

app_name=$(cat "${pkg_path}/APP_NAME")
[ -z "$app_name" ] && { echo >&2 "Could not read app_name from ${pkg_path}/APP_NAME"; return 1; }

echo " Publishing: ${app_name} from ${pkg_path} to ${server_host}"

pushd "${pkg_path}/app" > /dev/null
hab pkg exec jarvus/cadaver cadaver-put-recursive . "${server_host}/develop/webapp-builds/${app_name}/"
popd > /dev/null
}

echo " * Use 'publish-app-quick pkg/ident http://myhost.org' to quickly publish a build update to a server by including only frequently changed files"
publish-app-quick() {
pkg_ident="$1"
server_host="$2"
[ -z "$pkg_ident" ] || [ -z "$server_host" ] && { echo >&2 "Usage: publish-app-quick pkg/ident http://myhost.org"; return 1; }

pkg_path=$(hab pkg path "${pkg_ident}")
[ -z "$pkg_path" ] && { echo >&2 "Path not found for ${pkg_ident}"; return 1; }

app_name=$(cat "${pkg_path}/APP_NAME")
[ -z "$app_name" ] && { echo >&2 "Could not read app_name from ${pkg_path}/APP_NAME"; return 1; }

echo " Publishing quickly: ${app_name} from ${pkg_path} to ${server_host}"

pushd "${pkg_path}/app" > /dev/null
hab pkg exec jarvus/cadaver cadaver -r <(
find . -maxdepth 1 -type f -printf 'mput "%f"\n';
echo 'cd resources';
echo 'lcd resources';
find resources -maxdepth 1 -type f -printf 'mput "%f"\n';
echo 'quit'
) "${server_host}/develop/webapp-builds/${app_name}/"
popd > /dev/null
}


# setup caddy server
caddy-start() {
caddy-stop

echo
echo "--> Launching the Caddy web server in the background..."

echo " Running: caddy -port ${caddy_port} -root /src/sencha-workspace browse"
setsid caddy -port "${caddy_port}" -agree -quiet -root /src/sencha-workspace -pidfile /hab/bin/caddy.pid browse &
echo " * Open ${caddy_root} to browse sencha-workspace"
echo " (If using Mac or Windows, ensure HAB_DOCKER_OPTS=\"-p ${caddy_port}:${caddy_port}\" was set when entering the studio to expose this port to your host system)"
}

caddy-stop() {
[ -f /hab/bin/caddy.pid ] && {
echo
echo "--> Stopping web server..."
CADDY_PID=$(cat /hab/bin/caddy.pid);
echo " Killing caddy process #${CADDY_PID}"
kill "${CADDY_PID}"
}
}

caddy-start


## clean up on exit
_cbl_studio_cleanup() {
caddy-stop
}

trap _cbl_studio_cleanup exit




# final blank line
echo

0 comments on commit a698716

Please sign in to comment.