Coder Social home page Coder Social logo

azu / express-router-dependency-graph Goto Github PK

View Code? Open in Web Editor NEW
38.0 2.0 3.0 152 KB

A static code analysis tool that creates a dependency graph for express routing.

License: MIT License

Shell 0.27% JavaScript 2.95% TypeScript 96.78%
node express dependency-graph visualize tool

express-router-dependency-graph's Introduction

express-router-dependency-graph

Create dependency graph for express routing.

Install

Install with npm:

npx express-router-dependency-graph "src/**/*.ts"

Usage

Usage
  $ express-router-dependency-graph [input]

Options
  --cwd                   [Path:String] current working directory. Default: process.cwd()
  --rootBaseUrl           [Path:String] if pass it, replace rootDir with rootDirBaseURL in output.
  --format                ["json" | "markdown"] output format. Default: markdown

Examples
  # analyze all ts files in src directory
  $ express-router-dependency-graph "src/**/*.ts"
  # analyze all ts files in src directory and output json
  $ express-router-dependency-graph "src/**/*.ts" --format=json
  # analyze all js and ts files in src directory
  $ express-router-dependency-graph "src/**/*.ts" "src/**/*.js"
  # change rootDir to rootDirBaseURL to output
  $ express-router-dependency-graph "src/**/*.ts" --rootBaseUrl="https://github.com/owner/repo/tree/master/src"
  # include node_modules
  # node_modules, dist, build, test, __tests__ are excluded by default
  $ express-router-dependency-graph "src/**/*.ts" --noDefaultExcludes

Example

Example output: --format=markdown

  • File: file path
  • Method: get | post | put | delete | use(express's use)
  • Routing: routing path name
  • Middlewares: used middlewares
    • Note: app.use("/test", () => { ... }) is shown "Anonymous Function" middleware
  • FilePath: source code position
File Method Routing Middlewares FilePath
src/game.ts
get /getGameById requireRead src/game.ts#L11-L12
get /getGameList requireRead src/game.ts#L13-L14
post /updateGameById requireWrite src/game.ts#L15-L16
delete /deleteGameById requireWrite src/game.ts#L17-L18
src/index.ts
use /user user src/index.ts#L8-L8
use /game game src/index.ts#L9-L9
src/user.ts
get /getUserById requireRead src/user.ts#L10-L11
get /getUserList requireRead src/user.ts#L12-L13
post /updateUserById requireWrite src/user.ts#L14-L15
delete /deleteUserById requireWrite src/user.ts#L16-L17

Example output: --format=json

[
  {
    filePath: "<root>/src/game.ts",
    routers: [
      {
        method: "get",
        path: "/getGameById",
        middlewares: ["requireRead"],
        range: [288, 338],
        loc: { start: { line: 11, column: 0 }, end: { line: 12, column: 2 } }
      },
      {
        method: "get",
        path: "/getGameList",
        middlewares: ["requireRead"],
        range: [340, 390],
        loc: { start: { line: 13, column: 0 }, end: { line: 14, column: 2 } }
      },
      {
        method: "post",
        path: "/updateGameById",
        middlewares: ["requireWrite"],
        range: [392, 447],
        loc: { start: { line: 15, column: 0 }, end: { line: 16, column: 2 } }
      },
      {
        method: "delete",
        path: "/deleteGameById",
        middlewares: ["requireWrite"],
        range: [449, 506],
        loc: { start: { line: 17, column: 0 }, end: { line: 18, column: 2 } }
      }
    ]
  },
  {
    filePath: "<root>/src/index.ts",
    routers: [
      {
        method: "use",
        path: "/user",
        middlewares: ["user"],
        range: [140, 162],
        loc: { start: { line: 8, column: 0 }, end: { line: 8, column: 22 } }
      },
      {
        method: "use",
        path: "/game",
        middlewares: ["game"],
        range: [164, 186],
        loc: { start: { line: 9, column: 0 }, end: { line: 9, column: 22 } }
      }
    ]
  },
  {
    filePath: "<root>/src/user.ts",
    routers: [
      {
        method: "get",
        path: "/getUserById",
        middlewares: ["requireRead"],
        range: [287, 337],
        loc: { start: { line: 10, column: 0 }, end: { line: 11, column: 2 } }
      },
      {
        method: "get",
        path: "/getUserList",
        middlewares: ["requireRead"],
        range: [339, 389],
        loc: { start: { line: 12, column: 0 }, end: { line: 13, column: 2 } }
      },
      {
        method: "post",
        path: "/updateUserById",
        middlewares: ["requireWrite"],
        range: [391, 446],
        loc: { start: { line: 14, column: 0 }, end: { line: 15, column: 2 } }
      },
      {
        method: "delete",
        path: "/deleteUserById",
        middlewares: ["requireWrite"],
        range: [448, 505],
        loc: { start: { line: 16, column: 0 }, end: { line: 17, column: 2 } }
      }
    ]
  }
]

Changelog

See Releases page.

Related

Running tests

Install devDependencies and Run npm test:

npm test

Add test case

  1. Add test case to test/snapshot/<test-name>/app.ts
  2. Run npm run updateSnspahots
  3. Check test/snapshot/<test-name>/output.{json,md}
  4. Commit it!

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT © azu

express-router-dependency-graph's People

Contributors

azu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

express-router-dependency-graph's Issues

No such file <path>/node_modules/es5-ext/array/index.js#/uniq.js

Hey azu!

Sorry if this is a newbie question, I'm new to Node!
I can't run express-router-dependency-graph neither installing globally with npm install express-router-dependency-graph -g nor with executing via npx: npx express-router-dependency-graph --rootDir=/home/user/Documents/project

What I get is:

Error: Extracting dependencies ran afoul of...

  ENOENT: no such file or directory, open '/home/user/Documents/project/node_modules/es5-ext/array/index.js#/uniq.js'
... in node_modules/es5-ext/array/index.js#/uniq.js


    at getDependencies (/home/user/.nvm/versions/node/v16.0.0/lib/node_modules/express-router-dependency-graph/node_modules/dependency-cruiser/src/extract/get-dependencies.js:208:11)
    at extractRecursive (/home/user/.nvm/versions/node/v16.0.0/lib/node_modules/express-router-dependency-graph/node_modules/dependency-cruiser/src/extract/index.js:20:9)
    at lDependencies.filter.reduce.source (/home/user/.nvm/versions/node/v16.0.0/lib/node_modules/express-router-dependency-graph/node_modules/dependency-cruiser/src/extract/index.js:36:13)
    at Array.reduce (<anonymous>)
    at extractRecursive (/home/user/.nvm/versions/node/v16.0.0/lib/node_modules/express-router-dependency-graph/node_modules/dependency-cruiser/src/extract/index.js:32:6)
    at lDependencies.filter.reduce.source (/home/user/.nvm/versions/node/v16.0.0/lib/node_modules/express-router-dependency-graph/node_modules/dependency-cruiser/src/extract/index.js:36:13)
    at Array.reduce (<anonymous>)
    at extractRecursive (/home/user/.nvm/versions/node/v16.0.0/lib/node_modules/express-router-dependency-graph/node_modules/dependency-cruiser/src/extract/index.js:32:6)
    at /home/user/.nvm/versions/node/v16.0.0/lib/node_modules/express-router-dependency-graph/node_modules/dependency-cruiser/src/extract/index.js:80:9
    at Array.reduce (<anonymous>)

but es5-ext is installed in node_modules and the path is like this:
image

Here are the dependencies of this project:

"dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "express": "^4.17.1",
    "express-validator": "^6.10.0",
    "passport": "^0.4.1",
    "pg": "^8.6.0",
    "sequelize": "^6.6.2"
  },
  "devDependencies": {
    "express-router-dependency-graph": "1.0.0",
    "nodemon": "^2.0.7",
    "prettier": "^2.2.1",
    "sequelize-cli": "^6.2.0"
  }

Any tips? Am I doing something wrong here?
Thanks a lot :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.