Skip to content

Commit

Permalink
Preload every module and task before running the code
Browse files Browse the repository at this point in the history
It will ensure it works with everything loaded. No one needs to care about
requiring the module before using it. Requiring the tasks also ensure
everything will work if files are assembled into a single executable file.
  • Loading branch information
bellthoven committed Feb 20, 2015
1 parent 6ed8fcd commit 2a06f85
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tasks/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
btask.run.run () {
function btask.run.run () {
local working_dir="$(b.get bang.working_dir)"
local file="$1"
shift
Expand All @@ -9,8 +9,20 @@ btask.run.run () {
fi

if b.path.file? "$file"; then
local base_path="$(dirname "$file")"

# Preloading modules and tasks
b.path.dir? "$base_path/modules" && _load_bash_files_from "$base_path/modules"
b.path.dir? "$base_path/tasks" && _load_bash_files_from "$base_path/tasks"

. "$file"
else
b.abort "Could not run '$file' because it is not a file."
fi
}

function _load_bash_files_from () {
for file_path in $(find "$1" -name '*.sh'); do
source "$file_path"
done
}

0 comments on commit 2a06f85

Please sign in to comment.