-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Integrate mason_logger for improved logging and user prompts #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Luckey-Elijah
wants to merge
20
commits into
flame-engine:main
Choose a base branch
from
Luckey-Elijah:feat/use-mason_logger
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b8ce152
feat: Integrate mason_logger for improved logging and user prompts
Luckey-Elijah 6927bb2
switch to more descriptive exit codes & logger
Luckey-Elijah c858e09
use logger in create and version command logs
Luckey-Elijah dc7ff3b
refactor: Change error logging to info level for command validation
Luckey-Elijah 667b18c
setup context
Luckey-Elijah 79ad1f8
simplifying
Luckey-Elijah 757ad4d
working
Luckey-Elijah e347f5e
fix up thiings?
Luckey-Elijah ef061f2
ninx rules
Luckey-Elijah 7dbf9b1
grammar
Luckey-Elijah ea21a7f
tidy up
Luckey-Elijah b12f3db
coment
Luckey-Elijah 541280b
remove unnessacry deps
Luckey-Elijah 2d1dbd6
tweaks with testing
Luckey-Elijah 427fef4
rename
Luckey-Elijah d291f10
scope run to just context
Luckey-Elijah 96a18db
it's all context
Luckey-Elijah 3237593
fix closing buffer for stdout and stdin
Luckey-Elijah 76d24c2
no show imports
Luckey-Elijah 5137bd4
null assert
Luckey-Elijah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
import 'package:ignite_cli/main.dart'; | ||
import 'dart:io'; | ||
|
||
void main(List<String> args) { | ||
mainCommand(args); | ||
import 'package:ignite_cli/flame_version_manager.dart'; | ||
import 'package:ignite_cli/ignite_commmand_runner.dart'; | ||
import 'package:mason_logger/mason_logger.dart'; | ||
|
||
Future<void> main(List<String> args) async { | ||
final runner = IgniteCommandRunner( | ||
logger: Logger(), | ||
flameVersionManager: await FlameVersionManager.fetch(), | ||
); | ||
|
||
exit((await runner.run(args)).code); | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -2,26 +2,102 @@ import 'dart:io'; | |
|
||
import 'package:args/args.dart'; | ||
import 'package:dartlin/dartlin.dart'; | ||
import 'package:ignite_cli/commands/ignite_command.dart'; | ||
import 'package:ignite_cli/flame_version_manager.dart'; | ||
import 'package:ignite_cli/templates/template.dart'; | ||
import 'package:ignite_cli/utils.dart'; | ||
import 'package:io/ansi.dart' as ansi; | ||
import 'package:mason/mason.dart'; | ||
import 'package:process_run/process_run.dart'; | ||
|
||
Future<void> createCommand(ArgResults command) async { | ||
class CreateCommand extends IgniteCommand { | ||
CreateCommand(super.context) { | ||
final packages = context.flameVersionManager.versions; | ||
final flameVersions = packages[Package.flame]!; | ||
|
||
argParser.addFlag( | ||
'interactive', | ||
abbr: 'i', | ||
help: 'Whether to run in interactive mode or not.', | ||
defaultsTo: true, | ||
); | ||
argParser.addOption( | ||
'name', | ||
help: 'The name of your game (valid dart identifier).', | ||
); | ||
argParser.addOption( | ||
'org', | ||
help: 'The org name, in reverse domain notation ' | ||
'(package name/bundle identifier).', | ||
); | ||
argParser.addFlag( | ||
'create-folder', | ||
abbr: 'f', | ||
help: 'If you want to create a new folder on the current location with ' | ||
"the project name or if you are already on the new project's folder.", | ||
); | ||
argParser.addOption( | ||
'template', | ||
help: 'What Flame template you would like to use for your new project', | ||
allowed: ['simple', 'example'], | ||
); | ||
argParser.addOption( | ||
'flame-version', | ||
help: 'What Flame version you would like to use.', | ||
allowed: [ | ||
...flameVersions.versions.take(5), | ||
'...', | ||
flameVersions.versions.last, | ||
], | ||
); | ||
argParser.addMultiOption( | ||
'extra-packages', | ||
help: 'Which packages to use', | ||
allowed: packages.keys.map((e) => e.name).toList(), | ||
); | ||
} | ||
|
||
@override | ||
String get description => 'Create a new Flame project'; | ||
|
||
@override | ||
String get name => 'create'; | ||
|
||
@override | ||
Future<ExitCode> run() async { | ||
final argResults = this.argResults; | ||
if (argResults == null) { | ||
return ExitCode.usage; | ||
} | ||
|
||
await createCommand( | ||
context.logger, | ||
argResults, | ||
context.flameVersionManager, | ||
); | ||
|
||
return ExitCode.success; | ||
} | ||
} | ||
|
||
Future<void> createCommand( | ||
Logger logger, | ||
ArgResults command, | ||
FlameVersionManager flameVersionManager, | ||
) async { | ||
final interactive = command['interactive'] != 'false'; | ||
|
||
if (interactive) { | ||
stdout.write('\nWelcome to ${ansi.red.wrap('Ignite CLI')}! 🔥\n'); | ||
stdout.write("Let's create a new project!\n\n"); | ||
logger | ||
..info('\nWelcome to ${red.wrap('Ignite CLI')}! 🔥') | ||
..info("Let's create a new project!\n"); | ||
} | ||
|
||
final name = getString( | ||
isInteractive: interactive, | ||
logger: logger, | ||
|
||
command, | ||
'name', | ||
'Choose a name for your project: ', | ||
'Choose a name for your project', | ||
desc: 'Note: this must be a valid dart identifier (no dashes). ' | ||
'For example: my_game', | ||
validate: (it) => switch (it) { | ||
|
@@ -34,6 +110,7 @@ Future<void> createCommand(ArgResults command) async { | |
); | ||
|
||
final org = getString( | ||
logger: logger, | ||
isInteractive: interactive, | ||
command, | ||
'org', | ||
|
@@ -48,9 +125,10 @@ Future<void> createCommand(ArgResults command) async { | |
}, | ||
); | ||
|
||
final versions = FlameVersionManager.singleton.versions; | ||
final versions = flameVersionManager.versions; | ||
final flameVersions = versions[Package.flame]!; | ||
final flameVersion = getOption( | ||
logger: logger, | ||
isInteractive: interactive, | ||
command, | ||
'flame-version', | ||
|
@@ -60,11 +138,12 @@ Future<void> createCommand(ArgResults command) async { | |
fullOptions: flameVersions.versions.associateWith((e) => e), | ||
); | ||
|
||
final extraPackageOptions = FlameVersionManager.singleton.versions.keys | ||
final extraPackageOptions = flameVersionManager.versions.keys | ||
.where((key) => !Package.includedByDefault.contains(key)) | ||
.map((key) => key.name) | ||
.toList(); | ||
final extraPackages = getMultiOption( | ||
logger: logger, | ||
isInteractive: interactive, | ||
isRequired: false, | ||
command, | ||
|
@@ -83,9 +162,10 @@ Future<void> createCommand(ArgResults command) async { | |
final devDependencies = packages.where((e) => e.isDevDependency); | ||
|
||
final currentDir = Directory.current.path; | ||
print('\nYour current directory is: $currentDir'); | ||
logger.info('\nYour current directory is: $currentDir'); | ||
|
||
final createFolder = getOption( | ||
logger: logger, | ||
isInteractive: interactive, | ||
command, | ||
'create-folder', | ||
|
@@ -98,8 +178,9 @@ Future<void> createCommand(ArgResults command) async { | |
) == | ||
'true'; | ||
|
||
print('\n'); | ||
logger.info('\n'); | ||
final template = getOption( | ||
logger: logger, | ||
isInteractive: interactive, | ||
command, | ||
'template', | ||
|
@@ -112,26 +193,26 @@ Future<void> createCommand(ArgResults command) async { | |
if (createFolder) { | ||
await runExecutableArguments('mkdir', [actualDir]); | ||
} | ||
print('\nRunning flutter create on $actualDir ...'); | ||
logger.info('\nRunning flutter create on $actualDir ...'); | ||
|
||
await runExecutableArguments( | ||
'flutter', | ||
'create --org $org --project-name $name .'.split(' '), | ||
workingDirectory: actualDir, | ||
verbose: true, | ||
verbose: logger.level == Level.verbose, | ||
); | ||
|
||
await runExecutableArguments( | ||
'rm', | ||
'-rf lib test'.split(' '), | ||
workingDirectory: actualDir, | ||
verbose: true, | ||
verbose: logger.level == Level.verbose, | ||
); | ||
|
||
final bundle = Template.byKey(template).bundle; | ||
final generator = await MasonGenerator.fromBundle(bundle); | ||
final target = DirectoryGeneratorTarget( | ||
Directory(actualDir), | ||
); | ||
final target = DirectoryGeneratorTarget(Directory(actualDir)); | ||
|
||
final variables = <String, dynamic>{ | ||
'name': name, | ||
'description': 'A simple Flame game.', | ||
|
@@ -153,16 +234,17 @@ Future<void> createCommand(ArgResults command) async { | |
'rm', | ||
'-rf test'.split(' '), | ||
workingDirectory: actualDir, | ||
verbose: true, | ||
verbose: logger.level == Level.verbose, | ||
); | ||
} | ||
|
||
await runExecutableArguments( | ||
'flutter', | ||
'pub get'.split(' '), | ||
workingDirectory: actualDir, | ||
verbose: true, | ||
verbose: logger.level == Level.verbose, | ||
); | ||
|
||
print('Updated ${files.length} files on top of flutter create.\n'); | ||
print('Your new Flame project was successfully created!'); | ||
// logger.info('Updated ${files.length} files on top of flutter create.\n'); | ||
logger.info('Your new Flame project was successfully created!'); | ||
} |
This file contains hidden or 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,25 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:args/command_runner.dart'; | ||
import 'package:ignite_cli/flame_version_manager.dart'; | ||
import 'package:mason/mason.dart'; | ||
import 'package:mason_logger/mason_logger.dart'; | ||
|
||
abstract class IgniteCommand extends Command<ExitCode> { | ||
final IgniteContext context; | ||
|
||
IgniteCommand(this.context); | ||
|
||
@override | ||
Future<ExitCode> run(); | ||
} | ||
|
||
class IgniteContext { | ||
const IgniteContext({ | ||
required this.logger, | ||
required this.flameVersionManager, | ||
}); | ||
|
||
final Logger logger; | ||
final FlameVersionManager flameVersionManager; | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,11 +1,32 @@ | ||
import 'package:ignite_cli/version.g.dart'; | ||
import 'package:mason/mason.dart'; | ||
import 'package:process_run/process_run.dart'; | ||
|
||
Future<void> versionCommand() async { | ||
print(r'$ ignite --version:'); | ||
print(igniteVersion); | ||
print(''); | ||
await runExecutableArguments('dart', ['--version'], verbose: true); | ||
print(''); | ||
await runExecutableArguments('flutter', ['--version'], verbose: true); | ||
Future<void> versionCommand(Logger logger) async { | ||
logger.info('ignite --version: $igniteVersion\n'); | ||
|
||
final [dartProcess, flutterProcess] = await [ | ||
runExecutableArguments( | ||
'dart', | ||
['--version'], | ||
commandVerbose: false, | ||
verbose: false, | ||
), | ||
runExecutableArguments( | ||
'flutter', | ||
['--version'], | ||
commandVerbose: false, | ||
verbose: false, | ||
), | ||
].wait; | ||
|
||
logger.info('${dartProcess.stdout}'); | ||
logger.info('${flutterProcess.stdout}'); | ||
|
||
if (dartProcess.stderr case final String err when err.isNotEmpty) { | ||
logger.err(err); | ||
} | ||
if (flutterProcess.stderr case final String err when err.isNotEmpty) { | ||
logger.err(err); | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can just remove the override - it will be true by default :)