Skip to content

Commit dedd595

Browse files
authored
Merge pull request #4 from Mankeli-Software/development
Development
2 parents 88ecdb0 + 2fe857c commit dedd595

18 files changed

+202
-104
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ coverage/
1212
.test_runner.dart
1313

1414
# Android studio and IntelliJ
15-
.idea
15+
.idea

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# dart_define changelog
22

3+
## 2.0.1
4+
5+
- feat(BREAKING CHANGE): adds ability to append gitignore with generated json config file. This can be done with `--[no-]gitignore` flag. By default, it will append to gitignore.
6+
- fix: fixes issues with yaml_path argument breaking other options.
7+
38
## 1.0.6
49

510
- feat: makes it possible to change config yaml file location

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [Using the configuration ⚙️](#using-the-configuration-️)
1212
- [Configuring CI/CD pipeline ✔️](#configuring-cicd-pipeline-️)
1313
- [Setting up flavors 🍬](#setting-up-flavors-)
14+
- [Using custom yaml path 📁](#using-custom-yaml-path-)
1415

1516
## Motivation 🔥
1617

@@ -312,4 +313,10 @@ with the configurations. To set these up
312313
flutter run --dart-define-from-file=config/development.json
313314
```
314315

316+
## Using custom yaml path 📁
317+
318+
By default, `dart_define` will look for the configurations under the
319+
`pubspec.yaml` file in the project root. To change this behavior,
320+
you can specify a new yaml file with the `--yaml_path` flag.
321+
315322
[1]: https://itnext.io/flutter-3-7-and-a-new-way-of-defining-compile-time-variables-f63db8a4f6e2

example/.gitignore

-44
Original file line numberDiff line numberDiff line change
@@ -1,44 +0,0 @@
1-
# Miscellaneous
2-
*.class
3-
*.log
4-
*.pyc
5-
*.swp
6-
.DS_Store
7-
.atom/
8-
.buildlog/
9-
.history
10-
.svn/
11-
migrate_working_dir/
12-
13-
# IntelliJ related
14-
*.iml
15-
*.ipr
16-
*.iws
17-
.idea/
18-
19-
# The .vscode folder contains launch configuration and tasks you configure in
20-
# VS Code which you may wish to be included in version control, so this line
21-
# is commented out by default.
22-
#.vscode/
23-
24-
# Flutter/Dart/Pub related
25-
**/doc/api/
26-
**/ios/Flutter/.last_build_id
27-
.dart_tool/
28-
.flutter-plugins
29-
.flutter-plugins-dependencies
30-
.packages
31-
.pub-cache/
32-
.pub/
33-
/build/
34-
35-
# Symbolication related
36-
app.*.symbols
37-
38-
# Obfuscation related
39-
app.*.map.json
40-
41-
# Android Studio will place build artifacts here
42-
/android/app/debug
43-
/android/app/profile
44-
/android/app/release

example/dart_define.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"STRING_VALUE": "hello world!",
33
"INT_VALUE": 3,
4-
"BOOL_VALUE": false,
5-
"FLAVOR": "production"
4+
"BOOL_VALUE": true,
5+
"FLAVOR": "development"
66
}
77

example/pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ dart_define:
3737
required: false
3838
- name: BOOL_VALUE
3939
description: An example bool value
40-
required: true
40+
default: true
41+
required: false
4142
flavors: # OPTIONAL: The flavors to use within the app
4243
- name: production # REQUIRED: The name of the flavor
4344
description: The production flavor # REQUIRED: The description of the flavor

lib/dart_define.gen.dart

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This file was generated by package:dart_define, DO NOT modify or remove these comments
2+
class DartDefine {
3+
DartDefine._();
4+
5+
}
6+
7+

lib/src/command_runner.dart

+21-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'package:args/command_runner.dart';
33
import 'package:cli_completion/cli_completion.dart';
44
import 'package:cmd_plus/cmd_plus.dart';
55
import 'package:dart_define/src/commands/commands.dart';
6-
import 'package:dart_define/src/extension/extension.dart';
76
import 'package:dart_define/src/resource/resource.dart';
87
import 'package:dart_define/src/version.gen.dart';
98
import 'package:pub_updater/pub_updater.dart';
@@ -48,31 +47,31 @@ class DartDefineCommandRunner extends CompletionCommandRunner<int> {
4847
final Logger _logger;
4948
final PubUpdater _pubUpdater;
5049

51-
@override
52-
Future<int> run(Iterable<String> args) async {
53-
final cmdPlus = CmdPlus();
50+
String? parseOption(Iterable<String> args, String optionName) {
51+
final joinedArgs = args.join(' ');
5452

55-
final parser = ArgParser()
56-
..addOption(kYamlPathArg)
57-
..addFlag(
58-
'help',
59-
abbr: 'h',
60-
negatable: false,
61-
help: 'Print this usage information.',
62-
);
53+
final regex = RegExp(
54+
'--$optionName' r'(?:=|\s+)(\S+)',
55+
);
6356

64-
final results = parser.parse(args);
57+
final match = regex.firstMatch(joinedArgs);
6558

66-
final yamlPath = results.getAndMaybeOverrideOriginal<String>(
67-
kYamlPathArg,
68-
kYamlPathArgDefault,
69-
);
59+
if (match != null) {
60+
final value = match.group(1);
61+
return value;
62+
}
63+
64+
return null;
65+
}
66+
67+
@override
68+
Future<int> run(Iterable<String> args) async {
69+
final cmdPlus = CmdPlus();
7070

71-
cmdPlus.logger.info('Using config file: $yamlPath');
72-
cmdPlus.logger.info('Args: $args');
73-
cmdPlus.logger.info('Results: $results');
74-
cmdPlus.logger.info('Options: ${results.options}');
75-
cmdPlus.logger.info('Args: ${results.arguments}');
71+
/// As ArgParser fails on unknown options and we will specify options
72+
/// from the config file, we can't use ArgParser here. Thats why
73+
/// we parse the yaml path with its own function.
74+
final yamlPath = parseOption(args, kYamlPathArg) ?? kYamlPathArgDefault;
7675

7776
// Add sub commands
7877
addCommand(

lib/src/commands/src/generate_command.dart

+23-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class GenerateCommand extends Command<int> {
2828
..addSeparator('Config overrides from $yamlPath');
2929

3030
final readingConfig = cmdPlus.logger.progress(
31-
'Reading config from pubspec.yaml',
31+
'Reading config from $yamlPath',
3232
);
3333

3434
final yaml = DartDefineYaml();
@@ -107,6 +107,11 @@ class GenerateCommand extends Command<int> {
107107
kGenerateJsonArg,
108108
help: 'Whether to generate the json boilerplate or not',
109109
defaultsTo: config.generateJson,
110+
)
111+
..addFlag(
112+
kGenerateGitignore,
113+
help: 'Whether to append gitignore with the config json or not',
114+
defaultsTo: config.generateGitignore,
110115
);
111116
}
112117

@@ -140,6 +145,10 @@ class GenerateCommand extends Command<int> {
140145
kGenerateJsonArg,
141146
config.generateJson,
142147
);
148+
final generateGitignore = argResults!.getAndMaybeOverrideOriginal<bool>(
149+
kGenerateGitignore,
150+
config.generateGitignore,
151+
);
143152

144153
final className = argResults!.getAndMaybeOverrideOriginal<String>(
145154
kClassNameArg,
@@ -217,6 +226,19 @@ class GenerateCommand extends Command<int> {
217226
generatingDart.complete();
218227
}
219228

229+
if (generateGitignore && generateJson) {
230+
final generatingGitignore = cmdPlus.logger.progress(
231+
'Generating gitignore',
232+
);
233+
234+
GitignoreConfigurationGenerator(
235+
target: File('.gitignore'),
236+
jsonPath: jsonPath,
237+
).generate();
238+
239+
generatingGitignore.complete();
240+
}
241+
220242
return ExitCode.success.code;
221243
}
222244
}

lib/src/model/src/dart_define_configuration.dart

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ class DartDefineConfiguration with _$DartDefineConfiguration {
3535
defaultValue: kGenerateJsonArgDefault,
3636
)
3737
bool generateJson,
38+
@Default(kGenerateGitignoreDefault)
39+
@JsonKey(
40+
name: kGenerateGitignore,
41+
defaultValue: kGenerateGitignoreDefault,
42+
)
43+
bool generateGitignore,
3844
@Default(kDartPathArgDefault)
3945
@JsonKey(
4046
name: kDartPathArg,

lib/src/model/src/dart_define_configuration.g.dart

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)