Upgraded package cli

This commit is contained in:
thomashii 2021-03-06 19:56:49 +08:00
parent c5e7de1b97
commit 326d2d0c59
6 changed files with 50 additions and 41 deletions

1
.gitignore vendored
View file

@ -14,6 +14,7 @@
.metals/
build/
#**/packages/
packages/hubbub/
# Files created by dart2js
# (Most Dart developers will use pub build to compile Dart, use/modify these

View file

@ -12,7 +12,7 @@ import 'pub.dart';
import 'rename.dart';
class InitCommand extends Command {
final KeyCommand _key = new KeyCommand();
final KeyCommand _key = KeyCommand();
@override
String get name => "init";
@ -35,21 +35,19 @@ class InitCommand extends Command {
@override
run() async {
Directory projectDir =
new Directory(argResults.rest.isEmpty ? "." : argResults.rest[0]);
Directory(argResults.rest.isEmpty ? "." : argResults.rest[0]);
print("Creating new Angel project in ${projectDir.absolute.path}...");
await _cloneRepo(projectDir);
// await preBuild(projectDir);
var secret = rs.randomAlphaNumeric(32);
print('Generated new development JWT secret: $secret');
await _key.changeSecret(
new File.fromUri(projectDir.uri.resolve('config/default.yaml')),
secret);
File.fromUri(projectDir.uri.resolve('config/default.yaml')), secret);
secret = rs.randomAlphaNumeric(32);
print('Generated new production JWT secret: $secret');
await _key.changeSecret(
new File.fromUri(projectDir.uri.resolve('config/production.yaml')),
secret);
File.fromUri(projectDir.uri.resolve('config/production.yaml')), secret);
var name = argResults.wasParsed('project-name')
? argResults['project-name'] as String
@ -110,9 +108,9 @@ class InitCommand extends Command {
switch (stat.type) {
case FileSystemEntityType.directory:
return await _deleteRecursive(new Directory(path));
return await _deleteRecursive(Directory(path));
case FileSystemEntityType.file:
return await _deleteRecursive(new File(path));
return await _deleteRecursive(File(path));
default:
break;
}
@ -198,7 +196,7 @@ class InitCommand extends Command {
}
if (await git.exitCode != 0) {
throw new Exception("Could not clone repo.");
throw Exception("Could not clone repo.");
}
}
@ -224,7 +222,7 @@ class InitCommand extends Command {
await preBuild(projectDir).catchError((_) => null);
}
var gitDir = new Directory.fromUri(projectDir.uri.resolve(".git"));
var gitDir = Directory.fromUri(projectDir.uri.resolve(".git"));
if (await gitDir.exists()) await gitDir.delete(recursive: true);
} catch (e) {
await boilerplateDir.delete(recursive: true).catchError((_) => null);
@ -260,7 +258,7 @@ Future preBuild(Directory projectDir) async {
var buildCode = await build.exitCode;
if (buildCode != 0) throw new Exception('Failed to pre-build resources.');
if (buildCode != 0) throw Exception('Failed to pre-build resources.');
}
const RepoArchiveLocation = "https://github.com/angel-dart";

View file

@ -3,7 +3,7 @@ import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:glob/glob.dart';
import 'package:io/ansi.dart';
import 'package:mustache4dart/mustache4dart.dart' as mustache;
import 'package:mustache4dart2/mustache4dart2.dart' as mustache;
import 'package:path/path.dart' as p;
import 'package:prompts/prompts.dart' as prompts;
import 'package:pubspec_parse/pubspec_parse.dart';

View file

@ -1,8 +1,10 @@
import 'dart:io';
import 'package:analyzer/analyzer.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:args/command_runner.dart';
import 'package:dart_style/dart_style.dart';
import 'package:glob/glob.dart';
import 'package:glob/list_local_fs.dart';
import 'package:io/ansi.dart';
import 'package:prompts/prompts.dart' as prompts;
import 'package:recase/recase.dart';
@ -14,7 +16,7 @@ class RenameCommand extends Command {
String get name => 'rename';
@override
String get description => 'Renames the current project.';
String get description => 'Renames the current project (To be available).';
@override
String get invocation => '$name <new name>';
@ -33,7 +35,10 @@ class RenameCommand extends Command {
var choice = prompts.getBool('Rename the project to `$newName`?');
// TODO: To be available once the issue is fixed
if (choice) {
print('Rename the project is currently not available');
/*
print('Renaming project to `$newName`...');
var pubspecFile =
File.fromUri(Directory.current.uri.resolve('pubspec.yaml'));
@ -53,6 +58,7 @@ class RenameCommand extends Command {
stderr.addStream(pub.stderr);
await pub.exitCode;
}
*/
}
}
}
@ -61,7 +67,7 @@ renamePubspec(Directory dir, String oldName, String newName) async {
// var pubspec = await loadPubspec(dir);
print(cyan.wrap('Renaming your project to `$newName.`'));
var pubspecFile = new File.fromUri(dir.uri.resolve('pubspec.yaml'));
var pubspecFile = File.fromUri(dir.uri.resolve('pubspec.yaml'));
if (await pubspecFile.exists()) {
var contents = await pubspecFile.readAsString(), oldContents = contents;
@ -91,9 +97,11 @@ renameDartFiles(Directory dir, String oldName, String newName) async {
if (yamlFile is File) {
print(
'Replacing occurrences of "$oldName" with "$newName" in file "${yamlFile.absolute.path}"...');
var contents = await yamlFile.readAsString();
contents = contents.replaceAll(oldName, newName);
await yamlFile.writeAsString(contents);
if (yamlFile is File) {
var contents = (yamlFile as File).readAsStringSync();
contents = contents.replaceAll(oldName, newName);
(yamlFile as File).writeAsStringSync(contents);
}
}
}
} catch (_) {}
@ -109,9 +117,12 @@ renameDartFiles(Directory dir, String oldName, String newName) async {
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 = RenamingVisitor(oldName, newName)
..visitCompilationUnit(ast);
// TODO: Issue to be fixed: parseCompilationUnit uses Hubbub library which uses discontinued Google front_end library
// front_end package. Temporarily commeted out
//var ast = parseCompilationUnit(contents);
var visitor = RenamingVisitor(oldName, newName);
// ..visitCompilationUnit(ast);
if (visitor.replace.isNotEmpty) {
visitor.replace.forEach((range, replacement) {

View file

@ -1,28 +1,27 @@
author: Tobe O <thosakwe@gmail.com>
#author: Tobe O <thosakwe@gmail.com>
description: Command-line tools for the Angel framework, including scaffolding.
homepage: https://github.com/angel-dart/angel_cli
homepage: https://github.com/dukefirehawk/angel/packages/angel_cli
name: angel_cli
version: 2.2.0
version: 2.3.0
environment:
sdk: ">=2.10.0 <2.12.0"
sdk: ">=2.10.0 <3.0.0"
dependencies:
analyzer: ^0.39.17
args: ^1.0.0
analyzer: ^1.1.0
args: ^2.0.0
code_builder: ^3.0.0
dart_style: ^1.0.0
glob: ^1.1.0
http: ^0.12.0
io: ^0.3.2
glob: ^2.0.0
http: ^0.13.0
io: ^0.3.5
inflection2: ^0.4.2
mustache4dart: ^3.0.0-dev.1.0
mustache4dart2: ^0.1.0
path: ^1.0.0
prompts: ^1.0.0
pubspec_parse: ^0.1.2
quiver: ^2.0.0
recase: ^2.0.0
prompts: ^1.3.1
pubspec_parse: ^1.0.0
quiver: ^3.0.0
recase: ^3.0.1
shutdown: ^0.4.0
watcher: ^0.9.7
yaml: ^2.0.0
#yamlicious: ^0.0.5
watcher: ^1.0.0
yaml: ^3.0.0
executables:
angel: angel

View file

@ -1,8 +1,8 @@
name: angel_http_exception
version: 1.1.0
version: 2.3.0
description: Exception class that can be serialized to JSON and serialized to clients.
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/http_exception
#author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/dukefirehawk/angel/packages/http_exception
environment:
sdk: ">=2.10.0 <3.0.0"
dev_dependencies: