diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..518eb90 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true \ No newline at end of file diff --git a/lib/src/commands/init.dart b/lib/src/commands/init.dart index a7b3f6f..57e1a8e 100644 --- a/lib/src/commands/init.dart +++ b/lib/src/commands/init.dart @@ -122,7 +122,7 @@ class InitCommand extends Command { } print('Choose a project type before continuing:'); - var boilerplateChooser = new Chooser(ALL_BOILERPLATES); + var boilerplateChooser = new Chooser(allBoilerplates); var boilerplate = await boilerplateChooser.choose(); print( @@ -175,19 +175,24 @@ preBuild(Directory projectDir) async { if (buildCode != 0) throw new Exception('Failed to pre-build resources.'); } -const BoilerplateInfo FULL_APPLICATION_BOILERPLATE = const BoilerplateInfo( +const BoilerplateInfo fullApplicationBoilerplate = const BoilerplateInfo( 'Full Application', 'A complete project including authentication, multi-threading, and more.', 'https://github.com/angel-dart/angel.git'); -const BoilerplateInfo LIGHT_BOILERPLATE = const BoilerplateInfo( +const BoilerplateInfo lightBoilerplate = const BoilerplateInfo( 'Light', - 'Minimal starting point for new users', + 'Minimal starting point for new users.', 'https://github.com/angel-dart/boilerplate_light.git'); -const List ALL_BOILERPLATES = const [ - FULL_APPLICATION_BOILERPLATE, - LIGHT_BOILERPLATE +const BoilerplateInfo ormBoilerplate = const BoilerplateInfo( + 'ORM', + "A starting point for applications that use Angel's ORM.", + 'https://github.com/angel-dart/boilerplate_orm.git'); + +const List allBoilerplates = const [ + fullApplicationBoilerplate, + lightBoilerplate ]; class BoilerplateInfo { diff --git a/lib/src/commands/plugin.dart b/lib/src/commands/plugin.dart index dd1e0c5..2ded982 100644 --- a/lib/src/commands/plugin.dart +++ b/lib/src/commands/plugin.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:args/command_runner.dart'; import "package:console/console.dart"; +import 'package:dart_style/dart_style.dart'; import 'package:pubspec/pubspec.dart'; import 'package:recase/recase.dart'; @@ -23,7 +24,8 @@ class PluginCommand extends Command { if (!await pluginFile.exists()) await pluginFile.create(recursive: true); - await pluginFile.writeAsString(_generatePlugin(pubspec, name, lower)); + await pluginFile.writeAsString( + new DartFormatter().format(_generatePlugin(pubspec, name, lower))); _pen.green(); _pen("${Icon.CHECKMARK} Successfully generated plugin $name."); diff --git a/lib/src/commands/pub.dart b/lib/src/commands/pub.dart index 113c8b3..1f3a74c 100644 --- a/lib/src/commands/pub.dart +++ b/lib/src/commands/pub.dart @@ -2,12 +2,11 @@ import 'dart:io'; final RegExp _leadingSlashes = new RegExp(r'^/+'); - - String resolvePub() { -var exec = new File(Platform.resolvedExecutable); -var pubPath = exec.parent.uri.resolve('pub').path; -if (Platform.isWindows) -pubPath = pubPath.replaceAll(_leadingSlashes, '') + '.bat'; -pubPath = Uri.decodeFull(pubPath); -return pubPath; -} \ No newline at end of file +String resolvePub() { + var exec = new File(Platform.resolvedExecutable); + var pubPath = exec.parent.uri.resolve('pub').path; + if (Platform.isWindows) + pubPath = pubPath.replaceAll(_leadingSlashes, '') + '.bat'; + pubPath = Uri.decodeFull(pubPath); + return pubPath; +} diff --git a/lib/src/commands/pubspec.update.g.dart b/lib/src/commands/pubspec.update.g.dart index 0aa8ac8..7e5762c 100644 --- a/lib/src/commands/pubspec.update.g.dart +++ b/lib/src/commands/pubspec.update.g.dart @@ -3,7 +3,7 @@ import 'dart:convert'; import 'package:http/src/base_client.dart' as http; import 'package:pub_semver/pub_semver.dart'; -final Version PACKAGE_VERSION = new Version(1, 1, 4); +final Version PACKAGE_VERSION = new Version(1, 1, 5); Future fetchCurrentVersion(http.BaseClient client) async { var response = await client.get('https://pub.dartlang.org/api/packages/angel_cli'); diff --git a/lib/src/commands/rename.dart b/lib/src/commands/rename.dart index c3544e7..2c90d96 100644 --- a/lib/src/commands/rename.dart +++ b/lib/src/commands/rename.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:analyzer/analyzer.dart'; import 'package:args/command_runner.dart'; import 'package:console/console.dart'; +import 'package:dart_style/dart_style.dart'; import 'package:pubspec/pubspec.dart'; import 'pub.dart'; @@ -43,7 +44,9 @@ class RenameCommand extends Command { await renamePubspec(Directory.current, oldName, newName); await renameDartFiles(Directory.current, oldName, newName); print('Now running `pub get`...'); - var pub = await Process.start(resolvePub(), ['get']); + var pubPath = resolvePub(); + print('Pub path: $pubPath'); + var pub = await Process.start(pubPath, ['get']); stdout.addStream(pub.stdout); stderr.addStream(pub.stderr); await pub.exitCode; @@ -77,6 +80,7 @@ renameDartFiles(Directory dir, String oldName, String newName) async { print('Renaming library file `${entry.absolute.path}`...'); } + var fmt = new DartFormatter(); await for (FileSystemEntity file in dir.list(recursive: true)) { if (file is File && file.path.endsWith('.dart')) { var contents = await file.readAsString(); @@ -94,7 +98,7 @@ renameDartFiles(Directory dir, String oldName, String newName) async { } }); - await file.writeAsString(contents); + await file.writeAsString(fmt.format(contents)); print('Updated file `${file.absolute.path}`.'); } } diff --git a/lib/src/commands/service.dart b/lib/src/commands/service.dart index 0e7a00f..1db296e 100644 --- a/lib/src/commands/service.dart +++ b/lib/src/commands/service.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:args/command_runner.dart'; import 'package:code_builder/code_builder.dart'; import 'package:console/console.dart'; +import 'package:dart_style/dart_style.dart'; import 'package:inflection/inflection.dart'; import 'package:pubspec/pubspec.dart'; import 'package:recase/recase.dart'; @@ -60,9 +61,11 @@ class ServiceCommand extends Command { await servicesDir.create(recursive: true); if (!await testDir.exists()) await testDir.create(recursive: true); + var fmt = new DartFormatter(); + await serviceFile .writeAsString(_generateService(generator, name, lower, typed)); - await testFile.writeAsString(_generateTests(pubspec, lower)); + await testFile.writeAsString(_generateTests(pubspec, lower, fmt)); var runConfig = new File('./.idea/runConfigurations/${name}_Tests.xml'); @@ -72,11 +75,11 @@ class ServiceCommand extends Command { } if (generator.createsModel == true || typed == true) { - await _generateModel(pubspec, name, lower); + await _generateModel(pubspec, name, lower, fmt); } if (generator.createsValidator == true) { - await _generateValidator(pubspec, lower, rc.constantCase); + await _generateValidator(pubspec, lower, rc, fmt); } if (generator.exportedInServiceLibrary == true || typed == true) { @@ -104,8 +107,7 @@ class ServiceCommand extends Command { import '../models/$lower.dart'; export '../models/$lower.dart'; */ - lib.addMember( - new ImportBuilder('package:angel_common/angel_common.dart')); + lib.addMember(new ImportBuilder('package:angel_common/angel_common.dart')); generator.applyToLibrary(lib, name, lower); if (generator.createsModel == true || typed) { @@ -153,47 +155,46 @@ class ServiceCommand extends Command { return prettyToSource(lib.buildAst()); } - _generateModel(PubSpec pubspec, String name, String lower) async { + _generateModel( + PubSpec pubspec, String name, String lower, DartFormatter fmt) async { var file = new File('lib/src/models/$lower.dart'); if (!await file.exists()) await file.createSync(recursive: true); - await file.writeAsString(''' + await file.writeAsString(fmt.format(''' library ${pubspec.name}.models.$lower; -import 'package:angel_framework/common.dart'; +import 'package:angel_model/angel_model.dart'; class $name extends Model { @override String id; - String name, desc; + String name, description; @override DateTime createdAt, updatedAt; - $name({this.id, this.name, this.desc, this.createdAt, this.updatedAt}); + $name({this.id, this.name, this.description, this.createdAt, this.updatedAt}); } - ''' - .trim()); + ''')); } - _generateValidator(PubSpec pubspec, String lower, String constantCase) async { + _generateValidator( + PubSpec pubspec, String lower, ReCase rc, DartFormatter fmt) async { var file = new File('lib/src/validators/$lower.dart'); if (!await file.exists()) await file.createSync(recursive: true); - await file.writeAsString(''' + await file.writeAsString(fmt.format(''' library ${pubspec.name}.validtors.$lower; import 'package:angel_validate/angel_validate.dart'; -final Validator $constantCase = new Validator({ +final Validator ${rc.camelCase} = new Validator({ 'name': [isString, isNotEmpty], - 'desc': [isString, isNotEmpty] + 'description': [isString, isNotEmpty] }); -final Validator CREATE_$constantCase = $constantCase.extend({}) - ..requiredFields.addAll(['name', 'desc']); - - ''' - .trim()); +final Validator create${rc.pascalCase} = ${rc.camelCase}.extend({}) + ..requiredFields.addAll(['name', 'description']); + ''')); } _generateRunConfiguration(String name, String lower) { @@ -208,8 +209,8 @@ final Validator CREATE_$constantCase = $constantCase.extend({}) .trim(); } - _generateTests(PubSpec pubspec, String lower) { - return ''' + _generateTests(PubSpec pubspec, String lower, DartFormatter fmt) { + return fmt.format(''' import 'dart:io'; import 'package:${pubspec.name}/${pubspec.name}.dart'; import 'package:angel_common/angel_common.dart'; @@ -241,7 +242,6 @@ main() async { }); } - ''' - .trim(); + '''); } } diff --git a/lib/src/commands/start.dart b/lib/src/commands/start.dart index f1fac21..eae1456 100644 --- a/lib/src/commands/start.dart +++ b/lib/src/commands/start.dart @@ -80,7 +80,7 @@ class StartCommand extends Command { if (await pubspec.exists()) { // Run start scripts final doc = loadYamlDocument(await pubspec.readAsString()); - final scriptsNode = doc.contents['scripts']; + final scriptsNode = doc.contents.value['scripts']; if (scriptsNode != null && scriptsNode.containsKey('start')) { try { diff --git a/lib/src/commands/test.dart b/lib/src/commands/test.dart index fdb5dee..b74da8f 100644 --- a/lib/src/commands/test.dart +++ b/lib/src/commands/test.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:args/command_runner.dart'; import "package:console/console.dart"; +import 'package:dart_style/dart_style.dart'; import 'package:pubspec/pubspec.dart'; import 'package:recase/recase.dart'; @@ -23,8 +24,8 @@ class TestCommand extends Command { if (!await testFile.exists()) await testFile.create(recursive: true); - await testFile.writeAsString( - _generateTest(await PubSpec.load(Directory.current), lower)); + await testFile.writeAsString(new DartFormatter() + .format(_generateTest(await PubSpec.load(Directory.current), lower))); final runConfig = new File('./.idea/runConfigurations/${name}_tests.xml'); diff --git a/pubspec.yaml b/pubspec.yaml index ab99f0a..7b44351 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,12 +2,13 @@ author: "Tobe O " description: "Command-line tools for the Angel framework." homepage: "https://github.com/angel-dart/angel_cli" name: "angel_cli" -version: 1.1.4 +version: 1.1.5 dependencies: # analyzer: "^0.29.0" args: ^0.13.4 code_builder: ^1.0.0 console: "^2.2.3" + dart_style: ^1.0.0 glob: "^1.1.0" http: ^0.11.3 id: "^1.0.0" @@ -18,6 +19,7 @@ dependencies: watcher: "^0.9.7" yaml: "^2.0.0" dev_dependencies: + build: ^0.7.0 build_runner: ^0.3.0 check_for_update: ^1.0.0 environment: