diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/sourcemap2json.js | 15 | ||||
-rwxr-xr-x | tools/sourcemapper.js | 10 |
2 files changed, 21 insertions, 4 deletions
diff --git a/tools/sourcemap2json.js b/tools/sourcemap2json.js new file mode 100644 index 00000000..5dd162b2 --- /dev/null +++ b/tools/sourcemap2json.js @@ -0,0 +1,15 @@ +/* + * Quick utility script for the Python test script to call. Could be replaced if + * a good Python source map library is found. + */ +var SourceMapConsumer = require('source-map').SourceMapConsumer; +var fs = require('fs'); + +var consumer = new SourceMapConsumer(fs.readFileSync(process.argv[2], 'utf-8')); +var mappings = []; + +consumer.eachMapping(function(mapping) { + mappings.push(mapping); +}); + +console.log(JSON.stringify(mappings)); diff --git a/tools/sourcemapper.js b/tools/sourcemapper.js index 3d8dbe99..fce9251f 100755 --- a/tools/sourcemapper.js +++ b/tools/sourcemapper.js @@ -68,7 +68,7 @@ function generateMap(fileName, sourceRoot, mapFileBaseName) { var path = require('path'); var SourceMapGenerator = require('source-map').SourceMapGenerator; - var generator = new SourceMapGenerator({ file: fileName }); + var generator = new SourceMapGenerator({ file: mapFileBaseName }); var generatedSource = fs.readFileSync(fileName, 'utf-8'); var seenFiles = Object.create(null); @@ -80,11 +80,13 @@ function generateMap(fileName, sourceRoot, mapFileBaseName) { if (!(originalFileName in seenFiles)) { seenFiles[originalFileName] = true; + var rootedPath = originalFileName[0] === path.sep ? + originalFileName : path.join(sourceRoot, originalFileName); try { - generator.setSourceContent(originalFileName, - fs.readFileSync(sourceRoot + "/" + originalFileName)); + generator.setSourceContent(originalFileName, fs.readFileSync(rootedPath, 'utf-8')); } catch (e) { - console.warn("Unable to find original file for " + originalFileName); + console.warn("Unable to find original file for " + originalFileName + + " at " + rootedPath); } } |