run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<void> run() async {
CompilerLogger.verbose = argResults?['verbose'] == true;
final cwd = Directory.current.path;
final srcDir = Directory(p.join(cwd, 'src'));
if (!srcDir.existsSync()) {
print('No src/ directory found. Run "roblox-dart init" first.');
return;
}
final compiler = RobloxCompiler(projectRoot: cwd, sourceRoot: srcDir.path);
print('Building...');
final dartFiles = srcDir
.listSync(recursive: true)
.whereType<File>()
.where((f) => f.path.endsWith('.dart'));
for (final file in dartFiles) {
await _compile(compiler, file, cwd);
}
print('Build complete. Watching for changes...');
srcDir.watch(recursive: true).listen((event) async {
if (!event.path.endsWith('.dart')) return;
if (event.type == FileSystemEvent.modify ||
event.type == FileSystemEvent.create) {
print('Changed: ${p.relative(event.path, from: cwd)}');
await _compile(compiler, File(event.path), cwd);
}
});
await Completer<void>().future;
}