-
Notifications
You must be signed in to change notification settings - Fork 34
Add Support for Configuration of Dart JS Interop Gen #386
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2270518
Base config
nikeokoronkwo a47e696
Merge branch 'main' into nikeokoronkwo/issue376
nikeokoronkwo ca678f7
Added basic support for config and yaml config
nikeokoronkwo 8d7b452
Refactored intro for configuration
nikeokoronkwo 44850a9
Added preamble option
nikeokoronkwo 21f42e1
[web_generator] Configuration Support
nikeokoronkwo 34893ce
minor changes
nikeokoronkwo 634f864
Resolved all issues
nikeokoronkwo 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import 'package:dart_style/dart_style.dart'; | ||
import 'package:pub_semver/pub_semver.dart'; | ||
import 'package:yaml/yaml.dart'; | ||
|
||
abstract interface class Config { | ||
/// The name for the configuration | ||
String? get name; | ||
|
||
/// The description for the configuration | ||
String? get description; | ||
|
||
/// Preamble to add at the top of generated code | ||
String? get preamble; | ||
|
||
/// The input files | ||
List<String> get input; | ||
|
||
/// The output file or directory to write bindings to | ||
String get output; | ||
|
||
/// The configuration file | ||
Uri? get filename; | ||
|
||
/// The Dart Language Version to use | ||
Version get languageVersion; | ||
|
||
bool get singleFileOutput => input.length == 1; | ||
|
||
factory Config({ | ||
required List<String> input, | ||
required String output, | ||
required Version languageVersion, | ||
}) = ConfigImpl._; | ||
} | ||
|
||
class ConfigImpl implements Config { | ||
@override | ||
String? description; | ||
|
||
@override | ||
Uri? filename; | ||
|
||
@override | ||
List<String> input; | ||
|
||
@override | ||
String? name; | ||
|
||
@override | ||
String output; | ||
|
||
@override | ||
Version languageVersion; | ||
|
||
@override | ||
String? preamble; | ||
|
||
ConfigImpl._({ | ||
required this.input, | ||
required this.output, | ||
required this.languageVersion, | ||
}); | ||
|
||
@override | ||
// TODO: implement singleFileOutput | ||
bool get singleFileOutput => input.length == 1; | ||
} | ||
|
||
class YamlConfig implements Config { | ||
@override | ||
Uri filename; | ||
|
||
@override | ||
List<String> input; | ||
|
||
@override | ||
String? description; | ||
|
||
@override | ||
String? name; | ||
|
||
@override | ||
String output; | ||
|
||
@override | ||
bool get singleFileOutput => input.length == 1; | ||
|
||
@override | ||
Version languageVersion; | ||
|
||
@override | ||
String? preamble; | ||
|
||
YamlConfig._( | ||
{required this.filename, | ||
required this.input, | ||
required this.output, | ||
this.description, | ||
this.name, | ||
this.preamble, | ||
String? languageVersion}) | ||
: languageVersion = languageVersion == null | ||
? DartFormatter.latestLanguageVersion | ||
: Version.parse(languageVersion); | ||
|
||
factory YamlConfig.fromYaml(YamlMap yaml, {required String filename}) { | ||
List<String> input; | ||
final yamlInput = yaml['input']; | ||
if (yamlInput is YamlList) { | ||
input = yamlInput.map((y) => y is String ? y : y.toString()).toList(); | ||
} else if (yamlInput is String) { | ||
input = [yamlInput]; | ||
} else { | ||
throw TypeError(); | ||
} | ||
|
||
return YamlConfig._( | ||
filename: Uri.file(filename), | ||
input: input, | ||
output: yaml['output'] as String, | ||
name: yaml['name'] as String?, | ||
description: yaml['description'] as String?, | ||
languageVersion: yaml['language_version'] as String?, | ||
preamble: yaml['preamble'] as String?); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -21,3 +21,4 @@ dependencies: | |
path: ^1.8.3 | ||
pub_semver: ^2.1.5 | ||
test: ^1.24.4 | ||
yaml: ^3.1.3 |
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,5 @@ | ||
name: IDL Demo Gen | ||
preamble: | | ||
// GENERATED FILE: DO NOT EDIT | ||
input: intro.d.ts | ||
output: output.dart |
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,6 @@ | ||
name: Nanoid and Lodash | ||
preamble: | | ||
// GENERATED FILE: DO NOT EDIT | ||
input: | ||
nanoid: 'nanoid.d.ts' | ||
output: output |
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,9 @@ | ||
name: Nanoid and Lodash | ||
preamble: | | ||
// GENERATED FILE: DO NOT EDIT | ||
input: | ||
- 'nanoid.d.ts' | ||
- 'lodash.d.ts' | ||
output: | ||
- nanoid.dart | ||
- lodash.dart | ||
nikeokoronkwo marked this conversation as resolved.
Show resolved
Hide resolved
|
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,7 @@ | ||
name: Nanoid and Lodash | ||
preamble: | | ||
// GENERATED FILE: DO NOT EDIT | ||
input: | ||
- 'nanoid.d.ts' | ||
- 'lodash.d.ts' | ||
output: output |
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,66 @@ | ||
@TestOn('vm') | ||
library; | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:path/path.dart' as p; | ||
import 'package:test/test.dart'; | ||
import 'package:web_generator/src/config.dart'; | ||
import 'package:yaml/yaml.dart'; | ||
|
||
final configurationTests = { | ||
'basic': { | ||
'name': 'IDL Demo Gen', | ||
'single': true, | ||
'input': ['intro.d.ts'], | ||
'valid': true | ||
}, | ||
'multi_file': { | ||
'name': 'Nanoid and Lodash', | ||
'single': false, | ||
'input': ['nanoid.d.ts', 'lodash.d.ts'], | ||
'valid': true | ||
}, | ||
'invalid': {'valid': false}, | ||
'invalid_output': {'valid': false} | ||
}; | ||
|
||
void main() { | ||
group('Configuration Test', () { | ||
group('YAML Config Test', () { | ||
final assetsDir = p.join('test', 'assets'); | ||
|
||
final assets = Directory(assetsDir); | ||
|
||
for (final file in assets.listSync().whereType<File>().where((f) => | ||
p.basenameWithoutExtension(f.path).endsWith('_config') && | ||
p.extension(f.path) == '.yaml')) { | ||
final fileName = | ||
p.basenameWithoutExtension(file.path).replaceFirst('_config', ''); | ||
final fileContents = file.readAsStringSync(); | ||
final configTest = configurationTests[fileName]; | ||
|
||
if (configTest == null) continue; | ||
|
||
test(fileName, () { | ||
final yaml = loadYamlDocument(fileContents); | ||
|
||
if (configTest.containsKey('valid') && configTest['valid'] == false) { | ||
expect( | ||
() => YamlConfig.fromYaml(yaml.contents as YamlMap, | ||
filename: p.basename(file.path)), | ||
throwsA(isA<TypeError>())); | ||
} else { | ||
// validate | ||
final config = YamlConfig.fromYaml(yaml.contents as YamlMap, | ||
filename: p.basename(file.path)); | ||
|
||
expect(config.name, equals(configTest['name'])); | ||
expect(config.input, equals(configTest['input'])); | ||
expect(config.singleFileOutput, equals(configTest['single'])); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.