Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ Usage: very_good create <output directory>
--project-name The project name for this new project. This must be a valid dart package name.
--desc The description for this new project.
(defaults to "A Very Good Project created by Very Good CLI.")
--executable-name Used by the dart_cli template, the CLI executable name (defaults to the project name)
--org-name The organization for this new project.
(defaults to "com.example.verygoodcore")
-t, --template The template used to generate this new project.

[core] (default) Generate a Very Good Flutter application.
[dart_cli] Generate a Very Good Dart CLI application.
[dart_pkg] Generate a reusable Dart package.
[flutter_pkg] Generate a reusable Flutter package.
[flutter_plugin] Generate a reusable Flutter federated plugin.
Expand All @@ -68,6 +70,12 @@ very_good create my_flutter_package -t flutter_pkg --desc "My new Flutter packag
# Create a new Dart package named my_dart_package
very_good create my_dart_package -t dart_pkg --desc "My new Dart package"

# Create a new Dart CLI application named my_dart_cli
very_good create my_dart_cli -t dart_cli --desc "My new Dart CLI package"

# Create a new Dart CLI application named my_dart_cli with a custom executable name
very_good create my_dart_cli -t dart_cli --desc "My new Dart CLI package" --executable-name my_executable_name

# Create a new Flutter plugin named my_flutter_plugin (all platforms enabled)
very_good create my_flutter_plugin -t flutter_plugin --desc "My new Flutter plugin"

Expand Down
9 changes: 9 additions & 0 deletions lib/src/commands/create/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final _templates = [
DartPkgTemplate(),
FlutterPkgTemplate(),
FlutterPluginTemplate(),
VeryGoodDartCLITemplate(),
];

final _defaultTemplate = _templates.first;
Expand Down Expand Up @@ -53,6 +54,11 @@ class CreateCommand extends Command<int> {
help: 'The description for this new project.',
defaultsTo: _defaultDescription,
)
..addOption(
'executable-name',
help: 'Used by the dart_cli template, the CLI executable name '
'(defaults to the project name)',
)
..addOption(
'org-name',
help: 'The organization for this new project.',
Expand Down Expand Up @@ -143,11 +149,14 @@ class CreateCommand extends Command<int> {
final linux = _argResults['linux'] as String? ?? 'true';
final macos = _argResults['macos'] as String? ?? 'true';
final windows = _argResults['windows'] as String? ?? 'true';
final executableName =
_argResults['executable-name'] as String? ?? projectName;
final files = await generator.generate(
DirectoryGeneratorTarget(outputDirectory),
vars: <String, dynamic>{
'project_name': projectName,
'description': description,
'executable_name': executableName,
'org_name': orgName,
'android': android.toBool(),
'ios': ios.toBool(),
Expand Down
1 change: 1 addition & 0 deletions lib/src/commands/create/templates/templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export 'flutter_plugin/flutter_plugin.dart';
export 'post_generate_actions.dart';
export 'template.dart';
export 'very_good_core/very_good_core.dart';
export 'very_good_dart_cli/very_good_dart_cli.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'very_good_dart_cli_bundle.dart';
export 'very_good_dart_cli_template.dart';

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'dart:io';

import 'package:mason_logger/mason_logger.dart';
import 'package:very_good_cli/src/commands/create/templates/templates.dart';

/// {@template dart_cli_template}
/// A Dart CLI application template.
/// {@endtemplate}
class VeryGoodDartCLITemplate extends Template {
/// {@macro dart_cli_template}
VeryGoodDartCLITemplate()
: super(
name: 'dart_cli',
bundle: veryGoodDartCliBundle,
help: 'Generate a Very Good Dart CLI application.',
);

@override
Future<void> onGenerateComplete(Logger logger, Directory outputDir) async {
await installDartPackages(logger, outputDir);
await applyDartFixes(logger, outputDir);
_logSummary(logger);
}

void _logSummary(Logger logger) {
logger
..info('\n')
..alert('Created a Very Good Dart CLI application! 🦄')
..info('\n');
}
}
15 changes: 15 additions & 0 deletions test/src/commands/create/create_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ const expectedUsage = [
''' --project-name The project name for this new project. This must be a valid dart package name.\n'''
' --desc The description for this new project.\n'
''' (defaults to "A Very Good Project created by Very Good CLI.")\n'''
''' --executable-name Used by the dart_cli template, the CLI executable name (defaults to the project name)\n'''
' --org-name The organization for this new project.\n'
' (defaults to "com.example.verygoodcore")\n'
'''-t, --template The template used to generate this new project.\n'''
'\n'
''' [core] (default) Generate a Very Good Flutter application.\n'''
''' [dart_cli] Generate a Very Good Dart CLI application.\n'''
' [dart_pkg] Generate a reusable Dart package.\n'
' [flutter_pkg] Generate a reusable Flutter package.\n'
' [flutter_plugin] Generate a reusable Flutter plugin.\n'
Expand Down Expand Up @@ -221,6 +223,7 @@ void main() {
'project_name': 'my_app',
'org_name': 'com.example.verygoodcore',
'description': '',
'executable_name': 'my_app',
'android': true,
'ios': true,
'web': true,
Expand Down Expand Up @@ -283,6 +286,7 @@ void main() {
'project_name': 'my_app',
'org_name': 'com.example.verygoodcore',
'description': 'very good description',
'executable_name': 'my_app',
'android': true,
'ios': true,
'web': true,
Expand Down Expand Up @@ -424,6 +428,7 @@ void main() {
vars: <String, dynamic>{
'project_name': 'my_app',
'description': '',
'executable_name': 'my_app',
'org_name': orgName,
'android': true,
'ios': true,
Expand Down Expand Up @@ -539,6 +544,7 @@ void main() {
vars: <String, dynamic>{
'project_name': 'my_app',
'org_name': 'com.example.verygoodcore',
'executable_name': 'my_app',
'description': '',
'android': true,
'ios': true,
Expand Down Expand Up @@ -599,6 +605,15 @@ void main() {
expectedLogSummary: 'Created a Very Good Flutter Plugin! 🦄',
);
});

test('dart CLI template', () async {
await expectValidTemplateName(
getPackagesMsg: 'Running "flutter pub get" in .tmp',
templateName: 'dart_cli',
expectedBundle: veryGoodDartCliBundle,
expectedLogSummary: 'Created a Very Good Dart CLI application! 🦄',
);
});
});
});
});
Expand Down