Skip to content

Commit

Permalink
Add common grunt tasks and utils
Browse files Browse the repository at this point in the history
- readManifest: process recursive build.json's
- grunt task copy-sourcemap: copy the sourcesContent from sourceMapA to sourceMapB
  • Loading branch information
dfreedm committed Oct 21, 2013
1 parent 8248271 commit 7f50870
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
26 changes: 26 additions & 0 deletions loader/readManifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// recursive module loader
var fs = require('fs');
var path = require('path');

function readJSON(filename) {
var blob = fs.readFileSync(filename, 'utf8');
return JSON.parse(blob);
}

function readManifest(filename, modules) {
modules = modules || [];
var lines = readJSON(filename);
var dir = path.dirname(filename);
lines.forEach(function(line) {
var fullpath = path.join(dir, line);
if (line.slice(-5) == '.json') {
// recurse
readManifest(fullpath, modules);
} else {
modules.push(fullpath);
}
});
return modules;
}

module.exports = readManifest;
14 changes: 14 additions & 0 deletions tasks/copy-sourcemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = function(grunt) {
grunt.registerTask('sourcemap_copy', 'Copy sourcesContent between sourcemaps', function(source, dest) {
var sourceMap = grunt.file.readJSON(source);
var destMap = grunt.file.readJSON(dest);
destMap.sourcesContent = [];
var ssources = sourceMap.sources;
// uglify may reorder sources, make sure sourcesContent matches new order
destMap.sources.forEach(function(source) {
var j = ssources.indexOf(source);
destMap.sourcesContent.push(sourceMap.sourcesContent[j]);
});
grunt.file.write(dest, JSON.stringify(destMap));
});
};

0 comments on commit 7f50870

Please sign in to comment.