title: How to order the compiling of javascript files in Gulp
body: <p>Hi I'm trying to fix the order of the js files that get compiled in my Gulp task.</p>
  
  <p>The order I need:</p>
  
  <pre><code>'/_sources/js/libs/*.js'
  '/_sources/js/plugins/*.js'
  '/_sources/js/custom/*.js'
  '/_components/*.js'
  </code></pre>
  
  <p>Issue is that the custom folder contains a <strong>custom particlesJS</strong> script and the <strong>main particlesJS</strong> script is inside the plugins folder. So if the <strong>custom script</strong> ends up above the <strong>main particlesJS</strong> in the compiled js file everything breaks.</p>
  
  <p>I tried to re-order things with <strong><a href="https://www.npmjs.com/package/gulp-order" rel="nofollow">gulp-order</a></strong> and <code>event-stream</code> but the .order doesn't seem to work, still compiles in the wrong order:</p>
  
  <pre><code>function compile_js(minify, folder) {
      var jsLibs = gulp.src(folder+'/_sources/js/libs/*.js');
      var jsPlugins = gulp.src(folder+'/_sources/js/plugins/*.js');
      var jsCustom = gulp.src(folder+'/_sources/js/custom/*.js');
      var jsComponents = gulp.src(folder+'/_components/*.js');
  
      return es.merge(jsLibs, jsPlugins, jsComponents, jsCustom)
          .pipe(order([
              folder+'/_sources/js/libs/*.js',
              folder+'/_sources/js/plugins/*.js',
              folder+'/_sources/js/custom/*.js',
              folder+'/_components/*.js'
          ]))
          .pipe(concat('bitage_scripts.js'))
          .pipe(gulpif(minify, uglify()))
          .pipe(gulp.dest(folder+'/_assets/js'));
  };
  </code></pre>
  
  <p>Next I tried <strong><a href="https://www.npmjs.com/package/streamqueue" rel="nofollow">streamqueue</a></strong>:</p>
  
  <pre><code>function compile_js(minify, folder) {
      var jsLibs = gulp.src(folder+'/_sources/js/libs/*.js');
      var jsPlugins = gulp.src(folder+'/_sources/js/plugins/*.js');
      var jsCustom = gulp.src(folder+'/_sources/js/custom/*.js');
      var jsComponents = gulp.src(folder+'/_components/*.js');
  
      return streamqueue({ objectMode: true },
          gulp.src([
              jsLibs,
              jsPlugins,
              jsCustom]),
          gulp.src([jsComponents]).pipe(sass())
      )
      .pipe(concat('bitage_scripts.js'))
      .pipe(gulpif(minify, uglify()))
      .pipe(gulp.dest(folder+'/_assets/js'));
  };
  </code></pre>
  
  <p>Which threw this error: <code>Error: Invalid glob argument: [object Object],[object Object],[object Object]</code></p>
  
  <p><strong>The task:</strong></p>
  
  <pre><code>// Development task
  gulp.task('devsite', function () {
      minify = false;
      return compile_js(minify, 'public');
  });
  </code></pre>
  
  <p>Any thoughts/suggestions?</p>