Skip to content

Commit e7ce5db

Browse files
committed
Merge pull request #48 from KeenS/devtools
開発ツールの整備
2 parents 6c45cbc + fe5098c commit e7ce5db

File tree

2 files changed

+88
-10
lines changed

2 files changed

+88
-10
lines changed

tools/watch.sh

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,48 @@
11
#!/bin/sh
2-
VERSION=$1
3-
DIR=$(cd "$(dirname "$0")"; pwd)
4-
ROOT="${DIR}/../"
2+
usage() {
3+
cat <<HELP
4+
NAME:
5+
$0 -- watch document dir and build the book
6+
7+
SYNOPSIS:
8+
$0 <version>
9+
$0 [-h|--help]
10+
11+
DESCRIPTION:
12+
A watch and build script.
13+
This uses 'rustbook' command, and use 'RUSTBOOK' as the path if set.
14+
15+
-h --help Print this help.
16+
17+
EXAMPLE:
18+
watch and build 1.6
19+
20+
$ RUSTBOOK=/path/to/rustbook $0 1.6
21+
22+
HELP
23+
}
24+
25+
26+
main() {
27+
case "$1" in
28+
-h|--help) usage; exit 0;;
29+
esac
30+
31+
if command -v inotifywait > /dev/null 2>&1 ||
32+
command -v fswatch > /dev/null 2>&1
33+
then
34+
echo "You need to install 'inotifywait'(in inotify-tools) on Linux or 'fswatch' on OS X" >&2
35+
exit 1
36+
fi
37+
38+
: ${RUSTBOOK:=rustbook}
39+
VERSION=$1
40+
DIR=$(cd "$(dirname "$0")"; pwd)
41+
ROOT="${DIR}/../"
42+
build
43+
watch "${ROOT}/${VERSION}/ja"
44+
}
45+
546

647
build() {
748
make -C "${ROOT}" RUSTBOOK=${RUSTBOOK}
@@ -27,5 +68,4 @@ watch(){
2768
esac
2869
}
2970

30-
31-
watch "${ROOT}/${VERSION}/ja"
71+
main "$@"

tools/watch_and_serve.sh

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,47 @@
11
#!/bin/sh
2-
RUBY=ruby
3-
ROOT=$(cd "$(dirname "$0")"; pwd)
2+
usage() {
3+
cat <<HELP
4+
NAME:
5+
$0 -- watch document dir, build the book and serve built HTML
46
5-
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
7+
SYNOPSIS:
8+
$0 <version>
9+
$0 [-h|--help]
610
7-
"$RUBY" -run -e httpd -- . --port 8080 &
8-
"$ROOT/watch.sh" "$1"
11+
DESCRIPTION:
12+
A watch and build and serve script.
13+
The server will listen on localhost:8080 and document root will be 'public' dir.
14+
This uses 'rustbook' command.
15+
You can pass the 'rustbook' path via 'RUSTBOOK' env var.
916
17+
-h --help Print this help.
18+
19+
EXAMPLE:
20+
watch and build then serve HTML of 1.6
21+
22+
$ RUSTBOOK=/path/to/rustbook $0 1.6
23+
24+
BUGS:
25+
Server program might survive even after you INTed this program.
26+
Pathes are wellcome!
27+
28+
29+
HELP
30+
}
31+
32+
main() {
33+
case "$1" in
34+
-h|--help) usage; exit 0;;
35+
esac
36+
37+
RUBY=ruby
38+
DIR=$(cd "$(dirname "$0")"; pwd)
39+
ROOT="${DIR}/../"
40+
41+
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
42+
43+
"$RUBY" -run -e httpd -- "${ROOT}/public" --port 8080 &
44+
"$DIR/watch.sh" "$@"
45+
}
46+
47+
main "$@"

0 commit comments

Comments
 (0)