Skip to content

Commit

Permalink
fix!: remove analytics (#756)
Browse files Browse the repository at this point in the history
* fix: remove usage dependencies

* feat: removed analytics from source

* feat: continued removing analytics

* refactor: unused pacakge

* test: updated expected usage

* test: added missing test for coverage

* test: fixed test name

* test: updated command_runner test

---------

Co-authored-by: Renan <[email protected]>
Co-authored-by: Jochum van der Ploeg <[email protected]>
  • Loading branch information
3 people authored Aug 7, 2023
1 parent 257ef6a commit 0912a75
Show file tree
Hide file tree
Showing 27 changed files with 12 additions and 347 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ Usage: very_good <command> [arguments]
Global options:
-h, --help Print this usage information.
--version Print the current version.
--analytics Toggle anonymous usage statistics.

[false] Disable anonymous usage statistics
[true] Enable anonymous usage statistics

Available commands:
create very_good create <output directory>
Expand Down
13 changes: 0 additions & 13 deletions e2e/helpers/command_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import 'dart:async';
import 'package:mason/mason.dart';
import 'package:mocktail/mocktail.dart';
import 'package:pub_updater/pub_updater.dart';
import 'package:usage/usage.dart';
import 'package:very_good_cli/src/command_runner.dart';

class _MockAnalytics extends Mock implements Analytics {}

class _MockLogger extends Mock implements Logger {}

class _MockProgress extends Mock implements Progress {}
Expand Down Expand Up @@ -38,25 +35,15 @@ void Function() withRunner(
) runnerFn,
) {
return _overridePrint((printLogs) async {
final analytics = _MockAnalytics();
final logger = _MockLogger();
final progress = _MockProgress();
final pubUpdater = _MockPubUpdater();
final progressLogs = <String>[];
final commandRunner = VeryGoodCommandRunner(
analytics: analytics,
logger: logger,
pubUpdater: pubUpdater,
);

when(() => analytics.firstRun).thenReturn(false);
when(() => analytics.enabled).thenReturn(false);
when(
() => analytics.sendEvent(any(), any(), label: any(named: 'label')),
).thenAnswer((_) async {});
when(
() => analytics.waitForLastPing(timeout: any(named: 'timeout')),
).thenAnswer((_) async {});
when(() => progress.complete(any())).thenAnswer((_) {
final message = _.positionalArguments.elementAt(0) as String?;
if (message != null) progressLogs.add(message);
Expand Down
1 change: 0 additions & 1 deletion e2e/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dev_dependencies:
pub_updater: ^0.3.0
test: ^1.24.3
universal_io: ^2.0.4
usage: ^4.0.2
very_good_analysis: ^5.0.0
very_good_cli:
path: ../
48 changes: 1 addition & 47 deletions lib/src/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@ import 'package:args/command_runner.dart';
import 'package:cli_completion/cli_completion.dart';
import 'package:mason/mason.dart' hide packageVersion;
import 'package:pub_updater/pub_updater.dart';
import 'package:usage/usage_io.dart';
import 'package:very_good_cli/src/commands/commands.dart';
import 'package:very_good_cli/src/version.dart';

// The Google Analytics tracking ID.
const _gaTrackingId = 'UA-117465969-4';

// The Google Analytics Application Name.
const _gaAppName = 'very-good-cli';

/// The package name.
const packageName = 'very_good_cli';

Expand All @@ -22,12 +15,9 @@ const packageName = 'very_good_cli';
class VeryGoodCommandRunner extends CompletionCommandRunner<int> {
/// {@macro very_good_command_runner}
VeryGoodCommandRunner({
Analytics? analytics,
Logger? logger,
PubUpdater? pubUpdater,
}) : _logger = logger ?? Logger(),
_analytics =
analytics ?? AnalyticsIO(_gaTrackingId, _gaAppName, packageVersion),
_pubUpdater = pubUpdater ?? PubUpdater(),
super('very_good', '🦄 A Very Good Command-Line Interface') {
argParser
Expand All @@ -36,20 +26,11 @@ class VeryGoodCommandRunner extends CompletionCommandRunner<int> {
negatable: false,
help: 'Print the current version.',
)
..addOption(
'analytics',
help: 'Toggle anonymous usage statistics.',
allowed: ['true', 'false'],
allowedHelp: {
'true': 'Enable anonymous usage statistics',
'false': 'Disable anonymous usage statistics',
},
)
..addFlag(
'verbose',
help: 'Noisy logging, including all shell commands executed.',
);
addCommand(CreateCommand(analytics: _analytics, logger: _logger));
addCommand(CreateCommand(logger: _logger));
addCommand(PackagesCommand(logger: _logger));
addCommand(TestCommand(logger: _logger));
addCommand(UpdateCommand(logger: _logger, pubUpdater: pubUpdater));
Expand All @@ -59,7 +40,6 @@ class VeryGoodCommandRunner extends CompletionCommandRunner<int> {
static const timeout = Duration(milliseconds: 500);

final Logger _logger;
final Analytics _analytics;
final PubUpdater _pubUpdater;

@override
Expand All @@ -68,23 +48,6 @@ class VeryGoodCommandRunner extends CompletionCommandRunner<int> {
@override
Future<int> run(Iterable<String> args) async {
try {
if (_analytics.firstRun) {
final response = _logger.prompt(
lightGray.wrap(
'''
+---------------------------------------------------+
| Welcome to the Very Good CLI! |
+---------------------------------------------------+
| We would like to collect anonymous |
| usage statistics in order to improve the tool. |
| Would you like to opt-into help us improve? [y/n] |
+---------------------------------------------------+\n''',
),
);
final normalizedResponse = response.toLowerCase().trim();
_analytics.enabled =
normalizedResponse == 'y' || normalizedResponse == 'yes';
}
final argResults = parse(args);

if (argResults['verbose'] == true) {
Expand Down Expand Up @@ -139,19 +102,10 @@ class VeryGoodCommandRunner extends CompletionCommandRunner<int> {
}
}

if (_analytics.enabled) {
_logger.detail('Running with analytics enabled.');
}

int? exitCode = ExitCode.unavailable.code;
if (topLevelResults['version'] == true) {
_logger.info(packageVersion);
exitCode = ExitCode.success.code;
} else if (topLevelResults['analytics'] != null) {
final optIn = topLevelResults['analytics'] == 'true';
_analytics.enabled = optIn;
_logger.info('analytics ${_analytics.enabled ? 'enabled' : 'disabled'}.');
exitCode = ExitCode.success.code;
} else {
exitCode = await super.runCommand(topLevelResults);
}
Expand Down
16 changes: 1 addition & 15 deletions lib/src/commands/create/commands/create_subcommand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import 'package:args/command_runner.dart';
import 'package:mason/mason.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as path;
import 'package:usage/usage_io.dart';
import 'package:very_good_cli/src/command_runner.dart';
import 'package:very_good_cli/src/commands/commands.dart';
import 'package:very_good_cli/src/commands/create/templates/templates.dart';

Expand Down Expand Up @@ -50,12 +48,10 @@ typedef MasonGeneratorFromBrick = Future<MasonGenerator> Function(Brick);
abstract class CreateSubCommand extends Command<int> {
/// {@macro create_subcommand}
CreateSubCommand({
required Analytics analytics,
required this.logger,
required MasonGeneratorFromBundle? generatorFromBundle,
required MasonGeneratorFromBrick? generatorFromBrick,
}) : _analytics = analytics,
_generatorFromBundle = generatorFromBundle ?? MasonGenerator.fromBundle,
}) : _generatorFromBundle = generatorFromBundle ?? MasonGenerator.fromBundle,
_generatorFromBrick = generatorFromBrick ?? MasonGenerator.fromBrick {
argParser
..addOption(
Expand Down Expand Up @@ -110,8 +106,6 @@ abstract class CreateSubCommand extends Command<int> {
}
}

final Analytics _analytics;

/// The logger user to notify the user of the command's progress.
final Logger logger;
final MasonGeneratorFromBundle _generatorFromBundle;
Expand Down Expand Up @@ -199,14 +193,6 @@ abstract class CreateSubCommand extends Command<int> {
final generator = await _getGeneratorForTemplate();
final result = await runCreate(generator, template);

unawaited(
_analytics.sendEvent(
'create $name',
generator.id,
label: generator.description,
),
);
await _analytics.waitForLastPing(timeout: VeryGoodCommandRunner.timeout);
return result;
}

Expand Down
1 change: 0 additions & 1 deletion lib/src/commands/create/commands/dart_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
class CreateDartCLI extends CreateSubCommand with Publishable {
/// {@macro very_good_create_dart_cli_command}
CreateDartCLI({
required super.analytics,
required super.logger,
required super.generatorFromBundle,
required super.generatorFromBrick,
Expand Down
1 change: 0 additions & 1 deletion lib/src/commands/create/commands/dart_package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
class CreateDartPackage extends CreateSubCommand with Publishable {
/// {@macro very_good_create_dart_package_command}
CreateDartPackage({
required super.analytics,
required super.logger,
required super.generatorFromBundle,
required super.generatorFromBrick,
Expand Down
1 change: 0 additions & 1 deletion lib/src/commands/create/commands/docs_site.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
class CreateDocsSite extends CreateSubCommand {
/// {@macro very_good_create_docs_site}
CreateDocsSite({
required super.analytics,
required super.logger,
required super.generatorFromBundle,
required super.generatorFromBrick,
Expand Down
1 change: 0 additions & 1 deletion lib/src/commands/create/commands/flame_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
class CreateFlameGame extends CreateSubCommand with OrgName {
/// {@macro very_good_create_flame_game_command}
CreateFlameGame({
required super.analytics,
required super.logger,
required super.generatorFromBundle,
required super.generatorFromBrick,
Expand Down
1 change: 0 additions & 1 deletion lib/src/commands/create/commands/flutter_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
class CreateFlutterApp extends CreateSubCommand with OrgName, MultiTemplates {
/// {@macro very_good_create_flutter_app_command}
CreateFlutterApp({
required super.analytics,
required super.logger,
required super.generatorFromBundle,
required super.generatorFromBrick,
Expand Down
1 change: 0 additions & 1 deletion lib/src/commands/create/commands/flutter_package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
class CreateFlutterPackage extends CreateSubCommand with Publishable {
/// {@macro very_good_create_flutter_package_command}
CreateFlutterPackage({
required super.analytics,
required super.logger,
required super.generatorFromBundle,
required super.generatorFromBrick,
Expand Down
1 change: 0 additions & 1 deletion lib/src/commands/create/commands/flutter_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
class CreateFlutterPlugin extends CreateSubCommand with Publishable {
/// {@macro very_good_create_flutter_plugin_command}
CreateFlutterPlugin({
required super.analytics,
required super.logger,
required super.generatorFromBundle,
required super.generatorFromBrick,
Expand Down
9 changes: 0 additions & 9 deletions lib/src/commands/create/create.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:args/command_runner.dart';
import 'package:mason/mason.dart';
import 'package:usage/usage_io.dart';
import 'package:very_good_cli/src/commands/create/commands/commands.dart';

/// {@template create_command}
Expand All @@ -12,15 +11,13 @@ import 'package:very_good_cli/src/commands/create/commands/commands.dart';
class CreateCommand extends Command<int> {
/// {@macro create_command}
CreateCommand({
required Analytics analytics,
required Logger logger,
MasonGeneratorFromBundle? generatorFromBundle,
MasonGeneratorFromBrick? generatorFromBrick,
}) {
// very_good create flutter_app <args>
addSubcommand(
CreateFlutterApp(
analytics: analytics,
logger: logger,
generatorFromBundle: generatorFromBundle,
generatorFromBrick: generatorFromBrick,
Expand All @@ -30,7 +27,6 @@ class CreateCommand extends Command<int> {
// very_good create dart_package <args>
addSubcommand(
CreateDartPackage(
analytics: analytics,
logger: logger,
generatorFromBundle: generatorFromBundle,
generatorFromBrick: generatorFromBrick,
Expand All @@ -40,7 +36,6 @@ class CreateCommand extends Command<int> {
// very_good create dart_cli <args>
addSubcommand(
CreateDartCLI(
analytics: analytics,
logger: logger,
generatorFromBundle: generatorFromBundle,
generatorFromBrick: generatorFromBrick,
Expand All @@ -50,7 +45,6 @@ class CreateCommand extends Command<int> {
// very_good create docs_site <args>
addSubcommand(
CreateDocsSite(
analytics: analytics,
logger: logger,
generatorFromBundle: generatorFromBundle,
generatorFromBrick: generatorFromBrick,
Expand All @@ -60,7 +54,6 @@ class CreateCommand extends Command<int> {
// very_good create flutter_package <args>
addSubcommand(
CreateFlutterPackage(
analytics: analytics,
logger: logger,
generatorFromBundle: generatorFromBundle,
generatorFromBrick: generatorFromBrick,
Expand All @@ -70,7 +63,6 @@ class CreateCommand extends Command<int> {
// very_good create flutter_plugin <args>
addSubcommand(
CreateFlutterPlugin(
analytics: analytics,
logger: logger,
generatorFromBundle: generatorFromBundle,
generatorFromBrick: generatorFromBrick,
Expand All @@ -80,7 +72,6 @@ class CreateCommand extends Command<int> {
// very_good create flame_game <args>
addSubcommand(
CreateFlameGame(
analytics: analytics,
logger: logger,
generatorFromBundle: generatorFromBundle,
generatorFromBrick: generatorFromBrick,
Expand Down
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ dependencies:
pubspec_parse: ^1.2.0
stack_trace: ^1.10.0
universal_io: ^2.0.4
usage: ^4.0.2
very_good_test_runner: ^0.1.2

dev_dependencies:
Expand Down
4 changes: 0 additions & 4 deletions site/docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ Usage: very_good <command> [arguments]
Global options:
-h, --help Print this usage information.
--version Print the current version.
--analytics Toggle anonymous usage statistics.

[false] Disable anonymous usage statistics
[true] Enable anonymous usage statistics

Available commands:
create very_good create <output directory>
Expand Down
12 changes: 0 additions & 12 deletions site/docs/templates/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,6 @@ very_good create flutter_app my_app --desc "My new Flutter app"
very_good create flutter_app my_app --desc "My new Flutter app" --org "com.custom.org"
```

:::note
Upon first use, you will be prompted about anonymous usage statistics. You can adjust these settings at any time via the `--analytics` flag
:::

```sh
# opt into anonymous usage statistics
very_good --analytics true

# opt out of anonymous usage statistics
very_good --analytics false
```

### Running the Project ⚡

Once you have finished running `very_good create` with the project directory of your choice, you can change directories into the new project directory and install the dependencies
Expand Down
Loading

0 comments on commit 0912a75

Please sign in to comment.