Socket
Book a DemoInstallSign in
Socket

react-to-uml

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-to-uml

Visualize your react components tree with uml diagram

1.0.5
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

react-to-uml logo

react-to-uml

Visualize your react components tree with uml diagram

It is appropriate to your project if it uses babel and webpack.

Install

npm i react-to-uml

Connect to your project

// webpack.base.ts
import { makePlugins } from 'react-to-uml';

const rootPath = process.cwd();
const packagesPaths = new RegExp(rootPath + '/(packages)');
const entryFileName = rootPath + '/packages/app/client.js';
const gatheredComponentsFileName = `${rootPath}/build/assets/gatheredComponentsByFileName.json`;
const outUmlFileName = `${rootPath}/build/assets/treeComponentsUML.json`;

const { babelPlugin, webpackPlugin } = makePlugins({
  packagesPaths,
  entryFileName,
  gatheredComponentsFileName,
  outUmlFileName,
});

export default {
  entry: './packages/app/client.js',
  plugins: [new HtmlWebpackPlugin({ template: './public/index.html' }), webpackPlugin],
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'build'),
  },
  resolve: {
    extensions: ['.js', '.jsx', '.ts', '.tsx', '...'],
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx|ts|tsx)$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            plugins: [babelPlugin],
            presets: [
              ['@babel/preset-typescript'],
              ['@babel/preset-react', { runtime: 'automatic' }],
              ['@babel/preset-env'],
            ],
          },
        },
      },
    ],
  },
} as Configuration;

After build your project

  • You will get the treeComponentsUML.uml file where will be stored your diagram
  • On a small project, you can test it here
  • But to visualize it for the real project the simplest way is to use the plantUML java library
  • Download the jar file here
  • Download the graphviz it is needed for the kind of diagrams generated by the library
  • Run java -Xmx2G -jar plantuml-1.2023.11.jar ./build/assets/treeComponentsUML.uml -tsvg -verbose -t4 (more CLI params here)
  • Use your svg file. It is possible to render other formats (more CLI params here)

Extra options

acceptableExts?: string[];

by default ['jsx', 'js', 'tsx', 'ts'] - files in which library will looking for the jsx

isGroupByParentDirNeeded?: boolean;

by default false - grouping your components by root dir, e.g. for monorepo with packages root dir it will group it like in the picture below

image

repetitiveCountForRemoveFromTree?: number;

by default 4 - to adjust your zoom of view, components with a count of repetitive more than this param will be removed from the diagram.

Troubleshooting

To turn on extra logs in this library use --debug with your build script.

npm run build --debug

What is next?

Once you gathered the data from your code base, just imagine what you could do in the next step. This library right now just organizes the process of traverse, so it is possible to add logic into the library and gather extra data on the way like:

  • Test coverage for each file and component
  • Size of your files and components
  • Component names into files (if you use an approach with multiple components in one file)
  • Something else
  • Render it with the interactive like d3.js with the real-time input search filter, and highlights of the arcs when you select one of the nodes

Keywords

react-components-tree

FAQs

Package last updated on 05 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.