Skip to content

Commit 138c1e0

Browse files
committed
refactor(core): move projectName to getProjectData options
1 parent 49d2c47 commit 138c1e0

2 files changed

Lines changed: 24 additions & 39 deletions

File tree

packages/core/src/lib/api/get-project-data.ts

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export type Options = {
2323
* that contains the external libraries, i.e. node_modules.
2424
*/
2525
includeExternalLibraries?: boolean;
26+
/**
27+
* Adds a property `projectName` to each entry
28+
* that contains the name of the project.
29+
*/
30+
projectName?: string;
2631
};
2732
export type ProjectData = Record<string, ProjectDataEntry>;
2833

@@ -78,7 +83,6 @@ function calcOrGetTags(
7883
*/
7984
export function getProjectData(
8085
entryFileAbsolute: string,
81-
projectName: string,
8286
options?: Options,
8387
): ProjectData;
8488
/**
@@ -114,43 +118,28 @@ export function getProjectData(
114118
export function getProjectData(
115119
entryFileRelative: string,
116120
cwd: string,
117-
projectName: string,
118121
options?: Options,
119122
): ProjectData;
120123

121124
export function getProjectData(
122125
entryFile: string,
123-
cwdOrProjectName: string,
124-
projectNameOrOptions?: string | Options,
126+
cwdOrOptions?: string | Options,
125127
optionalOptions?: Options,
126128
): ProjectData {
127129
const fs = getFs();
128-
let absoluteEntryFile: string;
129-
let cwd: string | undefined;
130-
let projectName: string;
131-
let options: Options;
132-
133-
if (
134-
typeof cwdOrProjectName === 'string' &&
135-
typeof projectNameOrOptions === 'string'
136-
) {
137-
// Called with: (entryFile, cwd, projectName, options?)
138-
absoluteEntryFile = fs.join(entryFile);
139-
cwd = cwdOrProjectName;
140-
projectName = projectNameOrOptions;
141-
options = optionalOptions || {};
142-
} else if (
143-
typeof cwdOrProjectName === 'string' &&
144-
typeof projectNameOrOptions === 'object'
145-
) {
146-
// Called with: (entryFile, projectName, options)
147-
absoluteEntryFile = entryFile;
148-
cwd = undefined;
149-
projectName = cwdOrProjectName;
150-
options = projectNameOrOptions || {};
151-
} else {
152-
throw new Error('Invalid arguments to getProjectData');
153-
}
130+
const absoluteEntryFile =
131+
cwdOrOptions === undefined
132+
? entryFile
133+
: typeof cwdOrOptions === 'string'
134+
? fs.join(entryFile)
135+
: entryFile;
136+
137+
const cwd = typeof cwdOrOptions === 'string' ? cwdOrOptions : undefined;
138+
const options = optionalOptions
139+
? optionalOptions
140+
: typeof cwdOrOptions === 'object'
141+
? cwdOrOptions
142+
: {};
154143

155144
const projectInfo = init(toFsPath(absoluteEntryFile));
156145

@@ -164,7 +153,7 @@ export function getProjectData(
164153
tags: calcOrGetTags(fileInfo.moduleInfo.path, projectInfo, tagsCache),
165154
imports: fileInfo.imports.map((fileInfo) => fileInfo.path),
166155
unresolvedImports: fileInfo.unresolvableImports,
167-
projectName: projectName,
156+
projectName: options.projectName ?? '',
168157
};
169158

170159
if (options.includeExternalLibraries) {

packages/core/src/lib/cli/export-data.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ export function exportData(...args: string[]): void {
88
const projectEntries = getEntriesFromCliOrConfig(args[0], true);
99

1010
for (const entry of projectEntries) {
11-
const data = getProjectData(
12-
entry.entry.fileInfo.path,
13-
fs.cwd(),
14-
entry.projectName,
15-
{
16-
includeExternalLibraries: true,
17-
},
18-
);
11+
const data = getProjectData(entry.entry.fileInfo.path, fs.cwd(), {
12+
includeExternalLibraries: true,
13+
projectName: entry.projectName,
14+
});
1915
cli.log(JSON.stringify(data, null, ' '));
2016
}
2117
}

0 commit comments

Comments
 (0)