@@ -19,7 +19,13 @@ import * as debug from 'debug';
19
19
import { readFileSync } from 'fs' ;
20
20
import { join , resolve } from 'path' ;
21
21
import { parseJsonSchemaToCommandDescription } from '../utilities/json-schema' ;
22
- import { UniversalAnalytics , getGlobalAnalytics , getSharedAnalytics } from './analytics' ;
22
+ import {
23
+ getGlobalAnalytics ,
24
+ getSharedAnalytics ,
25
+ getWorkspaceAnalytics ,
26
+ hasWorkspaceAnalyticsConfiguration ,
27
+ promptProjectAnalytics ,
28
+ } from './analytics' ;
23
29
import { Command } from './command' ;
24
30
import { CommandDescription , CommandWorkspace } from './interface' ;
25
31
import * as parser from './parser' ;
@@ -58,8 +64,19 @@ export interface CommandMapOptions {
58
64
* Create the analytics instance.
59
65
* @private
60
66
*/
61
- async function _createAnalytics ( ) : Promise < analytics . Analytics > {
62
- const config = await getGlobalAnalytics ( ) ;
67
+ async function _createAnalytics ( workspace : boolean ) : Promise < analytics . Analytics > {
68
+ let config = await getGlobalAnalytics ( ) ;
69
+ // If in workspace and global analytics is enabled, defer to workspace level
70
+ if ( workspace && config ) {
71
+ // TODO: This should honor the `no-interactive` option.
72
+ // It is currently not an `ng` option but rather only an option for specific commands.
73
+ // The concept of `ng`-wide options are needed to cleanly handle this.
74
+ if ( ! ( await hasWorkspaceAnalyticsConfiguration ( ) ) ) {
75
+ await promptProjectAnalytics ( ) ;
76
+ }
77
+ config = await getWorkspaceAnalytics ( ) ;
78
+ }
79
+
63
80
const maybeSharedAnalytics = await getSharedAnalytics ( ) ;
64
81
65
82
if ( config && maybeSharedAnalytics ) {
@@ -214,7 +231,7 @@ export async function runCommand(
214
231
return map ;
215
232
} ) ;
216
233
217
- const analytics = options . analytics || await _createAnalytics ( ) ;
234
+ const analytics = options . analytics || await _createAnalytics ( ! ! workspace . configFile ) ;
218
235
const context = { workspace, analytics } ;
219
236
const command = new description . impl ( context , description , logger ) ;
220
237
0 commit comments