From 886dd32167cd65471c970461ea137ff1e9ddf3c7 Mon Sep 17 00:00:00 2001 From: thosakwe Date: Sat, 4 Mar 2017 16:34:49 -0500 Subject: [PATCH] 1.0.5 --- lib/src/commands/init.dart | 11 +++++---- lib/src/commands/rename.dart | 23 +++++++++++++++---- .../service_generators/generator.dart | 2 +- lib/src/commands/start.dart | 15 +++++++----- pubspec.yaml | 2 +- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/src/commands/init.dart b/lib/src/commands/init.dart index 3d775f1..9a84bfa 100644 --- a/lib/src/commands/init.dart +++ b/lib/src/commands/init.dart @@ -25,11 +25,6 @@ class InitCommand extends Command { argResults.arguments.isEmpty ? "." : argResults.arguments[0]); print("Creating new Angel project in ${projectDir.absolute.path}..."); await _cloneRepo(projectDir); - _pen.green(); - _pen( - "${Icon.CHECKMARK} Successfully initialized Angel project. Now running pub get..."); - _pen(); - await _pubGet(projectDir); // await preBuild(projectDir); var secret = rs.randomAlphaNumeric(32); print('Generated new development JWT secret: $secret'); @@ -45,7 +40,13 @@ class InitCommand extends Command { var name = p.basenameWithoutExtension(projectDir.path); print('Renaming project from "angel" to "$name"...'); + await renamePubspec(projectDir, 'angel', name); await renameDartFiles(projectDir, 'angel', name); + _pen.green(); + _pen( + "${Icon.CHECKMARK} Successfully initialized Angel project. Now running pub get..."); + _pen(); + await _pubGet(projectDir); } _cloneRepo(Directory projectDir) async { diff --git a/lib/src/commands/rename.dart b/lib/src/commands/rename.dart index 8901952..1eee74a 100644 --- a/lib/src/commands/rename.dart +++ b/lib/src/commands/rename.dart @@ -39,9 +39,7 @@ class RenameCommand extends Command { } else { var pubspec = await PubSpec.load(Directory.current); var oldName = pubspec.name; - var newPubspec = - new PubSpec.fromJson(pubspec.toJson()..['name'] = newName); - await newPubspec.save(Directory.current); + await renamePubspec(Directory.current, oldName, newName); await renameDartFiles(Directory.current, oldName, newName); print('Now running `pub get`...'); var pub = await Process.start('pub', ['get']); @@ -53,11 +51,28 @@ class RenameCommand extends Command { } } +renamePubspec(Directory dir, String oldName, String newName) async { + var pubspec = await PubSpec.load(dir); + var newPubspec = new PubSpec.fromJson(pubspec.toJson()..['name'] = newName); + await newPubspec.save(dir); +} + renameDartFiles(Directory dir, String oldName, String newName) async { + // Try to replace MongoDB URL + var defaultYaml = new File.fromUri(dir.uri.resolve('config/default.yaml')); + + if (await defaultYaml.exists()) { + print('Changing MongoDB URL in file "${defaultYaml.absolute.path}"...'); + var contents = await defaultYaml.readAsString(); + contents = contents.replaceAll('mongodb://localhost:27017/$oldName', + 'mongodb://localhost:27017/$newName'); + await defaultYaml.writeAsString(contents); + } + var entry = new File.fromUri(dir.uri.resolve('lib/$oldName.dart')); if (await entry.exists()) { - await entry.rename('lib/$newName.dart'); + await entry.rename(dir.uri.resolve('lib/$newName.dart').toFilePath()); print('Renaming library file `${entry.absolute.path}`...'); } diff --git a/lib/src/commands/service_generators/generator.dart b/lib/src/commands/service_generators/generator.dart index 280962e..79ccc4f 100644 --- a/lib/src/commands/service_generators/generator.dart +++ b/lib/src/commands/service_generators/generator.dart @@ -8,7 +8,7 @@ class ServiceGenerator { bool get createsModel => true; bool get createsValidator => true; bool get exportedInServiceLibrary => true; - bool get injectsSingleton => true; + bool get injectsSingleton => false; bool get shouldRunBuild => false; void applyToLibrary(LibraryBuilder library, String name, String lower) {} diff --git a/lib/src/commands/start.dart b/lib/src/commands/start.dart index 04dc19d..02ac0c0 100644 --- a/lib/src/commands/start.dart +++ b/lib/src/commands/start.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:io'; import 'package:args/command_runner.dart'; import 'package:watcher/watcher.dart'; @@ -62,8 +63,8 @@ class StartCommand extends Command { try { var scripts = await Process.start('pub', ['global', 'run', 'scripts', 'start']); - stdout.addStream(scripts.stdout); - stderr.addStream(scripts.stderr); + listen(scripts.stdout, stdout); + listen(scripts.stderr, stderr); int code = await scripts.exitCode; if (code != 0) { @@ -94,10 +95,8 @@ class StartCommand extends Command { environment: env); try { - if (isNew) { - stdout.addStream(server.stdout); - stderr.addStream(server.stderr); - } + listen(server.stdout, stdout); + listen(server.stderr, stderr); } catch (e) { print(e); } @@ -110,3 +109,7 @@ class StartCommand extends Command { exitCode = await server.exitCode; } } + +void listen(Stream> stream, IOSink sink) { + stream.listen(sink.add); +} diff --git a/pubspec.yaml b/pubspec.yaml index 12e0e1d..a544d70 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.4" +version: "1.0.5" dependencies: analyzer: "^0.29.0" args: "^0.13.7"