1.0.4
This commit is contained in:
parent
1db250ca16
commit
b3232b03af
4 changed files with 34 additions and 30 deletions
|
@ -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 {
|
||||
|
|
|
@ -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}`.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -2,7 +2,7 @@ author: "Tobe O <thosakwe@gmail.com>"
|
|||
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"
|
||||
|
|
Loading…
Reference in a new issue