Skip to content

Commit c59c1e7

Browse files
committed
fix(@angular/cli): add workspace information as part of analytics collection
With this change we collect 3 additional metrics - `all_projects_count` Count of all project in a workspace - `libs_projects_count` Count of library projects in a workspace - `apps_projects_count` Count of application projects in a workspace
1 parent cf1b778 commit c59c1e7

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

docs/design/analytics.md

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ PROJECT NAME TO BUILD OR A MODULE NAME.**
7979
| CssSizeInBytes | `epn.ng_css_size_bytes` | `number` |
8080
| JsSizeInBytes | `epn.ng_js_size_bytes` | `number` |
8181
| NgComponentCount | `epn.ng_component_count` | `number` |
82+
| AllProjectsCount | `epn.all_projects_count` | `number` |
83+
| LibraryProjectsCount | `epn.libs_projects_count` | `number` |
84+
| ApplicationProjectsCount | `epn.apps_projects_count` | `number` |
8285
<!--METRICS_TABLE_END-->
8386

8487
## Debugging

packages/angular/cli/src/analytics/analytics-collector.ts

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ export class AnalyticsCollector {
7272
};
7373
}
7474

75+
reportWorkspaceInfoEvent(
76+
parameters: Partial<Record<EventCustomMetric, string | boolean | number | undefined>>,
77+
): void {
78+
this.event('workspace_info', parameters);
79+
}
80+
7581
reportRebuildRunEvent(
7682
parameters: Partial<
7783
Record<EventCustomMetric & EventCustomDimension, string | boolean | number | undefined>

packages/angular/cli/src/analytics/analytics-parameters.ts

+3
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,7 @@ export enum EventCustomMetric {
9797
CssSizeInBytes = 'epn.ng_css_size_bytes',
9898
JsSizeInBytes = 'epn.ng_js_size_bytes',
9999
NgComponentCount = 'epn.ng_component_count',
100+
AllProjectsCount = 'epn.all_projects_count',
101+
LibraryProjectsCount = 'epn.libs_projects_count',
102+
ApplicationProjectsCount = 'epn.apps_projects_count',
100103
}

packages/angular/cli/src/command-builder/command-module.ts

+45-15
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,9 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
146146

147147
let exitCode: number | void | undefined;
148148
try {
149-
// Run and time command.
150149
if (analytics) {
151-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
152-
const internalMethods = (yargs as any).getInternalMethods();
153-
// $0 generate component [name] -> generate_component
154-
// $0 add <collection> -> add
155-
const fullCommand = (internalMethods.getUsageInstance().getUsage()[0][0] as string)
156-
.split(' ')
157-
.filter((x) => {
158-
const code = x.charCodeAt(0);
159-
160-
return code >= 97 && code <= 122;
161-
})
162-
.join('_');
163-
164-
analytics.reportCommandRunEvent(fullCommand);
150+
this.reportCommandRunAnalytics(analytics);
151+
this.reportWorkspaceInfoAnalytics(analytics);
165152
}
166153

167154
exitCode = await this.run(camelCasedOptions as Options<T> & OtherOptions);
@@ -307,6 +294,49 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
307294

308295
return parameters;
309296
}
297+
298+
private reportCommandRunAnalytics(analytics: AnalyticsCollector): void {
299+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
300+
const internalMethods = (yargs as any).getInternalMethods();
301+
// $0 generate component [name] -> generate_component
302+
// $0 add <collection> -> add
303+
const fullCommand = (internalMethods.getUsageInstance().getUsage()[0][0] as string)
304+
.split(' ')
305+
.filter((x) => {
306+
const code = x.charCodeAt(0);
307+
308+
return code >= 97 && code <= 122;
309+
})
310+
.join('_');
311+
312+
analytics.reportCommandRunEvent(fullCommand);
313+
}
314+
315+
private reportWorkspaceInfoAnalytics(analytics: AnalyticsCollector): void {
316+
const { workspace } = this.context;
317+
if (!workspace) {
318+
return;
319+
}
320+
321+
let applicationProjectsCount = 0;
322+
let librariesProjectsCount = 0;
323+
for (const project of workspace.projects.values()) {
324+
switch (project.extensions['projectType']) {
325+
case 'application':
326+
applicationProjectsCount++;
327+
break;
328+
case 'library':
329+
librariesProjectsCount++;
330+
break;
331+
}
332+
}
333+
334+
analytics.reportWorkspaceInfoEvent({
335+
[EventCustomMetric.AllProjectsCount]: librariesProjectsCount + applicationProjectsCount,
336+
[EventCustomMetric.ApplicationProjectsCount]: applicationProjectsCount,
337+
[EventCustomMetric.LibraryProjectsCount]: librariesProjectsCount,
338+
});
339+
}
310340
}
311341

312342
/**

0 commit comments

Comments
 (0)