Giter Site home page Giter Site logo

johnydays / gulp-continuous-concat-order Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gulp-community/gulp-concat

0.0 2.0 0.0 137 KB

Streaming concat middleware for gulp with ordering

License: Apache License 2.0

JavaScript 82.28% CoffeeScript 17.72%

gulp-continuous-concat-order's Introduction

Information

Packagegulp-continuous-concat
Description Continuously concatenates files
Node Version >= 0.4

Usage

var watch = require('gulp-watch');
var concat = require('gulp-continuous-concat');

gulp.task('scripts', function() {
  gulp.src('./lib/*.js')
    .pipe(watch({glob: './lib/*.js'}))
    .pipe(concat('all.js'))
    .pipe(gulp.dest('./dist/'))
});

This will continously concat files by your operating systems newLine. This differs from the standard gulp-concat plugin in that it does not require previous streams to emit an end to work. The typical use case for this plugin is after using gulp-watch, which does not emit an end. This prevents normal gulp-concat from ever finishing. Using the above example with standard gulp-concat, the concatenated file would never be created:

var watch = require('gulp-watch');
var concat = require('gulp-concat');   // <-- standard gulp-concat

gulp.task('scripts', function() {
  gulp.src('./lib/*.js')
    .pipe(watch({glob: './lib/*.js'})) // <-- will never emit 'end'
    .pipe(concat('all.js'))            // <-- sits around forever, waiting for 'end'
    .pipe(gulp.dest('./dist/'))
});

gulp-continuous-concat gets around this by rebuilding the destination file on every incoming file. To avoid excessive rebuilding (for example, when first running the command on several files), it debounces the build step so it will only run after 100ms of not being called (the debouncing period is configurable via the debounce option on the options hash).

Files will be concatenated in the order that they are supplied, or in the order you define as an option and will maintain that order even if one of those files is later re-emitted from upstream. For example, to concat ./lib/file3.js, ./lib/file1.js and ./lib/file2.js in that order, the following code would create a task to do that:

var concat = require('gulp-continuous-concat');

gulp.task('scripts', function() {
  gulp.src(['./lib/file1.js', './lib/file2.js', './lib/file3.js'])  // <-- emits the files in order
    .pipe(watch())                                                  // <-- later, ./lib/file1.js changes and re-emitted from here
    .pipe(concat('all.js', {order:['**/file1.js','**/file2.js', '**/file3.js']})) // ['./lib/file1.js', './lib/file2.js', './lib/file3.js'] 
    .pipe(gulp.dest('./dist/'))
});

Limitations

Because gulp-watch does not emit files that were deleted, if you add a continuous concat step after a gulp-watch, and then delete a file, it will not be removed from the concatentated result.

If and when gulp-watch adds this functionality, this plugin could be updated to remove deleted files from the result.

LICENSE

Apache 2.0 (See LICENSE file for full details)

gulp-continuous-concat-order's People

Contributors

callumacrae avatar colynb avatar davewasmer avatar floatdrop avatar kenany avatar tracker1 avatar yocontra avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.