Created
June 8, 2015 23:28
-
-
Save zxbodya/ca6fb758259f6a077de7 to your computer and use it in GitHub Desktop.
script to extract sources, from sourcesContent field in sourcemap
This file contains hidden or 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
'use strict'; | |
var fs = require('fs'); | |
var maps = [ | |
fs.readFileSync('./main.xxxx.js.map'), | |
fs.readFileSync('./1.chunk.xxxx.js.map'), | |
fs.readFileSync('./2.chunk.xxxx.js.map'), | |
fs.readFileSync('./3.chunk.xxxx.js.map') | |
]; | |
function mapping(name){ | |
if (/^webpack:\/\/\/\.\//.test(name)) { | |
return 'unpacked/' + name.replace(/^webpack:\/\/\/\.\//, 'app/') | |
.replace(/\.(\w+)\?[./]*/, '\.$1'); | |
} | |
// add more cases here to map all mossible source paths | |
return false; | |
} | |
maps.forEach(function (mainJSON) { | |
var main = JSON.parse(mainJSON); | |
main.sources.forEach(function (name, i) { | |
var dstFile; | |
if (dstFile = mapping(name)) { | |
if (!fs.existsSync(dstFile)) { | |
var dirs = dstFile.split('/'); | |
dirs.slice(0,-1).reduce(function (acc, di) { | |
var dir = acc+di; | |
if (!fs.existsSync(dir)) { | |
fs.mkdirSync(dir); | |
} | |
return dir+'/'; | |
}, './'); | |
fs.writeFileSync(dstFile, main.sourcesContent[i]); | |
} | |
} else { | |
console.log('Mapping missing for filename: '+name); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment