-
Notifications
You must be signed in to change notification settings - Fork 53
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
Remove package:cli_config
& package:args
dependencies in package:native_asset_cli
#1598
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
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
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,18 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
String getConfigArgument(List<String> arguments) { | ||
for (var i = 0; i < arguments.length; ++i) { | ||
final argument = arguments[i]; | ||
if (argument.startsWith('--config=')) { | ||
return argument.substring('--config='.length); | ||
} | ||
if (argument == '--config') { | ||
if ((i + 1) < arguments.length) { | ||
return arguments[i + 1]; | ||
} | ||
} | ||
} | ||
throw StateError('No --config argument given.'); | ||
} |
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,106 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:core'; | ||
import 'dart:core' as core; | ||
import 'dart:io'; | ||
|
||
extension JsonUtils on Map<String, Object?> { | ||
String string(String key, {Iterable<String>? validValues}) { | ||
final value = get<String>(key); | ||
if (validValues != null && !validValues.contains(value)) { | ||
throw FormatException('Json "$key" had value $value but expected one of ' | ||
'${validValues.join(',')}'); | ||
} | ||
return value; | ||
} | ||
|
||
String? optionalString(String key) => getOptional<String>(key); | ||
|
||
bool? optionalBool(String key) => getOptional<bool>(key); | ||
core.int int(String key) => get<core.int>(key); | ||
core.int? optionalInt(String key) => getOptional<core.int>(key); | ||
|
||
Uri path(String key, | ||
{required Uri baseUri, | ||
bool resolveUri = true, | ||
bool mustExist = false}) => | ||
_pathToUri(get<String>(key), baseUri: baseUri, resolveUri: resolveUri); | ||
|
||
Uri? optionalPath(String key, | ||
{required Uri baseUri, bool resolveUri = true, bool mustExist = false}) { | ||
final value = getOptional<String>(key); | ||
if (value == null) return null; | ||
final uri = _pathToUri(value, baseUri: baseUri, resolveUri: resolveUri); | ||
if (mustExist) { | ||
_throwIfNotExists(key, uri); | ||
} | ||
return uri; | ||
} | ||
|
||
List<String>? optionalStringList(String key) { | ||
final value = getOptional<List<Object?>>(key); | ||
if (value == null) return null; | ||
return value.cast<String>(); | ||
} | ||
|
||
List<Object?> list(String key) => get<List<Object?>>(key); | ||
List<Object?>? optionalList(String key) => getOptional<List<Object?>>(key); | ||
Map<String, Object?>? optionalMap(String key) => | ||
getOptional<Map<String, Object?>>(key); | ||
|
||
T get<T extends Object>(String key) { | ||
final value = this[key]; | ||
if (value == null) { | ||
throw FormatException('No value was provided for required key: $key'); | ||
} | ||
if (value is T) return value; | ||
throw FormatException( | ||
'Unexpected value \'$value\' for key \'.$key\' in config file. ' | ||
'Expected a $T.'); | ||
} | ||
|
||
T? getOptional<T extends Object>(String key) { | ||
final value = this[key]; | ||
if (value is T?) return value; | ||
throw FormatException( | ||
'Unexpected value \'$value\' for key \'.$key\' in config file. ' | ||
'Expected a $T?.'); | ||
} | ||
} | ||
|
||
Uri _pathToUri( | ||
String path, { | ||
required core.bool resolveUri, | ||
required Uri? baseUri, | ||
}) { | ||
final uri = _fileSystemPathToUri(path); | ||
if (resolveUri && baseUri != null) { | ||
return baseUri.resolveUri(uri); | ||
} | ||
return uri; | ||
} | ||
|
||
void _throwIfNotExists(String key, Uri value) { | ||
final fileSystemEntity = value.fileSystemEntity; | ||
if (!fileSystemEntity.existsSync()) { | ||
throw FormatException("Path '$value' for key '$key' doesn't exist."); | ||
} | ||
} | ||
|
||
extension on Uri { | ||
FileSystemEntity get fileSystemEntity { | ||
if (path.endsWith(Platform.pathSeparator) || path.endsWith('/')) { | ||
return Directory.fromUri(this); | ||
} | ||
return File.fromUri(this); | ||
} | ||
} | ||
|
||
Uri _fileSystemPathToUri(String path) { | ||
if (path.endsWith(Platform.pathSeparator)) { | ||
return Uri.directory(path); | ||
} | ||
return Uri.file(path); | ||
} |
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.
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 could actually decide that instead of making this based on arguments we set a
DART_BUILD_HOOK_CONFIG
environment variable containing the configuration.