build_it 0.2.8 build_it: ^0.2.8 copied to clipboard
The `build_it`is a builder that makes publicly available third-party source code generators and runs them during the build process for rapid development.
import 'package:build_it/build_it_helper.dart';
import 'package:json_helpers/json_helpers.dart';
Future<void> main(List<String> args, [message]) async {
return await buildIt(args, message, _build);
}
Future<BuildResult> _build(BuildConfig config) async {
const _template = '''
void main() {
stdout.writeln('Hello, {{NAME}}');
}
''';
final data = config.data.json((e) => Data.fromMap(e));
final name = data.name;
final code = <String>[];
final template = _template.replaceAll('{{NAME}}', name);
code.add(template);
final directives = <Directive>[];
directives.add(Directive(type: 'import', url: 'dart:io'));
return BuildResult(code: code.join('\n'), directives: directives);
}
class Data {
final String name;
Data({required this.name});
factory Data.fromMap(Map<String, dynamic> json) {
return Data(name: (json['name'] as String?) ?? '');
}
}