diff options
author | Jez Ng <me@jezng.com> | 2013-06-07 15:37:47 -0700 |
---|---|---|
committer | Jez Ng <me@jezng.com> | 2013-06-19 01:22:01 -0700 |
commit | 2f16717540cbeaa8e2e6b653bc31849111ccd9f2 (patch) | |
tree | a67c388de9926a2f290cbef3228e0e0ab6f4943d /tools | |
parent | 165befaa29b7226b28caecd2f30bae91dc20f26f (diff) |
Add test for source maps.
Tweak behavior of post_build; the `post2` hook now expects a function.
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); } } |