antoine-coulon / skott

All-in-one devtool to automatically analyze, search and visualize project modules and dependencies from JavaScript, TypeScript (JSX/TSX) and Node.js (ES6, CommonJS)
MIT License
669 stars 25 forks source link

allow group-by config via cli #176

Closed xaota closed 1 month ago

xaota commented 1 month ago

Summary

skott-group-by-config.js

const groupBy = (path) => {
  if (path.includes("core")) return "core";
  if (path.includes("feature-a")) return "feature-a";

  return undefined;
};

export default groupBy;
$ skott --groupBy="./skott-group-by-config.js" src/index.js

Details

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
Would you consider contributing a PR?
antoine-coulon commented 1 month ago

Hello @xaota,

As mentioned in the docs not all the features can be exposed directly from the CLI. Nonetheless groupBy option can be used via the API, that can be invoked in a CLI-ish way, with the same rendering as if it was run from the CLI (thanks to skott/rendering module).

So you can have

skott.mjs

import skott, { defaultConfig } from "skott";
// Should be imported as "skott/rendering" when being in a third-party context
import { Terminal } from "skott/rendering";

Terminal.renderTerminalApplication(
    {
      ...defaultConfig,
      groupBy: // insert you groupBy configuration here
    },
    {
      displayMode: "graph",
      exitCodeOnCircularDependencies: 1,
      showCircularDependencies: true,
      showUnusedDependencies: true,
      showUnusedFiles: false,
      watch: true
    }
)

Then you can have a npm script such as "skott": "node skott.mjs" and just run npm run skott from your CLI

antoine-coulon commented 1 month ago

Closing this as the CLI won't be embedding groupBy option anytime soon, given that it's available using the API