Skip to content

Commit

Permalink
Merge pull request danvk#18 from Hypercubed/feature/tsv
Browse files Browse the repository at this point in the history
Option to output tsv file
  • Loading branch information
danvk committed Oct 23, 2015
2 parents 92fc7d2 + 44c6819 commit 2c80940
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var doc = [
'',
'Usage:',
' source-map-explorer <script.js> [<script.js.map>]',
' source-map-explorer [--json | --html] <script.js> [<script.js.map>] [--replace=BEFORE --with=AFTER]... [--noroot]',
' source-map-explorer [--json | --html | --tsv] <script.js> [<script.js.map>] [--replace=BEFORE --with=AFTER]... [--noroot]',
' source-map-explorer -h | --help | --version',
'',
'If the script file has an inline source map, you may omit the map parameter.',
Expand All @@ -16,6 +16,8 @@ var doc = [
'',
' --json Output JSON (on stdout) instead of generating HTML',
' and opening the browser.',
' --tsv Output TSV (on stdout) instead of generating HTML',
' and opening the browser.',
' --html Output HTML (on stdout) rather than opening a browser.',
'',
' --noroot To simplify the visualization, source-map-explorer',
Expand All @@ -29,7 +31,6 @@ var doc = [
' --with=AFTER See --replace.',
].join('\n');


var fs = require('fs'),
path = require('path'),
sourcemap = require('source-map'),
Expand Down Expand Up @@ -110,7 +111,7 @@ function loadSourceMap(jsFile, mapFile) {
// See http:https://stackoverflow.com/a/1917041/388951
function commonPathPrefix(array){
if (array.length == 0) return '';
var A= array.concat().sort(),
var A= array.concat().sort(),
a1= A[0].split(/(\/)/), a2= A[A.length-1].split(/(\/)/), L= a1.length, i= 0;
while(i<L && a1[i] === a2[i]) i++;
return a1.slice(0, i).join('');
Expand Down Expand Up @@ -184,6 +185,12 @@ if (args['--json']) {
process.exit(0);
}

if (args['--tsv']) {
console.log('Source\tSize');
_.map(sizes, function(v, k) { console.log(k+'\t'+v); })
process.exit(0);
}

var html = fs.readFileSync(path.join(__dirname, 'tree-viz.html')).toString();

html = html.replace('INSERT TREE HERE', JSON.stringify(sizes, null, ' '))
Expand Down

0 comments on commit 2c80940

Please sign in to comment.