puggan icon

gulp

puggan | PRO | 05/26/20 10:10:19 AM UTC | 0 ⭐ | 562 👁️ | Never ⏰ | []
Bash |

1.5 KB

|

None

|

0 👍

/

0 👎

#!/usr/bin/env php
<?php
 
$gulp = '/usr/local/lib/node_modules/gulp/bin/gulp.js';
 
$cmd = [
    escapeshellcmd($gulp),
    '--color',
];
foreach($argv as $index => $arg) {
    if($index) {
        $cmd[] = escapeshellarg($arg);
    }
}
 
$dir = getcwd();
 
if(file_exists($dir .'/gulp.sh')) {
    $cmd[0] = escapeshellcmd($dir .'/gulp.sh');
} else {
    $gulpdir = gulpDir($dir);
    if($gulpdir && $dir !== $gulpdir) {
        chdir($gulpdir);
    }
}
 
 
$r = 0;
passthru(implode(' ', $cmd), $r);
exit($r);
 
function globTests($tests) {
    foreach($tests as $test) {
        $found = glob($test);
        foreach($found as $file) {
            if(is_file($file)) {
                return $file;
            }
        }
    }
}
 
function gulpDir($dir) {
    $dir_p1 = dirname($dir, 1);
    $dir_p2 = dirname($dir_p1, 1);
    $found = globTests([
        $dir . '/gulpfile.js',
        $dir . '/asset/gulpfile.js',
        $dir . '/assets/gulpfile.js',
        $dir . '/src/gulpfile.js',
        $dir_p1 . '/gulpfile.js',
        $dir_p2 . '/gulpfile.js',
        $dir . '/content/themes/*/gulpfile.js',
        $dir . '/content/themes/*/asset*/gulpfile.js',
        $dir . '/content/themes/*/src/gulpfile.js',
        $dir . '/content/themes/*/*/gulpfile.js',
        $dir . '/content/themes/*/*/*/gulpfile.js',
        $dir . '/themes/*/gulpfile.js',
        $dir . '/themes/*/asset*/gulpfile.js',
        $dir . '/themes/*/src/gulpfile.js',
        $dir . '/themes/*/*/gulpfile.js',
        $dir . '/themes/*/*/*/gulpfile.js',
        $dir . '/*/gulpfile.js',
        $dir . '/*/asset*/gulpfile.js',
        $dir . '/*/src/gulpfile.js',
        $dir . '/*/*/gulpfile.js',
        $dir . '/*/*/*/gulpfile.js',
    ]);
    if($found) {
        return dirname($found);
    }
}

Comments