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:args/command_runner.dart";
|
||||||
import "package:console/console.dart";
|
import "package:console/console.dart";
|
||||||
import 'package:random_string/random_string.dart' as rs;
|
import 'package:random_string/random_string.dart' as rs;
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
import 'key.dart';
|
import 'key.dart';
|
||||||
|
import 'rename.dart';
|
||||||
|
|
||||||
class InitCommand extends Command {
|
class InitCommand extends Command {
|
||||||
final KeyCommand _key = new KeyCommand();
|
final KeyCommand _key = new KeyCommand();
|
||||||
|
@ -40,6 +42,10 @@ class InitCommand extends Command {
|
||||||
await _key.changeSecret(
|
await _key.changeSecret(
|
||||||
new File.fromUri(projectDir.uri.resolve('config/production.yaml')),
|
new File.fromUri(projectDir.uri.resolve('config/production.yaml')),
|
||||||
secret);
|
secret);
|
||||||
|
|
||||||
|
var name = p.basenameWithoutExtension(projectDir.path);
|
||||||
|
print('Renaming project from "angel" to "$name"...');
|
||||||
|
await renameDartFiles(projectDir, 'angel', name);
|
||||||
}
|
}
|
||||||
|
|
||||||
_cloneRepo(Directory projectDir) async {
|
_cloneRepo(Directory projectDir) async {
|
||||||
|
|
|
@ -42,7 +42,7 @@ class RenameCommand extends Command {
|
||||||
var newPubspec =
|
var newPubspec =
|
||||||
new PubSpec.fromJson(pubspec.toJson()..['name'] = newName);
|
new PubSpec.fromJson(pubspec.toJson()..['name'] = newName);
|
||||||
await newPubspec.save(Directory.current);
|
await newPubspec.save(Directory.current);
|
||||||
await renameDartFiles(oldName, newName);
|
await renameDartFiles(Directory.current, oldName, newName);
|
||||||
print('Now running `pub get`...');
|
print('Now running `pub get`...');
|
||||||
var pub = await Process.start('pub', ['get']);
|
var pub = await Process.start('pub', ['get']);
|
||||||
stdout.addStream(pub.stdout);
|
stdout.addStream(pub.stdout);
|
||||||
|
@ -51,37 +51,35 @@ class RenameCommand extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
renameDartFiles(String oldName, String newName) async {
|
renameDartFiles(Directory dir, String oldName, String newName) async {
|
||||||
var entry =
|
var entry = new File.fromUri(dir.uri.resolve('lib/$oldName.dart'));
|
||||||
new File.fromUri(Directory.current.uri.resolve('lib/$oldName.dart'));
|
|
||||||
|
|
||||||
if (await entry.exists()) {
|
if (await entry.exists()) {
|
||||||
await entry.rename('lib/$newName.dart');
|
await entry.rename('lib/$newName.dart');
|
||||||
print('Renaming library file `${entry.absolute.path}`...');
|
print('Renaming library file `${entry.absolute.path}`...');
|
||||||
}
|
}
|
||||||
|
|
||||||
await for (FileSystemEntity file
|
await for (FileSystemEntity file in dir.list(recursive: true)) {
|
||||||
in Directory.current.list(recursive: true)) {
|
if (file is File && file.path.endsWith('.dart')) {
|
||||||
if (file is File && file.path.endsWith('.dart')) {
|
var contents = await file.readAsString();
|
||||||
var contents = await file.readAsString();
|
var ast = parseCompilationUnit(contents);
|
||||||
var ast = parseCompilationUnit(contents);
|
var visitor = new RenamingVisitor(oldName, newName)
|
||||||
var visitor = new RenamingVisitor(oldName, newName)
|
..visitCompilationUnit(ast);
|
||||||
..visitCompilationUnit(ast);
|
|
||||||
|
|
||||||
if (visitor.replace.isNotEmpty) {
|
if (visitor.replace.isNotEmpty) {
|
||||||
visitor.replace.forEach((range, replacement) {
|
visitor.replace.forEach((range, replacement) {
|
||||||
if (range.first is int) {
|
if (range.first is int) {
|
||||||
contents =
|
contents =
|
||||||
contents.replaceRange(range.first, range.last, replacement);
|
contents.replaceRange(range.first, range.last, replacement);
|
||||||
} else if (range.first is String) {
|
} else if (range.first is String) {
|
||||||
contents = contents.replaceAll(range.first, replacement);
|
contents = contents.replaceAll(range.first, replacement);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await file.writeAsString(contents);
|
await file.writeAsString(contents);
|
||||||
print('Updated file `${file.absolute.path}`.');
|
print('Updated file `${file.absolute.path}`.');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ class ServiceCommand extends Command {
|
||||||
|
|
||||||
await serviceFile
|
await serviceFile
|
||||||
.writeAsString(_generateService(generator, name, lower, typed));
|
.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');
|
var runConfig = new File('./.idea/runConfigurations/${name}_Tests.xml');
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ final Validator CREATE_$constantCase = $constantCase.extend({})
|
||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
_generateTests(PubSpec pubspec, String lower, String type) {
|
_generateTests(PubSpec pubspec, String lower) {
|
||||||
return '''
|
return '''
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:${pubspec.name}/${pubspec.name}.dart';
|
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."
|
description: "Command-line tools for the Angel framework."
|
||||||
homepage: "https://github.com/angel-dart/angel_cli"
|
homepage: "https://github.com/angel-dart/angel_cli"
|
||||||
name: "angel_cli"
|
name: "angel_cli"
|
||||||
version: "1.0.3"
|
version: "1.0.4"
|
||||||
dependencies:
|
dependencies:
|
||||||
analyzer: "^0.29.0"
|
analyzer: "^0.29.0"
|
||||||
args: "^0.13.7"
|
args: "^0.13.7"
|
||||||
|
|
Loading…
Reference in a new issue