diff --git a/lib/src/commands/key.dart b/lib/src/commands/key.dart index b25f5340..9ca570e5 100644 --- a/lib/src/commands/key.dart +++ b/lib/src/commands/key.dart @@ -20,23 +20,9 @@ class KeyCommand extends Command { changeSecret(File file, String secret) async { if (await file.exists()) { - bool foundSecret = false; - var sink = await file.openWrite(mode: FileMode.APPEND); - - await for (var chunk in await file.openRead().transform(UTF8.decoder)) { - var lines = chunk.split('\n'); - - for (String line in lines) { - if (line.contains('jwt_secret:')) { - foundSecret = true; - sink.writeln('jwt_secret: $secret'); - } else - sink.writeln(line); - } - } - - if (!foundSecret) sink.writeln('jwt:secret: $secret'); - await sink.close(); + var contents = await file.readAsString(); + contents = contents.replaceAll(new RegExp(r'jwt_secret:[^\n]+\n?'), ''); + await file.writeAsString(contents.trim() + '\njwt_secret: $secret'); } } } diff --git a/pubspec.yaml b/pubspec.yaml index 185977ec..80f82d27 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_cli -version: 1.0.0-dev+14 +version: 1.0.0-dev+15 description: Command-line tools for the Angel framework. environment: sdk: ">=1.19.0"