-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add a metadata plugin for project file sizes
- Loading branch information
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
CreateMetadata, | ||
CreateMetadataContext, | ||
ProjectsMetadata, | ||
} from '../../project-graph/plugins'; | ||
import { ProjectGraph } from '../../config/project-graph'; | ||
import { getFileMap } from '../../project-graph/build-project-graph'; | ||
|
||
export const name = 'nx/core/project-sizes'; | ||
|
||
export const createMetadata: CreateMetadata = ( | ||
graph: ProjectGraph, | ||
options: unknown, | ||
context: CreateMetadataContext | ||
): ProjectsMetadata => { | ||
// TODO: should this be a call to the daemon so that we can work in isolated context? | ||
const { | ||
fileMap: { projectFileMap }, | ||
} = getFileMap(); | ||
|
||
const projectsMetadata: ProjectsMetadata = {}; | ||
for (const [projectId, project] of Object.entries(graph.nodes)) { | ||
let totalSize = 0; | ||
let totalFiles = projectFileMap[projectId].length; | ||
for (let i of projectFileMap[projectId]) { | ||
totalSize += i.size ?? 0; | ||
} | ||
|
||
projectsMetadata[projectId] = { | ||
metadata: { | ||
totalSize, | ||
totalFiles, | ||
} as any, | ||
}; | ||
} | ||
|
||
return projectsMetadata; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters