Skip to content
This repository was archived by the owner on Feb 28, 2020. It is now read-only.

Commit

Permalink
feat: iterative dev
Browse files Browse the repository at this point in the history
Added iterative dev script, which allows for fast/easy dev iterations for the developer.  While the script is running, it will automatically detect changes in the project's `.swift` files and recompile the app accordingly.  

Sample usage (after generating the project)...

From native OS:
1. cd into the project's root directory directory
2. run `./iterative-dev.sh` 

With `bx dev` cli: 
1. build the app using `bx dev build --debug`
2. shell into the tools container using `bx dev shell tools`
3. run `./swift-project/iterative-dev.sh`

File system changes are detected using a low-tech infinitely looping poll mechanism, which works in both local OS/filesystem and across host OS->Docker container volume scenarios.
  • Loading branch information
triceam authored Apr 27, 2018
1 parent 59f3e8a commit 7cd7c0c
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
10 changes: 10 additions & 0 deletions refresh/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,16 @@ module.exports = Generator.extend({
)
this.fs.write(this.destinationPath('Sources', this.applicationModule, 'Routes', '.keep'), '')
}

this._ifNotExistsInProject('iterative-dev.sh', (filepath) => {
this.fs.copyTpl(
this.templatePath('common', 'iterative-dev.sh'),
filepath,
{
executableModule: this.executableModule
}
)
})
},

createFromSwagger: function () {
Expand Down
92 changes: 92 additions & 0 deletions refresh/templates/common/iterative-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

# This script sets up an iterative loop to accelerate development of
# server-side swift applications. It periodically checks the filesystem
# contents to look for changes in any .swift files. If any are found,
# it will kill the currently running server process, rebuild, and restart
# both the server process and lldb-server (debug) process.





# kills the executable for this project and the lldb debug server (if running)
function killServerProcesses() {
pid="$(pgrep <%- executableModule %>)"
if [ "$pid" != "" ]
then
echo "killing <%- executableModule %>"
kill $pid
fi

pid="$(pgrep lldb-server)"
if [ "$pid" != "" ]
then
echo "killing lldb-server"
kill $pid
fi
}

# called on signal interrupt (CTRL-C)
function interrupt ()
{
printf "\n\nuser cancelled\n"
killServerProcesses
printf "\n"
exit 2
}

# trap to handle signal interrupt
trap "interrupt" INT





# Using an infinite loop/polling mechanism b/c it appears that
# inotifywait (os file system events) does not pickup changes
# on a volume, where the change orignates from the host OS (outside of the container)
# the poll just checks the contents of a recursive ls command for *files* only with full timestamps.
#
# If the ls output changes between loop iterations, the script
# will kill the existing server process and restart it.
#
# This recursively looks for file changes for swift files only,

echo "setting up watcher..."
lastOutput=""

# check if tools-utils.sh exists. if so, assume you are inside of Dockerfile-tools container
if [ -e /swift-utils/tools-utils.sh ]
then
cd /swift-project/
fi

while true; do
unamestr=`uname`
lsCommand='ls -lt -R --time-style=full-iso'
if [[ "$unamestr" == 'Darwin' ]]; then
lsCommand='ls -lT -R'
fi
temp="$($lsCommand | grep -i ^-[-r][-w][-x][-r][-w][-x][-r][-w][-x].*\.swift$)"
if [ "$lastOutput" != "$temp" ]
then
lastOutput="$temp"
killServerProcesses

echo "starting server..."
if [ -e /swift-utils/tools-utils.sh ]
then
# assumes you are inside of Dockerfile-tools container
# starts debug server on port 1024
cd /swift-project/
/swift-utils/tools-utils.sh debug <%- executableModule %> 1024
else
# assumes you are running from "normal"/host operating system
swift build
./.build/debug/<%- executableModule %> &
fi

fi
sleep 2.0
done

0 comments on commit 7cd7c0c

Please sign in to comment.