jackrobertscott / solis-151011

Task running utilities for website development
0 stars 0 forks source link

Transform base tasks into reusable plugins #20

Open jackrobertscott opened 8 years ago

jackrobertscott commented 8 years ago

In response to a tweet by one of gulps main contributors, I had the idea of creating a system that maintained single stream on which plugins could be added to manipulated given file types. The transformed files, after transformation, would then be added back to the main stream.

This would achieve the following:

The system's process cycle:

  1. Load source files of all types (gulp.src)
  2. Run files through plugins. Plugins would:
    1. Filter files (https://www.npmjs.com/package/gulp-filter)
    2. Pipe files through gulp plugins, transforming code
    3. Restore filtered files
  3. Write files to destination (gulp.dest)

To do:

jackrobertscott commented 8 years ago

Example plugin:

module.exports = function cssPlugin(streamHandler) {
  return streamHandler.get('**/*.js')
    .pipe(autoprefixer())
    .pipe(csso())
    .pipe(concat('styles.css'));
}

In this example, stream handler would return the filtered segment of the main stream through the get() function. Then, when the altered files are returned, the stream handler restores the rest of the stream so the next plugin can filter from it.