This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into alestiago/remove-generator-script
- Loading branch information
Showing
5 changed files
with
445 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: ♻️ Sync Labels | ||
|
||
on: | ||
push: | ||
paths: | ||
- .github/labels.yml | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
labels: | ||
name: ♻️ Sync labels | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: ⤵️ Check out code from GitHub | ||
uses: actions/checkout@v4 | ||
|
||
- name: 🚀 Run Label Sync | ||
uses: srealmoreno/label-sync-action@v1 | ||
with: | ||
config-file: https://raw.githubusercontent.com/VeryGoodOpenSource/.github/main/.github/labels.yml |
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 |
---|---|---|
@@ -1,3 +1,87 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:mason/mason.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:very_good_flutter_plugin_hooks/src/cli/cli.dart'; | ||
|
||
/// The key for the `dartFixOutput` context variable. | ||
@visibleForTesting | ||
const dartFixOutputVariableKey = 'dartFixOutput'; | ||
|
||
Future<void> run( | ||
HookContext context, { | ||
@visibleForTesting VeryGoodCli veryGoodCli = VeryGoodCli.instance, | ||
@visibleForTesting DartCli dartCli = DartCli.instance, | ||
}) async { | ||
final dartFixOutput = context.vars.containsKey(dartFixOutputVariableKey) && | ||
context.vars[dartFixOutputVariableKey] as bool; | ||
if (dartFixOutput) { | ||
await _dartFixOutput( | ||
logger: context.logger, | ||
workingDirectory: Directory.current.path, | ||
veryGoodCli: veryGoodCli, | ||
dartCli: dartCli, | ||
); | ||
} | ||
} | ||
|
||
/// Attempts to `dart` fix and format the output. | ||
/// | ||
/// Since the template includes Dart files with templated variables, generating | ||
/// the template can cause the generated Dart files to be invalid. For example, | ||
/// if the user inputs a long enough package name, the generated Dart files may | ||
/// exceed the 80 character line limit enforced by the the Dart formatter. | ||
/// Running `dart fix` and `dart format` on the generated output ensures that | ||
/// the generated output is always valid. | ||
/// | ||
/// Before we can run `dart fix` and `dart format`, we need to ensure that the | ||
/// dependencies are installed. Doing so allows getting remote analysis options | ||
/// and allows the Dart code to resolve the imports. | ||
/// | ||
/// If the [DartCli] or [VeryGoodCli] is not installed, this function will log | ||
/// a warning and return immediately. | ||
Future<void> _dartFixOutput({ | ||
required Logger logger, | ||
required String workingDirectory, | ||
required VeryGoodCli veryGoodCli, | ||
required DartCli dartCli, | ||
}) async { | ||
if (!await dartCli.isInstalled(logger: logger)) { | ||
logger.warn( | ||
'''Could not fix output because Dart CLI is not installed.''', | ||
); | ||
return; | ||
} | ||
if (!await veryGoodCli.isInstalled(logger: logger)) { | ||
logger.warn( | ||
'''Could not fix output because Very Good CLI is not installed.''', | ||
); | ||
return; | ||
} | ||
|
||
Future<void> run(HookContext context) async {} | ||
try { | ||
await veryGoodCli.packagesGet( | ||
logger: logger, | ||
recursive: true, | ||
cwd: workingDirectory, | ||
); | ||
await dartCli.fix( | ||
logger: logger, | ||
apply: true, | ||
cwd: workingDirectory, | ||
); | ||
await dartCli.format( | ||
logger: logger, | ||
cwd: workingDirectory, | ||
); | ||
} on ProcessException catch (e) { | ||
logger.err( | ||
''' | ||
Running process ${e.executable} with ${e.arguments} failed: | ||
${e.message} | ||
''', | ||
); | ||
} catch (e) { | ||
logger.err('Unknown error occurred when fixing output: $e'); | ||
} | ||
} |
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
Oops, something went wrong.