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

Commit 77464c6

Browse files
committed
When versioning files, copy over .map files as well.
1 parent 07fbab4 commit 77464c6

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

ingredients/version.js

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var rev = require('gulp-rev');
44
var del = require('del');
55
var utilities = require('./commands/Utilities');
66
var vinylPaths = require('vinyl-paths');
7+
var fs = require('fs');
8+
var parsePath = require('parse-filepath');
79

810
/*
911
|----------------------------------------------------------------
@@ -17,13 +19,30 @@ var vinylPaths = require('vinyl-paths');
1719
*/
1820

1921
elixir.extend('version', function(src, buildDir) {
22+
buildTask(src, buildDir);
2023

24+
this.registerWatcher('version', src);
25+
26+
return this.queueTask('version');
27+
});
28+
29+
30+
/**
31+
* Build the "version" Gulp task.
32+
*
33+
* @param {string} src
34+
* @param {string} buildDir
35+
* @return {object}
36+
*/
37+
var buildTask = function(src, buildDir) {
2138
src = utilities.prefixDirToFiles('public', src);
22-
buildDir = buildDir ? buildDir + '/build' : 'public/build';
39+
buildDir = getBuildDir(buildDir);
2340

2441
gulp.task('version', function() {
2542
var files = vinylPaths();
2643

44+
// To start, we'll clear out the build directory,
45+
// so that we can start from scratch.
2746
del.sync(buildDir + '/*', { force: true });
2847

2948
return gulp.src(src, { base: './public' })
@@ -38,11 +57,49 @@ elixir.extend('version', function(src, buildDir) {
3857
// usually gets put in the "build" folder,
3958
// alongside the suffixed version.
4059
del(files.paths);
60+
61+
// We'll also copy over relevant sourcemap files.
62+
copyMaps(src, buildDir);
4163
});
4264
});
65+
};
4366

44-
this.registerWatcher('version', src);
4567

46-
return this.queueTask('version');
68+
/**
69+
* Prepare the path to the build directory.
70+
*
71+
* @param {string} buildDir
72+
* @return {string}
73+
*/
74+
var getBuildDir = function(buildDir) {
75+
return buildDir ? buildDir + '/build' : 'public/build';
76+
};
4777

48-
});
78+
79+
/**
80+
* Copy source maps to the build directory.
81+
*
82+
* @param {string} src
83+
* @param {string} buildDir
84+
* @return {object}
85+
*/
86+
var copyMaps = function(src, buildDir) {
87+
88+
// We'll first get any files from the src
89+
// array that have companion .map files.
90+
var mappings = src.map(function(file) {
91+
var map = file + '.map';
92+
93+
if (fs.existsSync(map)) {
94+
return map;
95+
}
96+
});
97+
98+
// And then we'll loop over this mapping array
99+
// and copy each over to the build directory.
100+
mappings.forEach(function(mapping) {
101+
var map = mapping.replace('public', buildDir);
102+
103+
gulp.src(mapping).pipe(gulp.dest(parsePath(map).dirname));
104+
});
105+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "laravel-elixir",
3-
"version": "0.12.1",
3+
"version": "0.12.2",
44
"description": "Laravel Elixir Core",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)