Skip to content

Commit 46a7be3

Browse files
alan-agius4clydin
authored andcommitted
refactor(@angular/cli): clean up analytics methods
Re-use methods were possible.
1 parent bb55043 commit 46a7be3

File tree

8 files changed

+132
-268
lines changed

8 files changed

+132
-268
lines changed

Diff for: docs/design/analytics.md

+1-10
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,5 @@ There are 2 ways of disabling usage analytics:
115115
as answering "No" to the prompt.
116116
1. There is an `NG_CLI_ANALYTICS` environment variable that overrides the global configuration.
117117
That flag is a string that represents the User ID. If the string `"false"` is used it will
118-
disable analytics for this run. If the string `"ci"` is used it will show up as a CI run (see
119-
below).
118+
disable analytics for this run.
120119

121-
# CI
122-
123-
A special user named `ci` is used for analytics for tracking CI information. This is a convention
124-
and is in no way enforced.
125-
126-
Running on CI by default will disable analytics (because of a lack of TTY on STDIN/OUT). It can be
127-
manually enabled using either a global configuration with a value of `ci`, or using the
128-
`NG_CLI_ANALYTICS=ci` environment variable.

Diff for: packages/angular/cli/bin/postinstall/analytics-prompt.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ try {
1717
var analytics = require('../../src/analytics/analytics');
1818

1919
analytics
20-
.hasGlobalAnalyticsConfiguration()
20+
.hasAnalyticsConfig('global')
2121
.then((hasGlobalConfig) => {
2222
if (!hasGlobalConfig) {
23-
return analytics.promptGlobalAnalytics();
23+
return analytics.promptAnalytics(true /** global */);
2424
}
2525
})
2626
.catch(() => {});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
function isDisabled(variable: string): boolean {
10+
return variable === '0' || variable.toLowerCase() === 'false';
11+
}
12+
13+
function isPresent(variable: string | undefined): variable is string {
14+
return typeof variable === 'string' && variable !== '';
15+
}
16+
17+
const analyticsVariable = process.env['NG_CLI_ANALYTICS'];
18+
export const analyticsDisabled = isPresent(analyticsVariable) && isDisabled(analyticsVariable);
19+
20+
const analyticsShareVariable = process.env['NG_CLI_ANALYTICS_SHARE'];
21+
export const analyticsShareDisabled =
22+
isPresent(analyticsShareVariable) && isDisabled(analyticsShareVariable);

0 commit comments

Comments
 (0)