+5
This commit is contained in:
parent
2a212c9d40
commit
b92ebdeb21
7 changed files with 159 additions and 82 deletions
|
@ -1,8 +0,0 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Service" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
|
||||
<option name="arguments" value="service" />
|
||||
<option name="filePath" value="$PROJECT_DIR$/bin/angel.dart" />
|
||||
<option name="workingDirectory" value="$PROJECT_DIR$/sample_project" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
|
@ -11,9 +11,12 @@ main(List<String> args) {
|
|||
var runner =
|
||||
new CommandRunner("angel", "Command-line tools for the Angel framework.");
|
||||
|
||||
runner.addCommand(new DoctorCommand());
|
||||
runner.addCommand(new ServiceCommand());
|
||||
runner.addCommand(new InitCommand());
|
||||
runner
|
||||
..addCommand(new DoctorCommand())
|
||||
..addCommand(new ServiceCommand())
|
||||
..addCommand(new InitCommand())
|
||||
..addCommand(new TestCommand())
|
||||
..addCommand(new PluginCommand());
|
||||
|
||||
return runner.run(args).then((_) {}).catchError((exc) {
|
||||
stderr.writeln("Oops, something went wrong: $exc");
|
||||
|
|
|
@ -2,4 +2,6 @@ library angel_cli.commands;
|
|||
|
||||
export "doctor.dart";
|
||||
export "init.dart";
|
||||
export "plugin.dart";
|
||||
export "service.dart";
|
||||
export "test.dart";
|
46
lib/src/commands/plugin.dart
Normal file
46
lib/src/commands/plugin.dart
Normal file
|
@ -0,0 +1,46 @@
|
|||
import 'dart:io';
|
||||
import 'package:args/command_runner.dart';
|
||||
import "package:console/console.dart";
|
||||
|
||||
class PluginCommand extends Command {
|
||||
final TextPen _pen = new TextPen();
|
||||
|
||||
@override
|
||||
String get name => "plugin";
|
||||
|
||||
@override
|
||||
String get description => "Creates a new plugin within the given project.";
|
||||
|
||||
@override
|
||||
run() async {
|
||||
final name = await readInput("Name of Plugin: "), lower = name.toLowerCase();
|
||||
final testDir = new Directory("lib/src/config/plugins");
|
||||
final pluginFile = new File.fromUri(
|
||||
testDir.uri.resolve("$lower.dart"));
|
||||
|
||||
if (!await pluginFile.exists())
|
||||
await pluginFile.create(recursive: true);
|
||||
|
||||
await pluginFile.writeAsString(_generatePlugin(lower));
|
||||
|
||||
_pen.green();
|
||||
_pen("${Icon.CHECKMARK} Successfully generated plugin $name.");
|
||||
_pen();
|
||||
}
|
||||
|
||||
String _generatePlugin(String name) {
|
||||
|
||||
return '''
|
||||
import 'dart:async';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
|
||||
class $name extends AngelPlugin {
|
||||
@override
|
||||
Future call(Angel app) async {
|
||||
// Work some magic...
|
||||
}
|
||||
}
|
||||
'''
|
||||
.trim();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
import "dart:io";
|
||||
import "package:args/command_runner.dart";
|
||||
import "package:console/console.dart";
|
||||
import "package:mustache4dart/mustache4dart.dart";
|
||||
|
||||
class ServiceCommand extends Command {
|
||||
final String CUSTOM = "Custom";
|
||||
|
@ -228,82 +227,36 @@ class ${name}Service extends MongoTypedService<$name> {
|
|||
_generateTests(String name, String type) {
|
||||
return '''
|
||||
import 'dart:io';
|
||||
import 'package:angel/src/services/${name.toLowerCase()}.dart';
|
||||
import 'package:angel/angel.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:json_god/json_god.dart' as god;${_includeMongo(type)}
|
||||
import 'package:angel_test/angel_test.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
main() {
|
||||
group('$name', () {
|
||||
Angel app;
|
||||
http.Client client;
|
||||
HttpServer server;
|
||||
String url;
|
||||
HookedService ${name}s;${_createDb(type)}
|
||||
main() async {
|
||||
Angel app;
|
||||
TestClient client;
|
||||
|
||||
setUp(() async {
|
||||
app = new Angel();
|
||||
client = new http.Client();${_openDb(type)}
|
||||
app.use('/${name.toLowerCase()}s', new ${name}Service(${_dbCollection(name, type)}));
|
||||
${name}s = app.service("${name.toLowerCase()}s");
|
||||
setUp(() async {
|
||||
app = await createServer();
|
||||
client = await connectTo(app, saveSession: false);
|
||||
});
|
||||
|
||||
server = await app.startServer(null, 0);
|
||||
url = "http://\${server.address.host}:\${server.port}";
|
||||
});
|
||||
tearDown(() async {
|
||||
await client.close();
|
||||
app = null;
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
app = null;
|
||||
url = null;
|
||||
client.close();
|
||||
client = null;
|
||||
${name}s = null;
|
||||
await server.close(force: true);
|
||||
});
|
||||
test('index via REST', () async {
|
||||
final response = await client.get('/api/${name.toLowerCase()}');
|
||||
expect(response, hasStatus(HttpStatus.OK));
|
||||
});
|
||||
|
||||
test('Index ${name.toLowerCase()}s', () async {
|
||||
var indexed${name}s = await ${name}s.index();
|
||||
});
|
||||
|
||||
test('Index via REST', () async {
|
||||
var response = await client.get('\$url/${name.toLowerCase()}s');
|
||||
print(god.deserialize(response.body));
|
||||
});
|
||||
test('Index ${name.toLowerCase()}s', () async {
|
||||
final ${name.toLowerCase()}s = await client.service('api/${name.toLowerCase()}').index();
|
||||
print(${name.toLowerCase()}s);
|
||||
});
|
||||
}
|
||||
'''
|
||||
.trim();
|
||||
}
|
||||
|
||||
_createDb(String type) {
|
||||
if (type == MONGO || type == MONGO_TYPED) {
|
||||
return "\n Db db;";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
_dbCollection(String name, String type) {
|
||||
if (type == MONGO || type == MONGO_TYPED) {
|
||||
return "db.collection('${name.toLowerCase()}s')";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
_includeMongo(String type) {
|
||||
if (type == MONGO || type == MONGO_TYPED) {
|
||||
return "\nimport 'package:mongo_dart/mongo_dart.dart';";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
_openDb(String type) {
|
||||
if (type == MONGO || type == MONGO_TYPED) {
|
||||
return "\n await db.open();";
|
||||
}
|
||||
|
||||
return "";
|
||||
'''.trim();
|
||||
}
|
||||
}
|
||||
|
|
82
lib/src/commands/test.dart
Normal file
82
lib/src/commands/test.dart
Normal file
|
@ -0,0 +1,82 @@
|
|||
import 'dart:io';
|
||||
import 'package:args/command_runner.dart';
|
||||
import "package:console/console.dart";
|
||||
|
||||
class TestCommand extends Command {
|
||||
final TextPen _pen = new TextPen();
|
||||
|
||||
@override
|
||||
String get name => "test";
|
||||
|
||||
@override
|
||||
String get description => "Creates a new test within the given project.";
|
||||
|
||||
@override
|
||||
run() async {
|
||||
final name = await readInput("Name of Test: "), lower = name.toLowerCase();
|
||||
final testDir = new Directory("test/services");
|
||||
final testFile = new File.fromUri(
|
||||
testDir.uri.resolve("${lower}_test.dart"));
|
||||
|
||||
if (!await testFile.exists())
|
||||
await testFile.create(recursive: true);
|
||||
|
||||
await testFile.writeAsString(_generateTest(lower));
|
||||
|
||||
final runConfig = new File('./.idea/runConfigurations/${name}_tests.xml');
|
||||
|
||||
if (!await runConfig.exists()) {
|
||||
await runConfig.create(recursive: true);
|
||||
await runConfig.writeAsString(_generateRunConfiguration(name));
|
||||
}
|
||||
|
||||
_pen.green();
|
||||
_pen("${Icon.CHECKMARK} Successfully generated test $name.");
|
||||
_pen();
|
||||
}
|
||||
|
||||
_generateRunConfiguration(String name) {
|
||||
final lower = name.toLowerCase();
|
||||
|
||||
return '''
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="$name Tests" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true">
|
||||
<option name="filePath" value="\$PROJECT_DIR\$/test/${lower}_test.dart" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
||||
'''
|
||||
.trim();
|
||||
}
|
||||
|
||||
String _generateTest(String lower) {
|
||||
return '''
|
||||
import 'dart:io';
|
||||
import 'package:angel/angel.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_test/angel_test.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
main() async {
|
||||
Angel app;
|
||||
TestClient client;
|
||||
|
||||
setUp(() async {
|
||||
app = await createServer();
|
||||
client = await connectTo(app, saveSession: false);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await client.close();
|
||||
app = null;
|
||||
});
|
||||
|
||||
test('$lower', () async {
|
||||
final response = await client.get('/$lower');
|
||||
expect(response, hasStatus(HttpStatus.OK));
|
||||
});
|
||||
}
|
||||
'''
|
||||
.trim();
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
name: angel_cli
|
||||
version: 1.0.0-dev+4
|
||||
version: 1.0.0-dev+5
|
||||
description: Command-line tools for the Angel framework.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_cli
|
||||
|
@ -9,5 +9,4 @@ dependencies:
|
|||
analyzer: ">=0.28.1 <1.0.0"
|
||||
args: ">=0.3.4 <1.0.0"
|
||||
console: ">=2.2.3 <3.0.0"
|
||||
mustache4dart: ">=1.0.0 <3.0.0"
|
||||
yaml: ">=2.0.0 <3.0.0"
|
Loading…
Reference in a new issue