Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Copy assets files when using mix.version() command #268

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
109 changes: 82 additions & 27 deletions tasks/version.js
Expand Up @@ -21,8 +21,15 @@ var revReplace = require('gulp-rev-replace');
|
*/

Elixir.extend('version', function(src, buildPath) {
Elixir.extend('version', function(src, buildPath, assets) {
// Allow users to use assets as the second argument
if(Array.isArray(buildPath)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cs

assets = buildPath;
buildPath = null;
}

var paths = prepGulpPaths(src, buildPath);
var assets = prepGulpPaths(assets, buildPath);

new Elixir.Task('version', function() {
var files = vinylPaths();
Expand Down Expand Up @@ -51,8 +58,11 @@ Elixir.extend('version', function(src, buildPath) {
// alongside the suffixed version.
del(files.paths, { force: true });

// We'll also copy over relevant sourcemap files.
// We'll copy over relevant sourcemap files.
copyMaps(paths.src.path, paths.output.baseDir);

// We'll also copy the assets if they exist.
copyAssets(assets.src.path, assets.output.baseDir);
})
);
})
Expand Down Expand Up @@ -98,35 +108,80 @@ var emptyBuildPathFiles = function(buildPath, manifest) {
/**
* Copy source maps to the build directory.
*
* @param {string} src
* @param {array} src
* @param {string} buildPath
* @return {object}
*/
var copyMaps = function(src, buildPath) {
wildcard(src,function(files){
var mappings = getMapFiles(files);
copyFiles(mappings, buildPath);
});
};


/**
* Copy user assets to the build directory.
*
* @param {array} src
* @param {string} buildPath
*/
var copyAssets = function(src, buildPath) {
wildcard(src,function(files){
copyFiles(files, buildPath);
});
};


/**
* Extract file listing from an array
* containing wildcard strings.
*
* @param {array} src
* @return ({array})
*/
var wildcard = function(src,callback) {
src.forEach(function(file) {
// We'll first get any files from the src
// array that have companion .map files.
glob(file, {}, function(err, files) {
if (err === null) {
// Here we will store the mappings.
var mappings = [];

// Loop over each file found by glob
// and check if a map for that file exists.
files.forEach(function(file) {
var map = file + '.map';
if (fs.existsSync(map)) {
mappings.push(map);
}
});

// And then we'll loop over this mapping array
// and copy each over to the build directory.
mappings.forEach(function(mapping) {
var map = mapping.replace(publicPath, buildPath);
gulp.src(mapping).pipe(gulp.dest(parsePath(map).dirname));
});
}
var listing = (err === null) ? files : [];
callback(listing);
});
});
};
}


/**
* Loop over each file and returns a
* list of corresponding .map files.
*
* @param {array} files
* @return {array}
*/
var getMapFiles = function(files) {
var mappings = [];

files.forEach(function(file) {
var map = file + '.map';
if (fs.existsSync(map)) {
mappings.push(map);
}
});

return mappings;
}


/**
* Copy files from public path to build path.
*
* @param {array} files
* @param {string} buildPath
*/
var copyFiles = function(files, buildPath) {

// Copy each file to the build directory.
files.forEach(function(file) {
var dest = file.replace(publicPath, buildPath);
gulp.src(file).pipe(gulp.dest(parsePath(dest).dirname));
});

}