Nixinova / LinguistJS

Analyse and list all languages used in a folder. Implementation of and powered by GitHub's Linguist.
ISC License
35 stars 11 forks source link

CLI: `--analyze` for a sibling folder produces odd paths in output #3

Closed kachkaev closed 3 years ago

kachkaev commented 3 years ago

Hi again @Nixinova 👋

Just wanted to share a small observation, which should be a rather rare use case. I’ve got two folders, say my-analytics-tool and my-analytics-tool-data. The first folder contains uses linguist-cli as a dependency, while the second folder contains a repo I want to analyse.

Here is what I do:

cd /path/to/my-analytics-tool
yarn add linguist-js
yarn linguist --analyze ../my-analytics-tool-data --json

And here is what shows up in the output:

{
  "files": {
    "count": 2,
    "bytes": 0,
    "results": {
      ".-data/README.md": "Markdown",
      ".-data/example.js": "JavaScript"
    }
  },
  "languages": {
    "count": 2,
    "bytes": 0,
    "results": {
      "Markdown": { "type": "prose", "bytes": 0, "color": "#083fa1" },
      "JavaScript": { "type": "programming", "bytes": 0, "color": "#f1e05a" }
    }
  },
  "unknown": {
    "count": 0,
    "bytes": 0,
    "extensions": {},
    "filenames": {}
  }
}

As you can see, instead of proper relative or absolute paths, the output includes entries like ".-data/README.md". Perhaps, showing full paths would be the right thing to do given what the JS-imported version does. That would be:

{
  "files": {
    "results": {
      "/path/to/my-analytics-tool-data/README.md": "Markdown",
      "/path/to/my-analytics-tool-data/example.js": "JavaScript"
    }
}

I guess there could also be an option to render file paths relative to some specific root path.

Nixinova commented 3 years ago

Perhaps, showing full paths would be the right thing to do given what the JS-imported version does.

The latest commit should have done that: https://github.com/Nixinova/Linguist/commit/a01a3ed93b647d9cdbd4074fc0e6353deb110128, it just hasn't been published to npm yet. From the next version all --json output filenames will be absolute.

kachkaev commented 3 years ago

That's cool, thanks! Happy to test that out when a new version is published 🙂 The diff looks promising 👍

Nixinova commented 3 years ago

Try it now with v2.0.1.

kachkaev commented 3 years ago

Yep, it works 🎉 Thanks for your quick response 💯