From a82f7479c601a15a112cbef9ebdd37fa50c2b432 Mon Sep 17 00:00:00 2001 From: thomashii Date: Sat, 13 Mar 2021 10:51:32 +0800 Subject: [PATCH] Updated to support SDK 2.12.x --- README.md | 6 ++- lib/src/commands/deploy.dart | 4 +- lib/src/commands/doctor.dart | 2 +- lib/src/commands/init.dart | 44 +++++++++--------- lib/src/commands/install.dart | 21 +++++---- lib/src/commands/key.dart | 6 +-- lib/src/commands/make.dart | 12 ++--- lib/src/commands/make/controller.dart | 2 +- lib/src/commands/pub.dart | 4 +- lib/src/commands/rename.dart | 45 ++++++++++++------- .../commands/service_generators/custom.dart | 2 +- .../commands/service_generators/rethink.dart | 2 +- lib/src/random_string.dart | 4 +- pubspec.yaml | 35 +++++++-------- 14 files changed, 102 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 3b96938..1aaea50 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,16 @@ Includes functionality such as: * Renaming projects * Much more... -To install: +* To install: ```bash $ pub global activate angel_cli ``` +* Install development version +`dart pub global activate --source path ./packages/cli` +`dart pub global activate --source git https://github.com/dukefirehawk/angel/packages/cli` + And then, for information on each command: ```bash diff --git a/lib/src/commands/deploy.dart b/lib/src/commands/deploy.dart index 92b5f82..9c95ea5 100644 --- a/lib/src/commands/deploy.dart +++ b/lib/src/commands/deploy.dart @@ -11,7 +11,7 @@ class DeployCommand extends Command { 'Generates scaffolding + helper functionality for deploying servers. Run this in your project root.'; DeployCommand() { - addSubcommand(new NginxCommand()); - addSubcommand(new SystemdCommand()); + addSubcommand(NginxCommand()); + addSubcommand(SystemdCommand()); } } diff --git a/lib/src/commands/doctor.dart b/lib/src/commands/doctor.dart index b435b6f..fc70af3 100644 --- a/lib/src/commands/doctor.dart +++ b/lib/src/commands/doctor.dart @@ -26,7 +26,7 @@ class DoctorCommand extends Command { print(green.wrap( "$checkmark Git executable found: v${version.replaceAll('git version', '').trim()}")); } else - throw new Exception("Git executable exit code not 0"); + throw Exception("Git executable exit code not 0"); } catch (exc) { print(red.wrap("$ballot Git executable not found")); } diff --git a/lib/src/commands/init.dart b/lib/src/commands/init.dart index 7dafb86..92f2ade 100644 --- a/lib/src/commands/init.dart +++ b/lib/src/commands/init.dart @@ -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,44 +258,48 @@ 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"; +const RepoLocation = "https://github.com/dukefirehawk"; + const BoilerplateInfo graphQLBoilerplate = const BoilerplateInfo( 'GraphQL', "A starting point for GraphQL API servers.", - 'https://github.com/angel-dart/angel.git', - ref: 'graphql', + '${RepoLocation}/boilerplates.git', + ref: 'graphql-sdk-2.12.x', ); const BoilerplateInfo ormBoilerplate = const BoilerplateInfo( 'ORM', "A starting point for applications that use Angel's ORM.", - 'https://github.com/angel-dart/angel.git', - ref: 'orm', + '${RepoLocation}/boilerplates.git', + ref: 'orm-sdk-2.12.x', ); const BoilerplateInfo basicBoilerplate = const BoilerplateInfo( 'Basic', 'Minimal starting point for Angel 2.x - A simple server with only a few additional packages.', - 'https://github.com/angel-dart/angel.git'); + '${RepoLocation}/boilerplates.git', + ref: 'basic-sdk-2.12.x'); const BoilerplateInfo legacyBoilerplate = const BoilerplateInfo( 'Legacy', 'Minimal starting point for applications running Angel 1.1.x.', - 'https://github.com/angel-dart/angel.git', + '${RepoArchiveLocation}/angel.git', ref: '1.1.x', ); const BoilerplateInfo sharedBoilerplate = const BoilerplateInfo( 'Shared', 'Holds common models and files shared across multiple Dart projects.', - 'https://github.com/angel-dart/boilerplate_shared.git'); + '${RepoLocation}/boilerplate_shared.git'); const BoilerplateInfo sharedOrmBoilerplate = const BoilerplateInfo( 'Shared (ORM)', 'Holds common models and files shared across multiple Dart projects.', - 'https://github.com/angel-dart/boilerplate_shared.git', + '${RepoLocation}/boilerplate_shared.git', ref: 'orm', ); @@ -306,8 +308,8 @@ const List boilerplates = const [ //legacyBoilerplate, ormBoilerplate, graphQLBoilerplate, - sharedBoilerplate, - sharedOrmBoilerplate, + //sharedBoilerplate, + //sharedOrmBoilerplate, ]; class BoilerplateInfo { diff --git a/lib/src/commands/install.dart b/lib/src/commands/install.dart index d7a9ec3..484fe12 100644 --- a/lib/src/commands/install.dart +++ b/lib/src/commands/install.dart @@ -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'; @@ -14,7 +14,7 @@ import 'make/maker.dart'; class InstallCommand extends Command { static const String repo = 'https://github.com/angel-dart/install.git'; static final Directory installRepo = - new Directory.fromUri(homeDir.uri.resolve('./.angel/addons')); + Directory.fromUri(homeDir.uri.resolve('./.angel/addons')); @override String get name => 'install'; @@ -72,7 +72,7 @@ class InstallCommand extends Command { for (var packageName in argResults.rest) { var packageDir = - new Directory.fromUri(installRepo.uri.resolve(packageName)); + Directory.fromUri(installRepo.uri.resolve(packageName)); if (!await packageDir.exists()) throw 'No add-on named "$packageName" is installed. You might need to run `angel install --update`.'; @@ -90,7 +90,7 @@ class InstallCommand extends Command { .map((k) { var dep = projectPubspec.dependencies[k]; if (dep is HostedDependency) - return new MakerDependency(k, dep.version.toString()); + return MakerDependency(k, dep.version.toString()); return null; }) .where((d) => d != null) @@ -99,14 +99,13 @@ class InstallCommand extends Command { deps.addAll(projectPubspec.devDependencies.keys.map((k) { var dep = projectPubspec.devDependencies[k]; if (dep is HostedDependency) - return new MakerDependency(k, dep.version.toString(), dev: true); + return MakerDependency(k, dep.version.toString(), dev: true); return null; }).where((d) => d != null)); await depend(deps); - var promptFile = - new File.fromUri(packageDir.uri.resolve('angel_cli.yaml')); + var promptFile = File.fromUri(packageDir.uri.resolve('angel_cli.yaml')); if (await promptFile.exists()) { var contents = await promptFile.readAsString(); @@ -116,7 +115,7 @@ class InstallCommand extends Command { // Loads globs if (cfg['templates'] is List) { globs.addAll( - (cfg['templates'] as List).map((p) => new Glob(p.toString()))); + (cfg['templates'] as List).map((p) => Glob(p.toString()))); } if (cfg['values'] is Map) { @@ -144,14 +143,14 @@ class InstallCommand extends Command { await for (var entity in src.list()) { if (entity is Directory) { var name = p.basename(entity.path); - var newDir = new Directory.fromUri(dst.uri.resolve(name)); + var newDir = Directory.fromUri(dst.uri.resolve(name)); await merge( entity, newDir, prefix.isEmpty ? name : '$prefix/$name'); } else if (entity is File && !entity.path.endsWith('angel_cli.yaml')) { var name = p.basename(entity.path); var target = dst.uri.resolve(name); - var targetFile = new File.fromUri(target); + var targetFile = File.fromUri(target); bool allClear = !await targetFile.exists(); if (!allClear) { @@ -187,7 +186,7 @@ class InstallCommand extends Command { } } - await merge(new Directory.fromUri(packageDir.uri.resolve('files')), + await merge(Directory.fromUri(packageDir.uri.resolve('files')), Directory.current, ''); print('Successfully installed $packageName@${projectPubspec.version}.'); } diff --git a/lib/src/commands/key.dart b/lib/src/commands/key.dart index cab986f..92e1045 100644 --- a/lib/src/commands/key.dart +++ b/lib/src/commands/key.dart @@ -13,17 +13,17 @@ class KeyCommand extends Command { run() async { var secret = rs.randomAlphaNumeric(32); print('Generated new development JWT secret: $secret'); - await changeSecret(new File('config/default.yaml'), secret); + await changeSecret(File('config/default.yaml'), secret); secret = rs.randomAlphaNumeric(32); print('Generated new production JWT secret: $secret'); - await changeSecret(new File('config/production.yaml'), secret); + await changeSecret(File('config/production.yaml'), secret); } changeSecret(File file, String secret) async { if (await file.exists()) { var contents = await file.readAsString(); - contents = contents.replaceAll(new RegExp(r'jwt_secret:[^\n]+\n?'), ''); + contents = contents.replaceAll(RegExp(r'jwt_secret:[^\n]+\n?'), ''); await file.writeAsString(contents.trim() + '\njwt_secret: "$secret"'); } } diff --git a/lib/src/commands/make.dart b/lib/src/commands/make.dart index 219fedf..012cb9f 100644 --- a/lib/src/commands/make.dart +++ b/lib/src/commands/make.dart @@ -15,11 +15,11 @@ class MakeCommand extends Command { 'Generates common code for your project, such as projects and controllers.'; MakeCommand() { - addSubcommand(new ControllerCommand()); - addSubcommand(new MigrationCommand()); - addSubcommand(new ModelCommand()); - addSubcommand(new PluginCommand()); - addSubcommand(new TestCommand()); - addSubcommand(new ServiceCommand()); + addSubcommand(ControllerCommand()); + addSubcommand(MigrationCommand()); + addSubcommand(ModelCommand()); + addSubcommand(PluginCommand()); + addSubcommand(TestCommand()); + addSubcommand(ServiceCommand()); } } diff --git a/lib/src/commands/make/controller.dart b/lib/src/commands/make/controller.dart index 209aa40..1d51db0 100644 --- a/lib/src/commands/make/controller.dart +++ b/lib/src/commands/make/controller.dart @@ -43,7 +43,7 @@ class ControllerCommand extends Command { const MakerDependency('angel_framework', '^2.0.0') ]; - // ${pubspec.name}.src.models.${rc.snakeCase} + //${pubspec.name}.src.models.${rc.snakeCase} var rc = new ReCase(name); var controllerLib = new Library((controllerLib) { diff --git a/lib/src/commands/pub.dart b/lib/src/commands/pub.dart index 1f3a74c..1b582eb 100644 --- a/lib/src/commands/pub.dart +++ b/lib/src/commands/pub.dart @@ -1,9 +1,9 @@ import 'dart:io'; -final RegExp _leadingSlashes = new RegExp(r'^/+'); +final RegExp _leadingSlashes = RegExp(r'^/+'); String resolvePub() { - var exec = new File(Platform.resolvedExecutable); + var exec = File(Platform.resolvedExecutable); var pubPath = exec.parent.uri.resolve('pub').path; if (Platform.isWindows) pubPath = pubPath.replaceAll(_leadingSlashes, '') + '.bat'; diff --git a/lib/src/commands/rename.dart b/lib/src/commands/rename.dart index ae11b5e..49e5bd0 100644 --- a/lib/src/commands/rename.dart +++ b/lib/src/commands/rename.dart @@ -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 '; @@ -29,17 +31,20 @@ class RenameCommand extends Command { newName = prompts.get('Rename project to'); } - newName = new ReCase(newName).snakeCase; + newName = ReCase(newName).snakeCase; 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 = - new File.fromUri(Directory.current.uri.resolve('pubspec.yaml')); + File.fromUri(Directory.current.uri.resolve('pubspec.yaml')); if (!await pubspecFile.exists()) { - throw new Exception('No pubspec.yaml found in current directory.'); + throw Exception('No pubspec.yaml found in current directory.'); } else { var pubspec = await loadPubspec(); var oldName = pubspec.name; @@ -53,6 +58,7 @@ class RenameCommand extends Command { stderr.addStream(pub.stderr); await pub.exitCode; } + */ } } } @@ -61,12 +67,12 @@ 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; contents = - contents.replaceAll(new RegExp('name:\\s*$oldName'), 'name: $newName'); + contents.replaceAll(RegExp('name:\\s*$oldName'), 'name: $newName'); if (contents != oldContents) { await pubspecFile.writeAsString(contents); @@ -76,7 +82,7 @@ renamePubspec(Directory dir, String oldName, String newName) async { // print(cyan // .wrap('Note that this does not actually modify your `pubspec.yaml`.')); // TODO: https://github.com/dart-lang/pubspec_parse/issues/17 -// var newPubspec = new Pubspec.fromJson(pubspec.toJson()..['name'] = newName); +// var newPubspec = Pubspec.fromJson(pubspec.toJson()..['name'] = newName); // await newPubspec.save(dir); } @@ -84,34 +90,39 @@ renameDartFiles(Directory dir, String oldName, String newName) async { if (!await dir.exists()) return; // Try to replace MongoDB URL - var configGlob = new Glob('config/**/*.yaml'); + var configGlob = Glob('config/**/*.yaml'); try { await for (var yamlFile in configGlob.list(root: dir.absolute.path)) { 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 (_) {} - var entry = new File.fromUri(dir.uri.resolve('lib/$oldName.dart')); + var entry = File.fromUri(dir.uri.resolve('lib/$oldName.dart')); if (await entry.exists()) { await entry.rename(dir.uri.resolve('lib/$newName.dart').toFilePath()); print('Renaming library file `${entry.absolute.path}`...'); } - var fmt = new DartFormatter(); + var fmt = DartFormatter(); 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); + + // 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) { diff --git a/lib/src/commands/service_generators/custom.dart b/lib/src/commands/service_generators/custom.dart index d413460..9008b69 100644 --- a/lib/src/commands/service_generators/custom.dart +++ b/lib/src/commands/service_generators/custom.dart @@ -12,7 +12,7 @@ class CustomServiceGenerator extends ServiceGenerator { @override void applyToLibrary(LibraryBuilder library, String name, String lower) { - library.body.add(new Class((clazz) { + library.body.add(Class((clazz) { clazz ..name = '${name}Service' ..extend = refer('Service'); diff --git a/lib/src/commands/service_generators/rethink.dart b/lib/src/commands/service_generators/rethink.dart index 5705984..49cc78c 100644 --- a/lib/src/commands/service_generators/rethink.dart +++ b/lib/src/commands/service_generators/rethink.dart @@ -34,7 +34,7 @@ class RethinkServiceGenerator extends ServiceGenerator { void applyToLibrary(LibraryBuilder library, String name, String lower) { library.directives.addAll([ 'package:angel_rethink/angel_rethink.dart', - 'package:rethinkdb_driver/rethinkdb_driver.dart' + 'package:rethinkdb_dart/rethinkdb_dart.dart' ].map((str) => new Directive.import(str))); } diff --git a/lib/src/random_string.dart b/lib/src/random_string.dart index c089e87..9f539aa 100644 --- a/lib/src/random_string.dart +++ b/lib/src/random_string.dart @@ -2,10 +2,10 @@ import 'dart:math'; const String _valid = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; -final Random _rnd = new Random.secure(); +final Random _rnd = Random.secure(); String randomAlphaNumeric(int length) { - var b = new StringBuffer(); + var b = StringBuffer(); for (int i = 0; i < length; i++) { b.writeCharCode(_valid.codeUnitAt(_rnd.nextInt(_valid.length))); diff --git a/pubspec.yaml b/pubspec.yaml index 34ab6e6..d8d35e6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,28 +1,27 @@ -author: Tobe O +#author: Tobe O 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.1.7+1 +version: 3.0.0 +environment: + sdk: ">=2.10.0 <3.0.0" dependencies: - analyzer: ">=0.32.0 <2.0.0" - 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 -environment: - sdk: ">=2.0.0-dev <3.0.0" + watcher: ^1.0.0 + yaml: ^3.0.0 executables: angel: angel