Skip to content
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

Closed
wants to merge 10 commits into from

Conversation

danvk
Copy link

@danvk danvk commented Sep 7, 2020

Several changes to make the CLI tool more useful:

  • Write to a temp file and open the browser by default instead of printing HTML to stdout. If you pipe the output to a file, it will still write HTML to stdout.
  • Make the treemap fullscreen (previously it was hard-coded as 800x600).
  • If the number is omitted in an input line, it is assumed to be 1. This allows, for example, find . -type f | webtreemap.
  • Read lines from a file instead of stdin, if provided.
  • Prefer integers for unit-less values, i.e. "1" instead of "1.0" (but still "1.0k").

I also updated TypeScript and a few dependencies and removed some helper functions and used built-ins instead.

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"
Copy link
Owner

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?

Copy link
Author

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%;
Copy link
Owner

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.

Copy link
Author

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"
Copy link
Owner

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?)

Copy link
Author

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 using os.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) {
Copy link
Owner

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?

Copy link
Author

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'"
Copy link
Owner

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.

Copy link
Author

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 :)

@evmar
Copy link
Owner

evmar commented Sep 8, 2020

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.)

@danvk
Copy link
Author

danvk commented Sep 8, 2020

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.

@evmar
Copy link
Owner

evmar commented Oct 20, 2020

Filed #37 about properly integrating this.

@danvk
Copy link
Author

danvk commented Sep 5, 2021

I wound up forking, these improvements are available in the webtreemap-cli npm package: https://www.npmjs.com/package/webtreemap-cli

@danvk danvk closed this Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants