Skip to content

Commit b664992

Browse files
committed
refactor(models): dir のみオプションではなくする
1 parent 4ad5bab commit b664992

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

src/graph/createGraph.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ import { Graph, Meta, Node, OptionValues, Relation } from '../models';
44
import { pipe, piped } from 'remeda';
55

66
export function createGraph(
7-
dir: string,
87
/**
98
* exclude で指定されたファイルの除外のみファイル読み込み時にも実施する。
109
*
1110
* include をによる絞り込みを行わない理由は、include から参照される include 指定されていないファイルをここで除外したくないため。
1211
* exclude は、ユーザーが明確に不要と指定しているため、たとえ include に含まれたり include 対象ファイルと関連をもつファイルであったとしても除外して良い。
1312
**/
14-
opt: Partial<Pick<OptionValues, 'exclude'>>,
13+
opt: Pick<OptionValues, 'exclude' | 'dir' | 'tsconfig'>,
1514
): { graph: Graph; meta: Meta } {
16-
const configPath = ts.findConfigFile(dir, ts.sys.fileExists);
15+
const configPath = ts.findConfigFile(opt.dir!, ts.sys.fileExists);
1716
if (!configPath) {
1817
throw new Error('Could not find a valid "tsconfig.json".');
1918
}

src/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ program
3333
)
3434
.option(
3535
'-d, --dir <char>',
36-
'Specify the TypeScript code base to be analyzed. if tsconfig.json is not found, specify the directory where tsconfig.json is located.',
36+
'Specifies the root directory of the TypeScript project to analyze. It reads and uses the tsconfig.json file found in this directory.',
3737
)
3838
.option(
3939
'--include <char...>',
@@ -66,12 +66,13 @@ opt.include = [...program.args, ...(opt.include ?? [])];
6666
opt.include = opt.include.length === 0 ? undefined : opt.include;
6767

6868
export async function main(
69-
dir: string,
70-
commandOptions: typeof opt & { executedScript: string },
69+
commandOptions: OptionValues & { executedScript: string },
7170
) {
72-
setupConfig(path.join(dir, commandOptions.configFile ?? '.tsgrc.json'));
71+
setupConfig(
72+
path.join(commandOptions.dir, commandOptions.configFile ?? '.tsgrc.json'),
73+
);
7374

74-
const { graph: fullGraph, meta } = createGraph(dir, commandOptions);
75+
const { graph: fullGraph, meta } = createGraph(commandOptions);
7576

7677
let couplingData: ReturnType<typeof measureInstability> = [];
7778
if (commandOptions.measureInstability) {
@@ -103,7 +104,5 @@ export async function main(
103104
couplingData,
104105
);
105106
}
106-
107-
const dir = path.resolve(opt.dir ?? './');
108107
const executedScript = `tsg ${process.argv.slice(2).join(' ')}`;
109-
main(dir, { ...opt, executedScript });
108+
main({ ...opt, dir: path.resolve(opt.dir ?? './'), executedScript });

src/mermaidify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type DirAndNodesTree = {
88
nodes: Node[];
99
children: DirAndNodesTree[];
1010
};
11-
type Options = Partial<OptionValues> & {
11+
type Options = OptionValues & {
1212
rootDir: string;
1313
};
1414

src/models.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
export type OptionValues = {
2-
md: string;
3-
mermaidLink: boolean;
2+
md?: string;
3+
mermaidLink?: boolean;
44
dir: string;
5-
include: string[];
6-
exclude: string[];
7-
abstraction: string[];
8-
highlight: string[];
9-
LR: boolean;
10-
TB: boolean;
11-
configFile: string;
12-
measureInstability: boolean;
5+
include?: string[];
6+
exclude?: string[];
7+
abstraction?: string[];
8+
highlight?: string[];
9+
LR?: boolean;
10+
TB?: boolean;
11+
configFile?: string;
12+
measureInstability?: boolean;
1313
};
1414

1515
type FileName = string;

src/writeMarkdownFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createWriteStream } from 'fs';
22
import mermaidify from './mermaidify';
33
import { Graph, OptionValues, measureInstability } from './models';
44

5-
type Options = Partial<OptionValues> & {
5+
type Options = OptionValues & {
66
rootDir: string;
77
executedScript?: string;
88
};

0 commit comments

Comments
 (0)