Skip to content

Commit 48da3fe

Browse files
authored
Merge pull request #194 from ysk8hori/feat/specify-tsconfig
tsconfig を指定可能とする
2 parents c50528a + 21379fc commit 48da3fe

File tree

10 files changed

+87
-73
lines changed

10 files changed

+87
-73
lines changed

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,22 @@ npm install --global @ysk8hori/typescript-graph
7070

7171
## Options
7272

73-
| Option | Description |
74-
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
75-
| `-V, --version` | Output the version number |
76-
| `--md <char>` | Specify the name of the markdown file to be output. The default is typescript-graph.md. |
77-
| `--mermaid-link` | (experimental) Generates a link on a node to open the corresponding file in VSCode. |
78-
| `-d, --dir <char>` | Specify the TypeScript codebase to be analyzed. |
79-
| `--include <char...>` | Specify file paths or parts of file paths to include in the graph (relative to the tsconfig directory, without `./`). |
80-
| `--exclude <char...>` | Specify file paths or parts of file paths to exclude from the graph (relative to the tsconfig directory, without `./`). |
81-
| `--abstraction <char...>` | Specify the paths of directories to be abstracted. Abstracted directories are treated as a single node. |
82-
| `--highlight <char...>` | Specify the path and file names to be highlighted. |
83-
| `--LR` | Set the flowchart orientation to Left-to-Right. |
84-
| `--TB` | Set the flowchart orientation to Top-to-Bottom. |
85-
| `--measure-instability` | Enable the beta feature to measure the instability of modules. |
86-
| `--config-file` | Specify the relative path to the config file (from the current directory or as specified by -d, --dir). The default is .tsgrc.json. |
87-
| `-h, --help` | Display help for the command. |
73+
| Option | Description |
74+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
75+
| `-V, --version` | Output the version number |
76+
| `--md <char>` | Specify the name of the markdown file to be output. The default is typescript-graph.md. |
77+
| `--mermaid-link` | (experimental) Generates a link on a node to open the corresponding file in VSCode. |
78+
| `-d, --dir <char>` | Specifies the root directory of the TypeScript project to analyze. It reads and uses the tsconfig.json file found in this directory. |
79+
| `--tsconfig <char>` | Specifies the path to the tsconfig file to use for analysis. If this option is provided, -d, --dir will be ignored. |
80+
| `--include <char...>` | Specify file paths or parts of file paths to include in the graph (relative to the tsconfig directory, without `./`). |
81+
| `--exclude <char...>` | Specify file paths or parts of file paths to exclude from the graph (relative to the tsconfig directory, without `./`). |
82+
| `--abstraction <char...>` | Specify the paths of directories to be abstracted. Abstracted directories are treated as a single node. |
83+
| `--highlight <char...>` | Specify the path and file names to be highlighted. |
84+
| `--LR` | Set the flowchart orientation to Left-to-Right. |
85+
| `--TB` | Set the flowchart orientation to Top-to-Bottom. |
86+
| `--measure-instability` | Enable the beta feature to measure the instability of modules. |
87+
| `--config-file` | Specify the relative path to the config file (from the current directory or as specified by -d, --dir). The default is .tsgrc.json. |
88+
| `-h, --help` | Display help for the command. |
8889

8990
## usage
9091

docs/README_en.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,22 @@ npm install --global @ysk8hori/typescript-graph
7070

7171
## Options
7272

73-
| Option | Description |
74-
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
75-
| `-V, --version` | Output the version number |
76-
| `--md <char>` | Specify the name of the markdown file to be output. The default is typescript-graph.md. |
77-
| `--mermaid-link` | (experimental) Generates a link on a node to open the corresponding file in VSCode. |
78-
| `-d, --dir <char>` | Specify the TypeScript codebase to be analyzed. |
79-
| `--include <char...>` | Specify file paths or parts of file paths to include in the graph (relative to the tsconfig directory, without `./`). |
80-
| `--exclude <char...>` | Specify file paths or parts of file paths to exclude from the graph (relative to the tsconfig directory, without `./`). |
81-
| `--abstraction <char...>` | Specify the paths of directories to be abstracted. Abstracted directories are treated as a single node. |
82-
| `--highlight <char...>` | Specify the path and file names to be highlighted. |
83-
| `--LR` | Set the flowchart orientation to Left-to-Right. |
84-
| `--TB` | Set the flowchart orientation to Top-to-Bottom. |
85-
| `--measure-instability` | Enable the beta feature to measure the instability of modules. |
86-
| `--config-file` | Specify the relative path to the config file (from the current directory or as specified by -d, --dir). The default is .tsgrc.json. |
87-
| `-h, --help` | Display help for the command. |
73+
| Option | Description |
74+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
75+
| `-V, --version` | Output the version number |
76+
| `--md <char>` | Specify the name of the markdown file to be output. The default is typescript-graph.md. |
77+
| `--mermaid-link` | (experimental) Generates a link on a node to open the corresponding file in VSCode. |
78+
| `-d, --dir <char>` | Specifies the root directory of the TypeScript project to analyze. It reads and uses the tsconfig.json file found in this directory. |
79+
| `--tsconfig <char>` | Specifies the path to the tsconfig file to use for analysis. If this option is provided, -d, --dir will be ignored. |
80+
| `--include <char...>` | Specify file paths or parts of file paths to include in the graph (relative to the tsconfig directory, without `./`). |
81+
| `--exclude <char...>` | Specify file paths or parts of file paths to exclude from the graph (relative to the tsconfig directory, without `./`). |
82+
| `--abstraction <char...>` | Specify the paths of directories to be abstracted. Abstracted directories are treated as a single node. |
83+
| `--highlight <char...>` | Specify the path and file names to be highlighted. |
84+
| `--LR` | Set the flowchart orientation to Left-to-Right. |
85+
| `--TB` | Set the flowchart orientation to Top-to-Bottom. |
86+
| `--measure-instability` | Enable the beta feature to measure the instability of modules. |
87+
| `--config-file` | Specify the relative path to the config file (from the current directory or as specified by -d, --dir). The default is .tsgrc.json. |
88+
| `-h, --help` | Display help for the command. |
8889

8990
## usage
9091

docs/README_ja.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ npm install --global @ysk8hori/typescript-graph
7575
| `-V, --version` | バージョン番号を出力 |
7676
| `--md <char>` | 出力するMarkdownファイルの名前を指定します。デフォルトは typescript-graph.md です。 |
7777
| `--mermaid-link` | (experimental) ノードにリンクを生成し、そのファイルをVSCodeで開けるようにします。 |
78-
| `-d, --dir <char>` | 解析対象のTypeScriptコードベースを指定します。 |
78+
| `-d, --dir <char>` | 解析対象のTypeScriptプロジェクトのルートディレクトリを指定します。そこにある tsconfig.json を読み取り、解析します。 |
79+
| `--tsconfig <char>` | 解析に使用する tsconfig ファイルのパスを指定します。これが指定された場合、`-d, --dir` を無視します。 |
7980
| `--include <char...>` | グラフに含めるファイルパスやその一部を指定します(tsconfig ディレクトリからの相対パスで、`./`は不要です)。 |
8081
| `--exclude <char...>` | グラフから除外するファイルパスやその一部を指定します(tsconfig ディレクトリからの相対パスで、`./`は不要です)。 |
8182
| `--abstraction <char...>` | 抽象化したいディレクトリのパスを指定します。抽象化したディレクトリは一つのノードとして扱います。 |

integration.spec.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ beforeAll(() => {
1111
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
1212
});
1313

14+
// TODO 現状、--config-file で指定するパスは -d からの相対パスだが、将来的には -d をなくしたい。その移行のため --config-file での指定は、-d を無視したカレントディレクトリからの相対パスで設定ファイルを優先し、なければ -d からの相対パスで探すようにしたい。
15+
1416
test('run:sample', async () => {
15-
await $`ts-node -O '{\"module\": \"commonjs\"}' ./src/index.ts -d './dummy_project' --md ${filepath}`;
17+
await $`ts-node -O '{\"module\": \"commonjs\"}' ./src/index.ts --tsconfig './dummy_project/tsconfig.json' --md ${filepath}`;
1618

1719
const file = fs.readFileSync(filepath, { encoding: 'utf-8' });
1820
expect(file).toMatchInlineSnapshot(`
1921
"# TypeScript Graph
2022
2123
\`\`\`bash
22-
tsg -d ./dummy_project --md __tmp__/test.md
24+
tsg --tsconfig ./dummy_project/tsconfig.json --md __tmp__/test.md
2325
\`\`\`
2426
2527
\`\`\`mermaid
@@ -115,14 +117,14 @@ test('run:sample', async () => {
115117
});
116118

117119
test('run:sample:argument-include', async () => {
118-
await $`ts-node -O '{\"module\": \"commonjs\"}' ./src/index.ts includeFiles config -d './dummy_project' --md ${filepath}`;
120+
await $`ts-node -O '{\"module\": \"commonjs\"}' ./src/index.ts includeFiles config --tsconfig './dummy_project/tsconfig.json' --md ${filepath}`;
119121

120122
const file = fs.readFileSync(filepath, { encoding: 'utf-8' });
121123
expect(file).toMatchInlineSnapshot(`
122124
"# TypeScript Graph
123125
124126
\`\`\`bash
125-
tsg includeFiles config -d ./dummy_project --md __tmp__/test.md
127+
tsg includeFiles config --tsconfig ./dummy_project/tsconfig.json --md __tmp__/test.md
126128
\`\`\`
127129
128130
\`\`\`mermaid
@@ -203,14 +205,14 @@ test('run:sample:argument-include', async () => {
203205
});
204206

205207
test('run:sample:include', async () => {
206-
await $`ts-node -O '{\"module\": \"commonjs\"}' ./src/index.ts -d './dummy_project' --include includeFiles config --md ${filepath}`;
208+
await $`ts-node -O '{\"module\": \"commonjs\"}' ./src/index.ts --tsconfig './dummy_project/tsconfig.json' --include includeFiles config --md ${filepath}`;
207209

208210
const file = fs.readFileSync(filepath, { encoding: 'utf-8' });
209211
expect(file).toMatchInlineSnapshot(`
210212
"# TypeScript Graph
211213
212214
\`\`\`bash
213-
tsg -d ./dummy_project --include includeFiles config --md __tmp__/test.md
215+
tsg --tsconfig ./dummy_project/tsconfig.json --include includeFiles config --md __tmp__/test.md
214216
\`\`\`
215217
216218
\`\`\`mermaid
@@ -291,14 +293,14 @@ test('run:sample:include', async () => {
291293
});
292294

293295
test('run:sample:exclude', async () => {
294-
await $`ts-node -O '{\"module\": \"commonjs\"}' ./src/index.ts -d './dummy_project' --include includeFiles config --exclude excludeFiles utils --md ${filepath}`;
296+
await $`ts-node -O '{\"module\": \"commonjs\"}' ./src/index.ts --tsconfig './dummy_project/tsconfig.json' --include includeFiles config --exclude excludeFiles utils --md ${filepath}`;
295297

296298
const file = fs.readFileSync(filepath, { encoding: 'utf-8' });
297299
expect(file).toMatchInlineSnapshot(`
298300
"# TypeScript Graph
299301
300302
\`\`\`bash
301-
tsg -d ./dummy_project --include includeFiles config --exclude excludeFiles utils --md __tmp__/test.md
303+
tsg --tsconfig ./dummy_project/tsconfig.json --include includeFiles config --exclude excludeFiles utils --md __tmp__/test.md
302304
\`\`\`
303305
304306
\`\`\`mermaid
@@ -351,14 +353,14 @@ test('run:sample:exclude', async () => {
351353
});
352354

353355
test('run:sample:abstraction', async () => {
354-
await $`ts-node -O '{\"module\": \"commonjs\"}' ./src/index.ts -d './dummy_project' --include includeFiles config --exclude excludeFiles utils --abstraction abstractions --md ${filepath}`;
356+
await $`ts-node -O '{\"module\": \"commonjs\"}' ./src/index.ts --tsconfig './dummy_project/tsconfig.json' --include includeFiles config --exclude excludeFiles utils --abstraction abstractions --md ${filepath}`;
355357

356358
const file = fs.readFileSync(filepath, { encoding: 'utf-8' });
357359
expect(file).toMatchInlineSnapshot(`
358360
"# TypeScript Graph
359361
360362
\`\`\`bash
361-
tsg -d ./dummy_project --include includeFiles config --exclude excludeFiles utils --abstraction abstractions --md __tmp__/test.md
363+
tsg --tsconfig ./dummy_project/tsconfig.json --include includeFiles config --exclude excludeFiles utils --abstraction abstractions --md __tmp__/test.md
362364
\`\`\`
363365
364366
\`\`\`mermaid
@@ -402,14 +404,14 @@ test('run:sample:abstraction', async () => {
402404
});
403405

404406
test('run:sample:highlight', async () => {
405-
await $`ts-node -O '{\"module\": \"commonjs\"}' ./src/index.ts -d './dummy_project' --include includeFiles config --exclude excludeFiles utils --abstraction abstractions --highlight config.ts b.ts --md ${filepath}`;
407+
await $`ts-node -O '{\"module\": \"commonjs\"}' ./src/index.ts --tsconfig './dummy_project/tsconfig.json' --include includeFiles config --exclude excludeFiles utils --abstraction abstractions --highlight config.ts b.ts --md ${filepath}`;
406408

407409
const file = fs.readFileSync(filepath, { encoding: 'utf-8' });
408410
expect(file).toMatchInlineSnapshot(`
409411
"# TypeScript Graph
410412
411413
\`\`\`bash
412-
tsg -d ./dummy_project --include includeFiles config --exclude excludeFiles utils --abstraction abstractions --highlight config.ts b.ts --md __tmp__/test.md
414+
tsg --tsconfig ./dummy_project/tsconfig.json --include includeFiles config --exclude excludeFiles utils --abstraction abstractions --highlight config.ts b.ts --md __tmp__/test.md
413415
\`\`\`
414416
415417
\`\`\`mermaid

0 commit comments

Comments
 (0)