mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-06-27 06:43:13 +00:00
1.3
This commit is contained in:
47
lib/builder.dart
Normal file
47
lib/builder.dart
Normal file
@ -0,0 +1,47 @@
|
||||
import 'package:source_gen/source_gen.dart';
|
||||
import 'package:build/build.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
Builder iipService(BuilderOptions options) {
|
||||
return LibraryBuilder(TemplateGenerator(), generatedExtension: '.info.dart');
|
||||
}
|
||||
|
||||
class TemplateBuilder implements Builder {
|
||||
//BuilderOptions options;
|
||||
String _fileName;
|
||||
TemplateBuilder([BuilderOptions options]) : _fileName = _get_dest(options);
|
||||
|
||||
@override
|
||||
Future build(BuildStep buildStep) async {
|
||||
final id = AssetId(buildStep.inputId.package, _fileName);
|
||||
|
||||
// generate
|
||||
var content = "Testing";
|
||||
|
||||
await buildStep.writeAsString(id, content);
|
||||
}
|
||||
|
||||
static String _get_dest(BuilderOptions options) {
|
||||
const defaultDestination = 'lib/src/iip_template.dart';
|
||||
if (options == null) return defaultDestination;
|
||||
if (options.config == null) return defaultDestination;
|
||||
return options.config['destination_file'] as String ?? defaultDestination;
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, List<String>> get buildExtensions {
|
||||
return {
|
||||
'.iip.yaml': [".iip.dart"]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class TemplateGenerator extends Generator {
|
||||
@override
|
||||
String generate(LibraryReader library, BuildStep buildStep) {
|
||||
return '''
|
||||
// Source library: ${library.element.source.uri}
|
||||
const Testinggggg = 3;
|
||||
''';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user