-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular/cli): add
ng analytics info
command
With this change we add a subcommand to `ng analytics`. This command can be used tp display analytics gathering and reporting configuration. Example: ``` $ ng analytics info Global setting: disabled Local setting: enabled Effective status: disabled ```
- Loading branch information
1 parent
afafa57
commit bb55043
Showing
9 changed files
with
256 additions
and
91 deletions.
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
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
34 changes: 34 additions & 0 deletions
34
packages/angular/cli/src/command-builder/utilities/command.ts
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,34 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { Argv } from 'yargs'; | ||
import { CommandContext, CommandModule, CommandModuleImplementation } from '../command-module'; | ||
|
||
export const demandCommandFailureMessage = `You need to specify a command before moving on. Use '--help' to view the available commands.`; | ||
|
||
export function addCommandModuleToYargs< | ||
T, | ||
U extends Partial<CommandModuleImplementation> & { | ||
new (context: CommandContext): Partial<CommandModuleImplementation> & CommandModule; | ||
}, | ||
>(localYargs: Argv<T>, commandModule: U, context: CommandContext): Argv<T> { | ||
const cmd = new commandModule(context); | ||
const describe = context.args.options.jsonHelp ? cmd.fullDescribe : cmd.describe; | ||
|
||
return localYargs.command({ | ||
command: cmd.command, | ||
aliases: cmd.aliases, | ||
describe: | ||
// We cannot add custom fields in help, such as long command description which is used in AIO. | ||
// Therefore, we get around this by adding a complex object as a string which we later parse when generating the help files. | ||
typeof describe === 'object' ? JSON.stringify(describe) : describe, | ||
deprecated: cmd.deprecated, | ||
builder: (argv) => cmd.builder(argv) as Argv<T>, | ||
handler: (args) => cmd.handler(args), | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { tags } from '@angular-devkit/core'; | ||
import { Argv } from 'yargs'; | ||
import { analyticsConfigValueToHumanFormat, createAnalytics } from '../../../analytics/analytics'; | ||
import { | ||
CommandModule, | ||
CommandModuleImplementation, | ||
Options, | ||
} from '../../../command-builder/command-module'; | ||
import { getWorkspaceRaw } from '../../../utilities/config'; | ||
|
||
export class AnalyticsInfoCommandModule | ||
extends CommandModule | ||
implements CommandModuleImplementation | ||
{ | ||
command = 'info'; | ||
describe = 'Prints analytics gathering and reporting configuration in the console.'; | ||
longDescriptionPath?: string | undefined; | ||
|
||
builder(localYargs: Argv): Argv { | ||
return localYargs.strict(); | ||
} | ||
|
||
async run(_options: Options<{}>): Promise<void> { | ||
const [globalWorkspace] = getWorkspaceRaw('global'); | ||
const [localWorkspace] = getWorkspaceRaw('local'); | ||
const globalSetting = globalWorkspace?.get(['cli', 'analytics']); | ||
const localSetting = localWorkspace?.get(['cli', 'analytics']); | ||
|
||
const effectiveSetting = await createAnalytics( | ||
!!this.context.workspace /** workspace */, | ||
true /** skipPrompt */, | ||
); | ||
|
||
this.context.logger.info(tags.stripIndents` | ||
Global setting: ${analyticsConfigValueToHumanFormat(globalSetting)} | ||
Local setting: ${ | ||
this.context.workspace | ||
? analyticsConfigValueToHumanFormat(localSetting) | ||
: 'No local workspace configuration file.' | ||
} | ||
Effective status: ${effectiveSetting ? 'enabled' : 'disabled'} | ||
`); | ||
} | ||
} |
9 changes: 0 additions & 9 deletions
9
packages/angular/cli/src/commands/analytics/long-description.md
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.