-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-cli.sh
executable file
·37 lines (30 loc) · 1.03 KB
/
create-cli.sh
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
#!/bin/bash
set -euo pipefail
echo '#!/bin/bash';
# Obtain path where ./create-cli.sh is located.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
SRC_FOLDERS=$(find "$DIR/src" -type d -d 1)
echo "exec osascript -l JavaScript - \"\$@\" 3<&0 <<'EOFautomac'"
# Append src/init.js to the beginning of the file
cat "$DIR/src/init.js"
for FOLDER_PATH in $SRC_FOLDERS; do
cd "$FOLDER_PATH";
CMD=$(basename -- "$(pwd)");
JS_FILES=$(find . -type f -name "*.js")
for i in $JS_FILES; do
filename="$(basename -- "$i")"
filenameWithoutExtension="${filename%.*}"
echo "(function () {"
echo "const module = {};"
echo "const exports = {};"
echo "module.exports = exports;"
echo "(function (module, exports) {"
cat "$i"
echo "})(module, exports);"
echo "modules[\"$CMD\"] = modules[\"$CMD\"] || {};";
echo "modules[\"$CMD\"][\"$filenameWithoutExtension\"] = module.exports;"
echo "})();"
done
cd ../..
done
echo "EOFautomac"