-
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
Conversation
package.json
Outdated
@@ -20,7 +20,7 @@ | |||
"test": "echo \"Error: no test specified\" && exit 1", | |||
"fmt": "prettier --write src/*.ts demo/*.ts *.md", | |||
"build": "tsc && webpack -p", | |||
"demo": "du -ab node_modules/ | node build/src/cli.js --title 'node_modules for webtreemap' > docs/index.html" | |||
"demo": "du -a node_modules/ | awk '{print $1*512 \"\t\" $2}' | node build/src/cli.js --title 'node_modules for webtreemap' > docs/index.html" |
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.
So gross! But so it goes. I wonder if there's some alternative to du on OS X that shows bytes?
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.
This is the closest I can find:
find . -type f -ls | awk '{ print $7, $11 }'
Does that work on Linux? It feels fragile.
@@ -115,12 +115,21 @@ async function main() { | |||
let output = `<!doctype html> | |||
<title>${title}</title> | |||
<style> | |||
html, body { | |||
height: 100%; |
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.
The reason I hadn't done this in the past is that it doesn't resize on window resize. But I guess it's better than nothing.
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.
I pushed a commit to track resizes.
"commander": "^2.11.0" | ||
"commander": "^2.11.0", | ||
"open": "^7.2.1", | ||
"tmp": "^0.2.1" |
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...
- For
tmp
, I can write something custom usingos.tmpdir
to sever the dependency. - For
open
I can switch to a dynamic import.
@@ -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 comment
The 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 foo | cat
has different behavior than foo
.
How about: -o somefile.html
writes to a file, otherwise always open in 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.
I can do that, but what would happen in your ssh session? Would it just fail? The foo | cat
vs. foo
behavior actually makes sense to me. You see this all the time, e.g. with jq, jq . foo.json
pretty-prints a JSON file with color to your terminal, but jq . foo.json | cat
drops the color unless you specifically ask for it.
package.json
Outdated
"webpack": "^3.7.1" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"fmt": "prettier --write src/*.ts demo/*.ts *.md", | ||
"build": "tsc && webpack -p", | ||
"demo": "du -a node_modules/ | awk '{print $1*512 \"\t\" $2}' | node build/src/cli.js --title 'node_modules for webtreemap' > docs/index.html" | ||
"demo": "du -a node_modules/ | awk '{print $1*512 \"\t\" $2}' | node build/src/cli.js --title 'node_modules for webtreemap'" |
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.
Prolly should be in previous commit, but I don't care too much.
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.
You should use Squash & Merge and not worry about PR branch commits :)
This looks really great. I left a bunch of unimportant comments, and the only important one is that I think we should kill the stdout behavior, defaulting to always opening in browser unless a flag is passed or something. (I do all my work via ssh so the browser-opening bit isn't gonna work for me anyway which means I never felt the need for it, so thanks for adding it.) |
Thanks @evmar. I pushed a commit to handle resizes. Let me know if you're confident about the stdout change and I'll implement it. |
Filed #37 about properly integrating this. |
I wound up forking, these improvements are available in the |
Several changes to make the CLI tool more useful:
1
. This allows, for example,find . -type f | webtreemap
.I also updated TypeScript and a few dependencies and removed some helper functions and used built-ins instead.