A static code analysis tool that creates a dependency graph for express routing.
MIT License
Create dependency graph for express routing.
Install with npm:
npx express-router-dependency-graph "src/**/*.ts"
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 output: --format=markdown
use
(express's use)app.use("/test", () => { ... })
is shown "Anonymous Function" middlewareFile | 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 } }
}
]
}
]
See Releases page.
Install devDependencies and Run npm test
:
npm test
test/snapshot/<test-name>/app.ts
npm run updateSnspahots
test/snapshot/<test-name>/output.{json,md}
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT © azu