puggan

gulp

May 26th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.50 KB | None | 0 0
  1. #!/usr/bin/env php
  2. <?php
  3.  
  4. $gulp = '/usr/local/lib/node_modules/gulp/bin/gulp.js';
  5.  
  6. $cmd = [
  7.     escapeshellcmd($gulp),
  8.     '--color',
  9. ];
  10. foreach($argv as $index => $arg) {
  11.     if($index) {
  12.         $cmd[] = escapeshellarg($arg);
  13.     }
  14. }
  15.  
  16. $dir = getcwd();
  17.  
  18. if(file_exists($dir .'/gulp.sh')) {
  19.     $cmd[0] = escapeshellcmd($dir .'/gulp.sh');
  20. } else {
  21.     $gulpdir = gulpDir($dir);
  22.     if($gulpdir && $dir !== $gulpdir) {
  23.         chdir($gulpdir);
  24.     }
  25. }
  26.  
  27.  
  28. $r = 0;
  29. passthru(implode(' ', $cmd), $r);
  30. exit($r);
  31.  
  32. function globTests($tests) {
  33.     foreach($tests as $test) {
  34.         $found = glob($test);
  35.         foreach($found as $file) {
  36.             if(is_file($file)) {
  37.                 return $file;
  38.             }
  39.         }
  40.     }
  41. }
  42.  
  43. function gulpDir($dir) {
  44.     $dir_p1 = dirname($dir, 1);
  45.     $dir_p2 = dirname($dir_p1, 1);
  46.     $found = globTests([
  47.         $dir . '/gulpfile.js',
  48.         $dir . '/asset/gulpfile.js',
  49.         $dir . '/assets/gulpfile.js',
  50.         $dir . '/src/gulpfile.js',
  51.         $dir_p1 . '/gulpfile.js',
  52.         $dir_p2 . '/gulpfile.js',
  53.         $dir . '/content/themes/*/gulpfile.js',
  54.         $dir . '/content/themes/*/asset*/gulpfile.js',
  55.         $dir . '/content/themes/*/src/gulpfile.js',
  56.         $dir . '/content/themes/*/*/gulpfile.js',
  57.         $dir . '/content/themes/*/*/*/gulpfile.js',
  58.         $dir . '/themes/*/gulpfile.js',
  59.         $dir . '/themes/*/asset*/gulpfile.js',
  60.         $dir . '/themes/*/src/gulpfile.js',
  61.         $dir . '/themes/*/*/gulpfile.js',
  62.         $dir . '/themes/*/*/*/gulpfile.js',
  63.         $dir . '/*/gulpfile.js',
  64.         $dir . '/*/asset*/gulpfile.js',
  65.         $dir . '/*/src/gulpfile.js',
  66.         $dir . '/*/*/gulpfile.js',
  67.         $dir . '/*/*/*/gulpfile.js',
  68.     ]);
  69.     if($found) {
  70.         return dirname($found);
  71.     }
  72. }
Add Comment
Please, Sign In to add comment