@@ -19,7 +19,13 @@ import * as debug from 'debug';
1919import { readFileSync } from 'fs' ;
2020import { join , resolve } from 'path' ;
2121import { 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' ;
2329import { Command } from './command' ;
2430import { CommandDescription , CommandWorkspace } from './interface' ;
2531import * as parser from './parser' ;
@@ -58,8 +64,19 @@ export interface CommandMapOptions {
5864 * Create the analytics instance.
5965 * @private
6066 */
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+
6380 const maybeSharedAnalytics = await getSharedAnalytics ( ) ;
6481
6582 if ( config && maybeSharedAnalytics ) {
@@ -214,7 +231,7 @@ export async function runCommand(
214231 return map ;
215232 } ) ;
216233
217- const analytics = options . analytics || await _createAnalytics ( ) ;
234+ const analytics = options . analytics || await _createAnalytics ( ! ! workspace . configFile ) ;
218235 const context = { workspace, analytics } ;
219236 const command = new description . impl ( context , description , logger ) ;
220237
0 commit comments