Skip to content

Commit 1e0822a

Browse files
authored
Merge pull request #29 from Himenon/add-cli-option
feat: add exclude,webpack options
2 parents b8f5085 + dc7de50 commit 1e0822a

File tree

15 files changed

+90
-32
lines changed

15 files changed

+90
-32
lines changed

.lintstagedrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"*.{js,jsx,json,yml,yaml,html}": ["prettier --write", "git add"],
3-
"*.{ts,tsx}": ["yarn run format", "yarn run lint", "git add"],
2+
"*.{js,jsx,json,yml,yaml,html,md}": ["prettier --write", "git add"],
3+
"*.{ts,tsx}": ["yarn format", "prettier --write", "git add"],
44
"package.json": ["sort-package-json", "git add"]
55
}

CHANGELOG.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

66
<a name="0.3.3"></a>
7+
78
## 0.3.3 (2020-01-07)
89

910
**Note:** Version bump only for package code-dependency
1011

11-
12-
13-
14-
1512
<a name="0.3.2"></a>
1613

1714
## 0.3.2 (2020-01-07)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ code-dependency --source ./src
1313
# open localhost:3000
1414
```
1515

16+
see [other option](./packages/cli/README.md#option).
17+
1618
![code dependency usage image](./docs/code-dependency-image.png)
1719

1820
## Core development UI / APi

lerna.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@
1111
"publish": {
1212
"access": "public",
1313
"allowBranch": "master",
14-
"ignoreChanges": [
15-
"CHANGELOG.md"
16-
]
14+
"ignoreChanges": ["CHANGELOG.md"]
1715
}
1816
},
19-
"packages": [
20-
"packages/*"
21-
],
17+
"packages": ["packages/*"],
2218
"version": "0.3.3",
2319
"npmClient": "yarn",
2420
"registry": "https://registry.npmjs.org/",

packages/cli/CHANGELOG.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

66
<a name="0.3.3"></a>
7+
78
## 0.3.3 (2020-01-07)
89

910
**Note:** Version bump only for package @code-dependency/cli
1011

11-
12-
13-
14-
1512
<a name="0.3.2"></a>
1613

1714
## 0.3.2 (2020-01-07)

packages/cli/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,51 @@
66
code-dependency --source ./src
77
```
88

9+
## Option
10+
11+
**-s --source** (required)
12+
13+
Source directory path
14+
15+
```bash
16+
code-dependency --source ./src
17+
code-dependency --source /home/app/src
18+
```
19+
20+
**-p --port**
21+
22+
Server port number (default 3000).
23+
24+
```bash
25+
code-dependency --source ./src --p 4000
26+
code-dependency --source ./src --port 4000
27+
```
28+
29+
**--ts-config**
30+
31+
`tsconfig.json` path. [see](https://github.com/sverweij/dependency-cruiser/blob/develop/doc/cli.md#--ts-config-use-a-typescript-configuration-file-project)
32+
33+
```bash
34+
code-dependency --source ./src --ts-config ./tsconfig.json
35+
```
36+
37+
**--webpack-config**
38+
39+
`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)
40+
41+
```bash
42+
code-dependency --source ./src --webpack-config webpack.config.js
43+
code-dependency --source ./src --webpack-config your.config.js
44+
```
45+
46+
**--exclude**
47+
48+
cruise ignore pattern (default: "node_modules"). [see](https://github.com/sverweij/dependency-cruiser/blob/develop/doc/cli.md#--exclude-exclude-dependencies-from-being-cruised)
49+
50+
```bash
51+
code-dependency --source ./src --exclude node_modules
52+
```
53+
954
## License
1055

1156
@code-dependency/cli is [MIT licensed](https://github.com/Himenon/code-dependency/blob/master/LICENSE).

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"build:webpack": "webpack --config ./scripts/build.ts",
3434
"clean": "rimraf ./lib ./build ./dist",
3535
"develop": "cross-env NODE_ENV=development yarn build:webpack --watch",
36-
"server": "nodemon ./bin/code-dependency.js --source ./src",
36+
"server": "nodemon ./bin/code-dependency.js --source ./src --exclude node_modules",
3737
"start": "run-p develop server",
3838
"test": "jest -c jest.config.json",
3939
"test:depcruise": "depcruise --validate .dependency-cruiser.json src",

packages/cli/scripts/webpack.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const generateConfig = ({ isProduction }: Option): webpack.Configuration[
4747
new ProgressBarPlugin(),
4848
new FriendlyErrorsWebpackPlugin(),
4949
new webpack.DefinePlugin({
50+
"process.env.NODE_ENV": JSON.stringify("production"),
5051
"process.env.isProduction": JSON.stringify(isProduction),
5152
"process.env.VERSION": JSON.stringify(require("../package.json").version),
5253
}),

packages/cli/src/cli/PathFactory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export const convertSourceToAbsolutePath = (source: string, context: string = pr
1919
export const create = ({ context = process.cwd(), source }: Params) => {
2020
const absolutePath = convertSourceToAbsolutePath(source);
2121
return {
22+
original: source,
23+
binRelativePath: path.relative(__dirname, source),
2224
rootDir: path.dirname(absolutePath),
2325
rootAbsolutePath: absolutePath,
2426
};

packages/cli/src/cli/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,35 @@ const isInvalidPath = require("is-invalid-path");
77
interface CLIArguments {
88
source: PathFactory.Type;
99
port: number;
10-
tsconfig?: PathFactory.Type;
10+
tsConfig?: PathFactory.Type;
11+
exclude?: string;
12+
webpackConfig?: PathFactory.Type;
1113
}
1214

1315
export const validateCliArguments = (args: commander.Command): CLIArguments => {
1416
if (typeof args["source"] !== "string" || isInvalidPath(args["source"])) {
1517
throw new SourcePathInvalidError("`--source` arguments does not selected.");
1618
}
17-
if (args["tsconfig"] && isInvalidPath(args["source"])) {
19+
if (args["tsConfig"] && isInvalidPath(args["source"])) {
1820
throw new SourcePathInvalidError("`--source` arguments does not selected.");
1921
}
2022
return {
2123
source: PathFactory.create({ source: args["source"] }),
2224
port: args["port"],
23-
tsconfig: args["tsconfig"] && PathFactory.create({ source: args["tsconfig"] }),
25+
tsConfig: args["tsConfig"] && PathFactory.create({ source: args["tsConfig"] }),
26+
exclude: args["exclude"],
27+
webpackConfig: args["webpackConfig"] && PathFactory.create({ source: args["webpackConfig"] }),
2428
};
2529
};
2630

2731
export const executeCommandLine = (): CLIArguments => {
2832
commander
2933
.version(process.env.VERSION!) // add webpack.DefinePlugin
30-
.option("-s --source [value]", "Source Directory or File")
31-
.option("-p --port [value]", "Port number", 3000)
32-
.option("--tsconfig [value]", "tsconfig.json path", undefined)
34+
.option("-s --source [directory]", "Source directory")
35+
.option("-p --port [number]", "Port number", 3000)
36+
.option("--ts-config [path]", "tsconfig.json path", undefined)
37+
.option("--webpack-config [path]", "webpack.config.js path (only js file)")
38+
.option("--exclude [string pattern]", "cruise exclude pattern", "node_modules")
3339
.parse(process.argv);
3440
return validateCliArguments(commander);
3541
};

0 commit comments

Comments
 (0)