-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assorted changes to webtreemap CLI tool #35
Changes from 1 commit
7962c2d
659682c
0a0717b
0ddb08d
98f350b
a00c8be
38f1360
990d5b2
54ec5d5
a9557b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ | |
|
||
import {Command} from 'commander'; | ||
import * as fs from 'fs'; | ||
import open from 'open'; | ||
import * as readline from 'readline'; | ||
import * as tmp from 'tmp'; | ||
|
||
import * as tree from './tree'; | ||
|
||
|
@@ -95,6 +97,12 @@ function humanSizeCaption(n: tree.Node): string { | |
return `${n.id || ''} (${size.toFixed(1)}${units[unit]})`; | ||
} | ||
|
||
function writeToTempFile(contents: string): string { | ||
const filename = tmp.tmpNameSync(); | ||
fs.writeFileSync(filename, contents, { encoding: 'utf-8' }); | ||
return filename; | ||
} | ||
|
||
async function main() { | ||
const args = new Command() | ||
.description( | ||
|
@@ -141,8 +149,10 @@ body { | |
`; | ||
if (args.output) { | ||
fs.writeFileSync(args.output, output, {encoding: 'utf-8'}); | ||
} else { | ||
} else if (!process.stdout.isTTY) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is better expressed as some sort of flag, because otherwise you run into weird behaviors where like How about: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can do that, but what would happen in your ssh session? Would it just fail? The |
||
console.log(output); | ||
} else { | ||
open(writeToTempFile(output)); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrrmm. We run this in Google and probably don't have these packages.
What's the alternative? Can you make this an optional dependency? (E.g. only import if opening in a browser?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow, I can only imagine how
//third_party/node_modules
works...tmp
, I can write something custom usingos.tmpdir
to sever the dependency.open
I can switch to a dynamic import.