Formatting

This commit is contained in:
thosakwe 2017-08-04 11:42:07 -04:00
parent 6f5b4624b4
commit c351f0ed14
10 changed files with 64 additions and 49 deletions

2
analysis_options.yaml Normal file
View file

@ -0,0 +1,2 @@
analyzer:
strong-mode: true

View file

@ -122,7 +122,7 @@ class InitCommand extends Command {
} }
print('Choose a project type before continuing:'); print('Choose a project type before continuing:');
var boilerplateChooser = new Chooser<BoilerplateInfo>(ALL_BOILERPLATES); var boilerplateChooser = new Chooser<BoilerplateInfo>(allBoilerplates);
var boilerplate = await boilerplateChooser.choose(); var boilerplate = await boilerplateChooser.choose();
print( print(
@ -175,19 +175,24 @@ preBuild(Directory projectDir) async {
if (buildCode != 0) throw new Exception('Failed to pre-build resources.'); 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', 'Full Application',
'A complete project including authentication, multi-threading, and more.', 'A complete project including authentication, multi-threading, and more.',
'https://github.com/angel-dart/angel.git'); 'https://github.com/angel-dart/angel.git');
const BoilerplateInfo LIGHT_BOILERPLATE = const BoilerplateInfo( const BoilerplateInfo lightBoilerplate = const BoilerplateInfo(
'Light', 'Light',
'Minimal starting point for new users', 'Minimal starting point for new users.',
'https://github.com/angel-dart/boilerplate_light.git'); 'https://github.com/angel-dart/boilerplate_light.git');
const List<BoilerplateInfo> ALL_BOILERPLATES = const [ const BoilerplateInfo ormBoilerplate = const BoilerplateInfo(
FULL_APPLICATION_BOILERPLATE, 'ORM',
LIGHT_BOILERPLATE "A starting point for applications that use Angel's ORM.",
'https://github.com/angel-dart/boilerplate_orm.git');
const List<BoilerplateInfo> allBoilerplates = const [
fullApplicationBoilerplate,
lightBoilerplate
]; ];
class BoilerplateInfo { class BoilerplateInfo {

View file

@ -1,6 +1,7 @@
import 'dart:io'; 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:dart_style/dart_style.dart';
import 'package:pubspec/pubspec.dart'; import 'package:pubspec/pubspec.dart';
import 'package:recase/recase.dart'; import 'package:recase/recase.dart';
@ -23,7 +24,8 @@ class PluginCommand extends Command {
if (!await pluginFile.exists()) await pluginFile.create(recursive: true); 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.green();
_pen("${Icon.CHECKMARK} Successfully generated plugin $name."); _pen("${Icon.CHECKMARK} Successfully generated plugin $name.");

View file

@ -2,12 +2,11 @@ import 'dart:io';
final RegExp _leadingSlashes = new RegExp(r'^/+'); final RegExp _leadingSlashes = new RegExp(r'^/+');
String resolvePub() {
String resolvePub() { var exec = new File(Platform.resolvedExecutable);
var exec = new File(Platform.resolvedExecutable); var pubPath = exec.parent.uri.resolve('pub').path;
var pubPath = exec.parent.uri.resolve('pub').path; if (Platform.isWindows)
if (Platform.isWindows) pubPath = pubPath.replaceAll(_leadingSlashes, '') + '.bat';
pubPath = pubPath.replaceAll(_leadingSlashes, '') + '.bat'; pubPath = Uri.decodeFull(pubPath);
pubPath = Uri.decodeFull(pubPath); return pubPath;
return pubPath;
} }

View file

@ -3,7 +3,7 @@ import 'dart:convert';
import 'package:http/src/base_client.dart' as http; import 'package:http/src/base_client.dart' as http;
import 'package:pub_semver/pub_semver.dart'; 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<Version> fetchCurrentVersion(http.BaseClient client) async { Future<Version> fetchCurrentVersion(http.BaseClient client) async {
var response = var response =
await client.get('https://pub.dartlang.org/api/packages/angel_cli'); await client.get('https://pub.dartlang.org/api/packages/angel_cli');

View file

@ -2,6 +2,7 @@ import 'dart:io';
import 'package:analyzer/analyzer.dart'; import 'package:analyzer/analyzer.dart';
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:console/console.dart'; import 'package:console/console.dart';
import 'package:dart_style/dart_style.dart';
import 'package:pubspec/pubspec.dart'; import 'package:pubspec/pubspec.dart';
import 'pub.dart'; import 'pub.dart';
@ -43,7 +44,9 @@ class RenameCommand extends Command {
await renamePubspec(Directory.current, oldName, newName); await renamePubspec(Directory.current, oldName, newName);
await renameDartFiles(Directory.current, oldName, newName); await renameDartFiles(Directory.current, oldName, newName);
print('Now running `pub get`...'); 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); stdout.addStream(pub.stdout);
stderr.addStream(pub.stderr); stderr.addStream(pub.stderr);
await pub.exitCode; await pub.exitCode;
@ -77,6 +80,7 @@ renameDartFiles(Directory dir, String oldName, String newName) async {
print('Renaming library file `${entry.absolute.path}`...'); print('Renaming library file `${entry.absolute.path}`...');
} }
var fmt = new DartFormatter();
await for (FileSystemEntity file in dir.list(recursive: true)) { await for (FileSystemEntity file in dir.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();
@ -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}`.'); print('Updated file `${file.absolute.path}`.');
} }
} }

View file

@ -2,6 +2,7 @@ import 'dart:io';
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:code_builder/code_builder.dart'; import 'package:code_builder/code_builder.dart';
import 'package:console/console.dart'; import 'package:console/console.dart';
import 'package:dart_style/dart_style.dart';
import 'package:inflection/inflection.dart'; import 'package:inflection/inflection.dart';
import 'package:pubspec/pubspec.dart'; import 'package:pubspec/pubspec.dart';
import 'package:recase/recase.dart'; import 'package:recase/recase.dart';
@ -60,9 +61,11 @@ class ServiceCommand extends Command {
await servicesDir.create(recursive: true); await servicesDir.create(recursive: true);
if (!await testDir.exists()) await testDir.create(recursive: true); if (!await testDir.exists()) await testDir.create(recursive: true);
var fmt = new DartFormatter();
await serviceFile await serviceFile
.writeAsString(_generateService(generator, name, lower, typed)); .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'); var runConfig = new File('./.idea/runConfigurations/${name}_Tests.xml');
@ -72,11 +75,11 @@ class ServiceCommand extends Command {
} }
if (generator.createsModel == true || typed == true) { if (generator.createsModel == true || typed == true) {
await _generateModel(pubspec, name, lower); await _generateModel(pubspec, name, lower, fmt);
} }
if (generator.createsValidator == true) { if (generator.createsValidator == true) {
await _generateValidator(pubspec, lower, rc.constantCase); await _generateValidator(pubspec, lower, rc, fmt);
} }
if (generator.exportedInServiceLibrary == true || typed == true) { if (generator.exportedInServiceLibrary == true || typed == true) {
@ -104,8 +107,7 @@ class ServiceCommand extends Command {
import '../models/$lower.dart'; import '../models/$lower.dart';
export '../models/$lower.dart'; export '../models/$lower.dart';
*/ */
lib.addMember( lib.addMember(new ImportBuilder('package:angel_common/angel_common.dart'));
new ImportBuilder('package:angel_common/angel_common.dart'));
generator.applyToLibrary(lib, name, lower); generator.applyToLibrary(lib, name, lower);
if (generator.createsModel == true || typed) { if (generator.createsModel == true || typed) {
@ -153,47 +155,46 @@ class ServiceCommand extends Command {
return prettyToSource(lib.buildAst()); 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'); var file = new File('lib/src/models/$lower.dart');
if (!await file.exists()) await file.createSync(recursive: true); if (!await file.exists()) await file.createSync(recursive: true);
await file.writeAsString(''' await file.writeAsString(fmt.format('''
library ${pubspec.name}.models.$lower; library ${pubspec.name}.models.$lower;
import 'package:angel_framework/common.dart'; import 'package:angel_model/angel_model.dart';
class $name extends Model { class $name extends Model {
@override @override
String id; String id;
String name, desc; String name, description;
@override @override
DateTime createdAt, updatedAt; 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'); var file = new File('lib/src/validators/$lower.dart');
if (!await file.exists()) await file.createSync(recursive: true); if (!await file.exists()) await file.createSync(recursive: true);
await file.writeAsString(''' await file.writeAsString(fmt.format('''
library ${pubspec.name}.validtors.$lower; library ${pubspec.name}.validtors.$lower;
import 'package:angel_validate/angel_validate.dart'; import 'package:angel_validate/angel_validate.dart';
final Validator $constantCase = new Validator({ final Validator ${rc.camelCase} = new Validator({
'name': [isString, isNotEmpty], 'name': [isString, isNotEmpty],
'desc': [isString, isNotEmpty] 'description': [isString, isNotEmpty]
}); });
final Validator CREATE_$constantCase = $constantCase.extend({}) final Validator create${rc.pascalCase} = ${rc.camelCase}.extend({})
..requiredFields.addAll(['name', 'desc']); ..requiredFields.addAll(['name', 'description']);
'''));
'''
.trim());
} }
_generateRunConfiguration(String name, String lower) { _generateRunConfiguration(String name, String lower) {
@ -208,8 +209,8 @@ final Validator CREATE_$constantCase = $constantCase.extend({})
.trim(); .trim();
} }
_generateTests(PubSpec pubspec, String lower) { _generateTests(PubSpec pubspec, String lower, DartFormatter fmt) {
return ''' return fmt.format('''
import 'dart:io'; import 'dart:io';
import 'package:${pubspec.name}/${pubspec.name}.dart'; import 'package:${pubspec.name}/${pubspec.name}.dart';
import 'package:angel_common/angel_common.dart'; import 'package:angel_common/angel_common.dart';
@ -241,7 +242,6 @@ main() async {
}); });
} }
''' ''');
.trim();
} }
} }

View file

@ -80,7 +80,7 @@ class StartCommand extends Command {
if (await pubspec.exists()) { if (await pubspec.exists()) {
// Run start scripts // Run start scripts
final doc = loadYamlDocument(await pubspec.readAsString()); final doc = loadYamlDocument(await pubspec.readAsString());
final scriptsNode = doc.contents['scripts']; final scriptsNode = doc.contents.value['scripts'];
if (scriptsNode != null && scriptsNode.containsKey('start')) { if (scriptsNode != null && scriptsNode.containsKey('start')) {
try { try {

View file

@ -1,6 +1,7 @@
import 'dart:io'; 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:dart_style/dart_style.dart';
import 'package:pubspec/pubspec.dart'; import 'package:pubspec/pubspec.dart';
import 'package:recase/recase.dart'; import 'package:recase/recase.dart';
@ -23,8 +24,8 @@ class TestCommand extends Command {
if (!await testFile.exists()) await testFile.create(recursive: true); if (!await testFile.exists()) await testFile.create(recursive: true);
await testFile.writeAsString( await testFile.writeAsString(new DartFormatter()
_generateTest(await PubSpec.load(Directory.current), lower)); .format(_generateTest(await PubSpec.load(Directory.current), lower)));
final runConfig = new File('./.idea/runConfigurations/${name}_tests.xml'); final runConfig = new File('./.idea/runConfigurations/${name}_tests.xml');

View file

@ -2,12 +2,13 @@ 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.1.4 version: 1.1.5
dependencies: dependencies:
# analyzer: "^0.29.0" # analyzer: "^0.29.0"
args: ^0.13.4 args: ^0.13.4
code_builder: ^1.0.0 code_builder: ^1.0.0
console: "^2.2.3" console: "^2.2.3"
dart_style: ^1.0.0
glob: "^1.1.0" glob: "^1.1.0"
http: ^0.11.3 http: ^0.11.3
id: "^1.0.0" id: "^1.0.0"
@ -18,6 +19,7 @@ dependencies:
watcher: "^0.9.7" watcher: "^0.9.7"
yaml: "^2.0.0" yaml: "^2.0.0"
dev_dependencies: dev_dependencies:
build: ^0.7.0
build_runner: ^0.3.0 build_runner: ^0.3.0
check_for_update: ^1.0.0 check_for_update: ^1.0.0
environment: environment: