ARTISAN_APP=./artisan

function main() {
    runLaravelArtisan "$@"
}

function runLaravelArtisan() {
    # is there an artisan in current folder?
    if [ ! -f $ARTISAN_APP ]; then
        findLaravelArtisan
    fi

    # artisan was found?
    if [ "$ARTISAN_APP" != "" ] && [ -f $ARTISAN_APP ]; then
        echo "Artisan found at $ARTISAN_APP"
        php $ARTISAN_APP $@
        exit 1
    else
        echo "sorry, no artisan found"
    fi
}

function findLaravelArtisan() {
    # find artisan or stop on /
    dir=..; until [[ -e $dir/artisan || $dir -ef / ]]; do dir+=/..; done

    # convert path to absolute path
    dir=`cd "$dir"; pwd`

    # make artisan file path
    app=$dir/artisan

    # was it found?
    if [[ "$app" != "" ]]; then
        ARTISAN_APP=$app
    fi
}

main "$@"
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

Refs:

  • https://github.com/antonioribeiro/artisan-anywhere

Powered by VuePress
Copyright 2010-2024 Thai Nguyen Hung all rights reserved.