-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle-ls
executable file
·113 lines (102 loc) · 2.86 KB
/
bundle-ls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
# show help
# -----------------------------------------------
show_help(){
cat <<HELP
Creates bundle from a LiveScript file by using Rollup.
$(basename $0) source-file.ls [options]
Options:
--out : Output file
--no-map : Do not include Source Maps
-f, --force : Overwrite the output file
-h, --help : Show help
-w, --watch : Watch the file and its dependencies, rebuild when necessary
HELP
}
die(){
echo
echo "$1"
echo
show_help
exit 1
}
err(){
echo
echo "$@"
echo
exit 1
}
# Parse command line arguments
# ---------------------------
# Initialize parameters
out="auto"
force=
sourcemaps="--output.sourcemap=inline"
watch=
# ---------------------------
args_backup=("$@")
args=()
_count=1
while :; do
key="${1:-}"
case $key in
-h|-\?|--help)
show_help # Display a usage synopsis.
exit
;;
# --------------------------------------------------------
--out) shift
if [[ -n $1 ]]; then
out="$1"
shift
fi
;;
-f|--force) shift
force=true
;;
--no-map) shift
sourcemaps=
;;
-w|--watch) shift
watch="-w"
;;
# --------------------------------------------------------
-*) # Handle unrecognized options
echo
echo "Unknown option: $1"
echo
exit 1
;;
*) # Generate the new positional arguments: $arg1, $arg2, ... and ${args[@]}
if [[ ! -z ${1:-} ]]; then
declare arg$((_count++))="$1"
args+=("$1")
shift
fi
esac
[[ -z ${1:-} ]] && break
done; set -- "${args_backup[@]}"
# Use $arg1 in place of $1, $arg2 in place of $2 and so on,
# "$@" is in the original state,
# use ${args[@]} for new positional arguments
src="${arg1:-}"
[[ -z ${src:-} ]] && die "Source file can not be empty"
[[ "$out" = "auto" ]] && out="${src}.js"
[[ -z "$force" ]] && [[ -f "$out" ]] && err "Output file exists: $out"
cleanup(){
echo "Cleaning up temporary file ($tmp)"
rm $out 2> /dev/null
}
trap cleanup INT
rollup $watch -c "$DIR/rollup.config.js" --input "$src" --output.file "$out" $sourcemaps &
while sleep 1; do
# wait until first output is created
[[ -f "$out" ]] && break
done