From b3232b03afaf947ae2301765ed3fa4b6bb4869eb Mon Sep 17 00:00:00 2001 From: thosakwe Date: Fri, 3 Mar 2017 23:14:39 -0500 Subject: [PATCH] 1.0.4 --- lib/src/commands/init.dart | 6 ++++ lib/src/commands/rename.dart | 52 +++++++++++++++++------------------ lib/src/commands/service.dart | 4 +-- pubspec.yaml | 2 +- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/lib/src/commands/init.dart b/lib/src/commands/init.dart index a8d35a6e..3d775f12 100644 --- a/lib/src/commands/init.dart +++ b/lib/src/commands/init.dart @@ -2,7 +2,9 @@ import "dart:io"; import "package:args/command_runner.dart"; import "package:console/console.dart"; import 'package:random_string/random_string.dart' as rs; +import 'package:path/path.dart' as p; import 'key.dart'; +import 'rename.dart'; class InitCommand extends Command { final KeyCommand _key = new KeyCommand(); @@ -40,6 +42,10 @@ class InitCommand extends Command { await _key.changeSecret( new File.fromUri(projectDir.uri.resolve('config/production.yaml')), secret); + + var name = p.basenameWithoutExtension(projectDir.path); + print('Renaming project from "angel" to "$name"...'); + await renameDartFiles(projectDir, 'angel', name); } _cloneRepo(Directory projectDir) async { diff --git a/lib/src/commands/rename.dart b/lib/src/commands/rename.dart index cfa9beea..89019528 100644 --- a/lib/src/commands/rename.dart +++ b/lib/src/commands/rename.dart @@ -42,7 +42,7 @@ class RenameCommand extends Command { var newPubspec = new PubSpec.fromJson(pubspec.toJson()..['name'] = newName); await newPubspec.save(Directory.current); - await renameDartFiles(oldName, newName); + await renameDartFiles(Directory.current, oldName, newName); print('Now running `pub get`...'); var pub = await Process.start('pub', ['get']); stdout.addStream(pub.stdout); @@ -51,37 +51,35 @@ class RenameCommand extends Command { } } } +} - renameDartFiles(String oldName, String newName) async { - var entry = - new File.fromUri(Directory.current.uri.resolve('lib/$oldName.dart')); +renameDartFiles(Directory dir, String oldName, String newName) async { + var entry = new File.fromUri(dir.uri.resolve('lib/$oldName.dart')); - if (await entry.exists()) { - await entry.rename('lib/$newName.dart'); - print('Renaming library file `${entry.absolute.path}`...'); - } + if (await entry.exists()) { + await entry.rename('lib/$newName.dart'); + print('Renaming library file `${entry.absolute.path}`...'); + } - await for (FileSystemEntity file - in Directory.current.list(recursive: true)) { - if (file is File && file.path.endsWith('.dart')) { - var contents = await file.readAsString(); - var ast = parseCompilationUnit(contents); - var visitor = new RenamingVisitor(oldName, newName) - ..visitCompilationUnit(ast); + await for (FileSystemEntity file in dir.list(recursive: true)) { + if (file is File && file.path.endsWith('.dart')) { + var contents = await file.readAsString(); + var ast = parseCompilationUnit(contents); + var visitor = new RenamingVisitor(oldName, newName) + ..visitCompilationUnit(ast); - if (visitor.replace.isNotEmpty) { - visitor.replace.forEach((range, replacement) { - if (range.first is int) { - contents = - contents.replaceRange(range.first, range.last, replacement); - } else if (range.first is String) { - contents = contents.replaceAll(range.first, replacement); - } - }); + if (visitor.replace.isNotEmpty) { + visitor.replace.forEach((range, replacement) { + if (range.first is int) { + contents = + contents.replaceRange(range.first, range.last, replacement); + } else if (range.first is String) { + contents = contents.replaceAll(range.first, replacement); + } + }); - await file.writeAsString(contents); - print('Updated file `${file.absolute.path}`.'); - } + await file.writeAsString(contents); + print('Updated file `${file.absolute.path}`.'); } } } diff --git a/lib/src/commands/service.dart b/lib/src/commands/service.dart index aa1bf75a..71f2945f 100644 --- a/lib/src/commands/service.dart +++ b/lib/src/commands/service.dart @@ -61,7 +61,7 @@ class ServiceCommand extends Command { await serviceFile .writeAsString(_generateService(generator, name, lower, typed)); - await testFile.writeAsString(_generateTests(lower, type)); + await testFile.writeAsString(_generateTests(pubspec, lower)); var runConfig = new File('./.idea/runConfigurations/${name}_Tests.xml'); @@ -206,7 +206,7 @@ final Validator CREATE_$constantCase = $constantCase.extend({}) .trim(); } - _generateTests(PubSpec pubspec, String lower, String type) { + _generateTests(PubSpec pubspec, String lower) { return ''' import 'dart:io'; import 'package:${pubspec.name}/${pubspec.name}.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index bbe944d2..12e0e1d1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ author: "Tobe O " description: "Command-line tools for the Angel framework." homepage: "https://github.com/angel-dart/angel_cli" name: "angel_cli" -version: "1.0.3" +version: "1.0.4" dependencies: analyzer: "^0.29.0" args: "^0.13.7"