Skip to content

Commit 40245db

Browse files
authored
Merge pull request #38 from Himenon/feat/add-native-dot-engine
feat: add `--engine` which use native graphviz engine
2 parents 6098c29 + b75167f commit 40245db

File tree

36 files changed

+390
-190
lines changed

36 files changed

+390
-190
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,20 @@ private_npm_cache
1111
buildcache/
1212
bin/*.js
1313
.npmrc
14+
15+
### packages/cli
16+
17+
packages/cli/lib
18+
packages/cli/coverage
19+
packages/cli/node_modules
20+
packages/cli/package-lock.json
21+
packages/cli/.env*
22+
packages/cli/*.log
23+
packages/cli/private_npm_cache
24+
packages/cli/data/
25+
packages/cli/dist/
26+
packages/cli/output
27+
28+
### packages/view
29+
30+
packages/view/dist

.prettierignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44

55
docs
66

7+
### packages/cli
8+
9+
packages/cli/lib
10+
packages/cli/coverage
11+
packages/cli/node_modules
12+
packages/cli/package-lock.json
13+
packages/cli/.env*
14+
packages/cli/*.log
15+
packages/cli/private_npm_cache
16+
packages/cli/data/
17+
packages/cli/dist/
18+
packages/cli/output
19+
20+
### packages/view
21+
22+
packages/view/dist
23+
724
### Node ###
825
# Logs
926
logs

packages/cli/.gitignore

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/cli/.prettierignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/cli/README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ code-dependency --source ./src
88

99
## Option
1010

11-
**-s --source** (required)
11+
### -s --source\*\* (required)
1212

1313
Source directory path
1414

@@ -17,7 +17,7 @@ code-dependency --source ./src
1717
code-dependency --source /home/app/src
1818
```
1919

20-
**-p --port**
20+
### -p --port
2121

2222
Server port number (default 3000).
2323

@@ -26,15 +26,15 @@ code-dependency --source ./src --p 4000
2626
code-dependency --source ./src --port 4000
2727
```
2828

29-
**--ts-config**
29+
### --ts-config
3030

3131
`tsconfig.json` path. [see](https://github.com/sverweij/dependency-cruiser/blob/develop/doc/cli.md#--ts-config-use-a-typescript-configuration-file-project)
3232

3333
```bash
3434
code-dependency --source ./src --ts-config ./tsconfig.json
3535
```
3636

37-
**--webpack-config**
37+
### --webpack-config
3838

3939
`webpack.config.js` path. (JavaScript only) [see](https://github.com/sverweij/dependency-cruiser/blob/develop/doc/cli.md#--webpack-config-use-the-resolution-options-of-a-webpack-configuration)
4040

@@ -43,23 +43,23 @@ code-dependency --source ./src --webpack-config webpack.config.js
4343
code-dependency --source ./src --webpack-config your.config.js
4444
```
4545

46-
**--exclude**
46+
### --exclude
4747

4848
cruise ignore pattern (default: "node_modules"). [see](https://github.com/sverweij/dependency-cruiser/blob/develop/doc/cli.md#--exclude-exclude-dependencies-from-being-cruised)
4949

5050
```bash
5151
code-dependency --source ./src --exclude node_modules
5252
```
5353

54-
**--export-static**
54+
### --export-static
5555

5656
generate static site.
5757

5858
```bash
5959
code-dependency --source ./src --exclude node_modules --export-static ./docs
6060
```
6161

62-
**--public-path**
62+
### --public-path
6363

6464
```bash
6565
code-dependency --source ./src --exclude node_modules --export-static ./docs --public-path /docs
@@ -79,7 +79,17 @@ Directory Structure
7979
└── src // `--source` target : Browser entrypoint -> /project/src/index.html
8080
```
8181

82-
**--dry-run** (experimental)
82+
### --engine
83+
84+
Use native graphviz engine. (https://www.graphviz.org/)
85+
86+
Option: `dot` (recommended)
87+
88+
```bash
89+
code-dependency --source ./src --exclude node_modules --export-static ./docs --public-path /docs --engine dot
90+
```
91+
92+
### --dry-run (experimental)
8393

8494
if failed generate static file and retry generate static file only unfinished path.
8595

packages/cli/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"export:static": "node ./bin/code-dependency.js --source ./src --exclude node_modules --export-static ./output --public-path http://localhost:5000/output",
3737
"generate:docs": "node ./bin/code-dependency.js --source ./src --exclude node_modules --export-static ../../docs --public-path https://himenon.github.io/code-dependency/",
3838
"server": "nodemon ./bin/code-dependency.js --source ./src --exclude node_modules",
39+
"server2": "nodemon ./bin/code-dependency.js --source ./src --engine dot --exclude node_modules",
3940
"start": "run-p develop server",
4041
"test": "jest -c jest.config.json && yarn export:static",
4142
"test:ci": "jest -c jest.config.json --no-cache --ci && yarn export:static",
@@ -60,6 +61,7 @@
6061
"recursive-readdir": "^2.2.2",
6162
"resolve-pkg": "^2.0.0",
6263
"rimraf": "^3.0.1",
64+
"tempfile": "^3.0.0",
6365
"tsconfig": "^7.0.0",
6466
"urljoin": "^0.1.5"
6567
},
@@ -71,7 +73,8 @@
7173
"@types/pretty": "^2.0.0",
7274
"@types/react": "^16.9.19",
7375
"@types/react-dom": "^16.9.5",
74-
"@types/rimraf": "^2.0.3"
76+
"@types/rimraf": "^2.0.3",
77+
"@types/tempfile": "^3.0.0"
7578
},
7679
"publishConfig": {
7780
"access": "public"

packages/cli/src/cli/PathFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const create = ({ context = process.cwd(), source }: Params) => {
2222
original: source,
2323
binRelativePath: path.relative(__dirname, source),
2424
rootDir: path.dirname(absolutePath),
25-
rootAbsolutePath: absolutePath,
25+
absoluteRootPath: absolutePath,
2626
};
2727
};
2828

packages/cli/src/cli/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import commander from "commander";
2-
import { SourcePathInvalidError } from "../exceptions";
2+
import { SourcePathInvalidError, CliArgumentError } from "../exceptions";
33
import * as PathFactory from "./PathFactory";
44

55
const isInvalidPath = require("is-invalid-path");
@@ -13,6 +13,7 @@ interface CLIArguments {
1313
exportStatic?: PathFactory.Type;
1414
publicPath?: string;
1515
dryRun: boolean;
16+
engine?: "dot";
1617
}
1718

1819
export const validateCliArguments = (args: commander.Command): CLIArguments => {
@@ -22,6 +23,12 @@ export const validateCliArguments = (args: commander.Command): CLIArguments => {
2223
if (args["tsConfig"] && isInvalidPath(args["source"])) {
2324
throw new SourcePathInvalidError("`--source` arguments does not selected.");
2425
}
26+
if ("exportStatic" in args && typeof args["exportStatic"] !== "string") {
27+
throw new CliArgumentError("`--export-static` require 1 string argument.");
28+
}
29+
if ("publicPath" in args && typeof args["publicPath"] !== "string") {
30+
throw new CliArgumentError("`--public-path` require 1 string argument.");
31+
}
2532
return {
2633
source: PathFactory.create({ source: args["source"] }),
2734
port: args["port"],
@@ -31,6 +38,7 @@ export const validateCliArguments = (args: commander.Command): CLIArguments => {
3138
exportStatic: args["exportStatic"] && PathFactory.create({ source: args["exportStatic"] }),
3239
publicPath: args["publicPath"],
3340
dryRun: !!args["dryRun"],
41+
engine: args["engine"] === "dot" ? "dot" : undefined,
3442
};
3543
};
3644

@@ -45,6 +53,7 @@ export const executeCommandLine = (): CLIArguments => {
4553
.option("--export-static [static directory]", "static file hosting directory")
4654
.option("--public-path [host public path]", "the base path for all the assets")
4755
.option("--dry-run", "only use --export-static option")
56+
.option("--engine <dot>", "already local installed graphviz. <https://www.graphviz.org/>")
4857
.parse(process.argv);
4958
return validateCliArguments(commander);
5059
};

packages/cli/src/config/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from "path";
22
import { FilePathObject } from "@code-dependency/view";
33

44
export interface Type {
5+
rendererType: "client" | "server";
56
server: {
67
port: number;
78
};
@@ -11,8 +12,16 @@ export interface Type {
1112
filePathList: FilePathObject[];
1213
}
1314

14-
export const create = (port: number, absoluteRootPath: string, filePathList: FilePathObject[]): Type => {
15+
export interface Params {
16+
rendererType: "client" | "server";
17+
port: number;
18+
absoluteRootPath: string;
19+
filePathList: FilePathObject[];
20+
}
21+
22+
export const create = ({ rendererType, port, absoluteRootPath, filePathList }: Params): Type => {
1523
return {
24+
rendererType,
1625
server: {
1726
port,
1827
},

packages/cli/src/constants/router.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
export const routes = {
2+
index: {
3+
path: "/",
4+
},
25
project: {
36
path: "/project",
47
},

0 commit comments

Comments
 (0)