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 all 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
78 changes: 58 additions & 20 deletions tasks/version.js
Expand Up @@ -21,8 +21,9 @@ var revReplace = require('gulp-rev-replace');
|
*/

Elixir.extend('version', function(src, buildPath) {
Elixir.extend('version', function(src, buildPath, assets) {
var paths = prepGulpPaths(src, buildPath);
var assets = prepGulpPaths(assets, buildPath);

new Elixir.Task('version', function() {
var files = vinylPaths();
Expand Down Expand Up @@ -51,8 +52,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,29 +102,63 @@ 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) {
src.forEach(function(file) {
// We'll first get any files from the src
// array that have companion .map files.
getFiles(src,function(files){
var maps = files
.map(function(file) {
return file + '.map';
})
.filter(function(file) {
return fs.existsSync(file);
});

copyFiles(maps, buildPath);
});
};


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


/**
* Extract the file listing from an array that may
* contain files, directories and wildcard strings
*
* @param {array} src
* @return ({array})
*/
var getFiles = function(src,callback) {
src.forEach(function(file) {
glob(file, {}, function(error, files) {
if (error) return;

files
.filter(function(file) {
return fs.existsSync(file + '.map');
})
.forEach(function(file) {
// We will loop over this files array, and
// copy each map to the build directory.
var map = file.replace(publicPath, buildPath);

gulp.src(file + '.map').pipe(gulp.dest(parsePath(map).dirname));
});
callback(files);
});
});
};
}


/**
* Copy files from public path to build path.
*
* @param {array} files
* @param {string} buildPath
*/
var copyFiles = function(files, buildPath) {
files.forEach(function(file) {
var dest = file.replace(publicPath, buildPath);
gulp.src(file).pipe(gulp.dest(parsePath(dest).dirname));
});
}