Skip to content

Commit

Permalink
feat: add --includeOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Aug 13, 2021
1 parent 4820df4 commit 1177873
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const cli = meow(
$ express-router-dependency-graph --rootDir=path/to/project
Options
--includeOnly [String] only include modules satisfying a pattern. https://github.com/sverweij/dependency-cruiser/blob/develop/doc/cli.md#--include-only-only-include-modules-satisfying-a-pattern
--rootDir [Path:String] path to root dir of source code [required]
--rootBaseUrl [Path:String] if pass it, replace rootDir with rootDirBaseURL in output.
--format ["json" | "markdown"] output format. Default: json
Expand All @@ -25,6 +26,9 @@ export const cli = meow(
type: "string",
default: ""
},
includeOnly: {
type: "string"
},
format: {
type: "string",
default: "json"
Expand All @@ -42,7 +46,8 @@ export const run = async (
const result = await analyzeDependency({
rootDir: path.resolve(process.cwd(), flags.rootDir),
rootBaseUrl: flags.rootBaseUrl,
outputFormat: flags.format as "json" | "markdown"
outputFormat: flags.format as "json" | "markdown",
includeOnly: flags.includeOnly
});
return {
stdout: flags.format === "json" ? JSON.stringify(result) : result,
Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ const findRouting = async (filePath: string) => {
export async function analyzeDependency({
outputFormat,
rootDir,
rootBaseUrl = ""
rootBaseUrl = "",
includeOnly
}: {
rootDir: string;
rootBaseUrl: string;
outputFormat: "markdown" | "json";
includeOnly?: string | string[];
}) {
const ROOT_DIR = rootDir;
const hasImportExpress = (dep: IDependency) => {
Expand All @@ -88,7 +90,9 @@ export async function analyzeDependency({
return path.relative(ROOT_DIR, toAbsolute(f));
};
const ARRAY_OF_FILES_AND_DIRS_TO_CRUISE: string[] = [ROOT_DIR];
const cruiseResult: IReporterOutput = cruise(ARRAY_OF_FILES_AND_DIRS_TO_CRUISE);
const cruiseResult: IReporterOutput = cruise(ARRAY_OF_FILES_AND_DIRS_TO_CRUISE, {
includeOnly
});
if (typeof cruiseResult.output !== "object") {
throw new Error("NO OUTPUT");
}
Expand Down

0 comments on commit 1177873

Please sign in to comment.