-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- readManifest: process recursive build.json's - grunt task copy-sourcemap: copy the sourcesContent from sourceMapA to sourceMapB
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}; |