Looking to use Gulp to create individual distributions of standalone HTML files

Basically I'm looking for a Gulp plugin to turn a directory like this:

/app
     - htmlfile1.html
     - htmlfile2.html
     - htmlfile3.html
     - /css
          -cssmain.css
     -/js
          -global.js

And turn that into this:

/dist
     -/htmlfile1
          - htmlfile1.html
          - /css
               -cssmain.css
          -/js
               -global.js
     - /htmlfile2
          - htmlfile2.html
          - /css
               -cssmain.css
          -/js
               -global.js
     - /htmlfile3
          - htmlfile3.html
          - /css
               -cssmain.css
          -/js
               -global.js

Any thoughts on how to do accomplish a build system like this?

The code allows common files to be added to every page distribution as well as unique dependencies defined as an array in the pages object.

The following Gulp file relies on gulp-foreach, parse-filepath, and event-stream: npm install gulp gulp-foreach parse-filepath event-stream --save-dev

gulpfile.js:

// Command:
// npm install gulp gulp-foreach parse-filepath event-stream --save-dev

// Include gulp
var gulp = require('gulp');

var foreach = require('gulp-foreach'); // https://www.npmjs.org/package/gulp-foreach
var parsePath = require('parse-filepath'); // https://www.npmjs.org/package/parse-filepath
var es = require('event-stream'); // https://www.npmjs.org/package/event-stream

// The pages that each make a distribution
// Unique dependencies are defined as an array value for each page.
var pages = {
    './app/htmlfile1.html': [
        './app/images/1.png',
        './app/images/1-another.png',
    ],
    './app/htmlfile2.html': [],
    './app/htmlfile3.html': []
};

// Files added to each page distribution
var common = [
    './app/css/cssmain.css',
    './app/js/global.js',
];

function makeDistributionStream(page)
{
    var gulpStream = gulp.src(page)
        .pipe(foreach(function(stream, file) {
            var pathParts = parsePath(file.path);
            // Assemble the distribution path
            var destinationPath = './dist/' + pathParts.name + '/';

            // Pipe the html into the distribution folder
            stream.pipe(gulp.dest(destinationPath));

            // Move all of the unique and common files into the distibution
            var uniqueDependencies = pages[page];
            // Merge the common files to the unique ones
            var distFiles = uniqueDependencies.concat(common);
            gulp.src(distFiles, {base: './app/'})
                .pipe(gulp.dest(destinationPath));
        }));

    return gulpStream;
}

// Assemble the distribution directories for each page
gulp.task('make-distributions', function() {
    var mergedStream = null;
    for(var page in pages)
    {
        var stream = makeDistributionStream(page);

        // Merge the streams, if there is already one
        if(mergedStream)
        {
            mergedStream = es.merge(mergedStream, stream);
        }
        // Otherwise, just make it this one
        else
        {
            mergedStream = stream;
        }
    }

    return mergedStream;
});

// Rerun the task when a file changes
gulp.task('watch', function() {
    // If the html pages change, re-make the distributions
    gulp.watch(Object.keys(pages), ['make-distributions']);
});

// Default Task
gulp.task('default', ['make-distributions', 'watch']);