Remove deprecated commands

This commit is contained in:
Tobe O 2018-07-14 18:13:32 -04:00
parent e5ecbeef3d
commit df0632d000
8 changed files with 0 additions and 1004 deletions

View file

@ -1,15 +1,10 @@
library angel_cli.commands;
export 'controller.dart';
export "doctor.dart";
export "key.dart";
export "init.dart";
export "install.dart";
export "make.dart";
export "plugin.dart";
export "rename.dart";
export "service.dart";
export "start.dart";
export "test.dart";
export 'update.dart';
export 'version.dart';

View file

@ -1,69 +0,0 @@
import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:code_builder/code_builder.dart';
import "package:console/console.dart";
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:recase/recase.dart';
import 'deprecated.dart';
class ControllerCommand extends Command {
final TextPen _pen = new TextPen();
@override
String get name => "controller";
@override
String get description =>
"Creates a new controller within the given project.";
@override
run() async {
warnDeprecated(this.name, _pen);
final name = await readInput("Name of Controller: "),
recase = new ReCase(name),
lower = recase.snakeCase;
final controllersDir = new Directory("lib/src/routes/controllers");
final controllerFile =
new File.fromUri(controllersDir.uri.resolve("$lower.dart"));
if (!await controllerFile.exists())
await controllerFile.create(recursive: true);
await controllerFile.writeAsString(
_generateController(await Pubspec.load(Directory.current), recase));
_pen.green();
_pen("${Icon.CHECKMARK} Successfully generated controller $name.");
_pen();
}
NewInstanceBuilder _expose(String path) => refer('Expose')
.constInstance([], namedArguments: {'path': literal(path)});
String _generateController(Pubspec pubspec, ReCase recase) {
var lower = recase.snakeCase;
var lib = new LibraryBuilder('${pubspec.name}.routes.controllers.$lower');
lib.addDirective(
new Directive.import('package:angel_common/angel_common.dart'));
var clazz = new ClassBuilder('${recase.pascalCase}Controller',
asExtends: refer('Controller'));
// Add @Expose()
clazz.addAnnotation(_expose('/$lower'));
// Add
// @Expose(path: '/')
// String foo() => 'bar';
var meth = new MethodBuilder('foo',
returns: literal('bar'), returnType: refer('String'));
meth.addAnnotation(_expose('/'));
clazz.addMethod(meth);
lib.addMember(clazz);
return prettyToSource(lib.buildAst());
}
}

View file

@ -1,10 +0,0 @@
import 'package:console/console.dart';
void warnDeprecated(String command, [TextPen pen]) {
pen ??= new TextPen();
pen
..yellow()
..call('The `$command` command is deprecated, and will be removed by v1.2.0.')
..call()
..reset();
}

View file

@ -1,54 +0,0 @@
import 'dart:io';
import 'package:args/command_runner.dart';
import "package:console/console.dart";
import 'package:dart_style/dart_style.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:recase/recase.dart';
import 'deprecated.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 {
warnDeprecated(this.name, _pen);
var pubspec = await Pubspec.load(Directory.current);
final name = await readInput("Name of Plugin: "),
lower = new ReCase(name).snakeCase;
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(
new DartFormatter().format(_generatePlugin(pubspec, name, lower)));
_pen.green();
_pen("${Icon.CHECKMARK} Successfully generated plugin $name.");
_pen();
}
String _generatePlugin(Pubspec pubspec, String name, String lower) {
return '''
library ${pubspec.name}.config.plugins.$lower;
import 'dart:async';
import 'package:angel_framework/angel_framework.dart';
class $name extends AngelPlugin {
@override
Future call(Angel app) async {
// Work some magic...
}
}
'''
.trim();
}
}

View file

@ -1,242 +0,0 @@
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_parse/pubspec_parse.dart';
import 'package:recase/recase.dart';
import 'service_generators/service_generators.dart';
import 'deprecated.dart';
import 'init.dart' show preBuild;
class ServiceCommand extends Command {
final TextPen _pen = new TextPen();
@override
String get name => 'service';
@override
String get description => 'Creates a new service within the given project.';
@override
run() async {
warnDeprecated(this.name, _pen);
var pubspec = await Pubspec.load(Directory.current);
var name = await readInput('Name of Service (not plural): ');
var chooser = new Chooser<String>(
serviceGenerators.map<String>((g) => g.name).toList(),
message: 'What type of service would you like to create? ');
var type = await chooser.choose();
print('Wrap this service in a TypedService? (slight performance cost)');
chooser = new Chooser<String>(['Yes', 'No']);
var typed = (await chooser.choose()) == 'Yes';
var generator =
serviceGenerators.firstWhere((g) => g.name == type, orElse: () => null);
if (generator == null) {
_pen.blue();
_pen('${Icon.STAR} \'$type\' services are not yet implemented. :(');
_pen();
} else {
var rc = new ReCase(name);
name = rc.pascalCase;
var lower = rc.snakeCase;
var servicesDir = new Directory('lib/src/services');
var serviceFile =
new File.fromUri(servicesDir.uri.resolve('$lower.dart'));
var testDir = new Directory('test/services');
var testFile =
new File.fromUri(testDir.uri.resolve('${lower}_test.dart'));
if (!await servicesDir.exists())
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, fmt));
var runConfig = new File('./.idea/runConfigurations/${name}_Tests.xml');
if (!await runConfig.exists()) {
await runConfig.create(recursive: true);
await runConfig.writeAsString(_generateRunConfiguration(name, lower));
}
if (generator.createsModel == true || typed == true) {
await _generateModel(pubspec, name, lower, fmt);
}
if (generator.createsValidator == true) {
await _generateValidator(pubspec, lower, rc, fmt);
}
if (generator.exportedInServiceLibrary == true || typed == true) {
var serviceLibrary = new File('lib/src/models/models.dart');
await serviceLibrary.writeAsString("\nexport '$lower.dart';",
mode: FileMode.APPEND);
}
if (generator.shouldRunBuild == true) {
await preBuild(Directory.current);
}
_pen.green();
_pen('${Icon.CHECKMARK} Successfully generated service $name.');
_pen();
}
}
String _generateService(
ServiceGenerator generator, String name, String lower, bool typed) {
var lib = new LibraryBuilder();
/*
import 'package:angel_framework/angel_framework.dart';
import '../models/$lower.dart';
export '../models/$lower.dart';
*/
lib.addMember(new Directive.import('package:angel_common/angel_common.dart'));
generator.applyToLibrary(lib, name, lower);
if (generator.createsModel == true || typed) {
lib
..addMember(new Directive.import('../models/$lower.dart'))
..addMember(new ExportBuilder('../models/$lower.dart'));
}
// configureServer() {}
var configureServer = new MethodBuilder('configureServer',
returnType: refer('AngelConfigurer'));
generator.applyToConfigureServer(configureServer, name, lower);
// return (Angel app) async {}
var closure = new MethodBuilder.closure(modifier: MethodModifier.asAsync)
..addPositional(parameter('app', [refer('Angel')]));
generator.beforeService(closure, name, lower);
// app.use('/api/todos', new MapService());
var service = generator.createInstance(closure, name, lower);
if (typed == true) {
service =
refer('TypedService', genericTypes: [refer(name)])
.newInstance([service]);
}
closure.addStatement(refer('app')
.invoke('use', [literal('/api/${pluralize(lower)}'), service]));
if (generator.injectsSingleton == true) {
closure.addStatement(varField('service',
value: refer('app')
.invoke('service', [literal('/api/${pluralize(lower)}')]).castAs(
refer('HookedService'))));
closure.addStatement(refer('app')
.property('container')
.invoke('singleton', [refer('service').property('inner')]));
}
configureServer.addStatement(closure.asReturn());
lib.addMember(configureServer);
return prettyToSource(lib.buildAst());
}
_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(fmt.format('''
library ${pubspec.name}.models.$lower;
import 'package:angel_model/angel_model.dart';
class $name extends Model {
@override
String id;
String name, description;
@override
DateTime createdAt, updatedAt;
$name({this.id, this.name, this.description, this.createdAt, this.updatedAt});
}
'''));
}
_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(fmt.format('''
library ${pubspec.name}.validtors.$lower;
import 'package:angel_validate/angel_validate.dart';
final Validator ${rc.camelCase} = new Validator({
'name': [isString, isNotEmpty],
'description': [isString, isNotEmpty]
});
final Validator create${rc.pascalCase} = ${rc.camelCase}.extend({})
..requiredFields.addAll(['name', 'description']);
'''));
}
_generateRunConfiguration(String name, String lower) {
return '''
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="$name Tests" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true">
<option name="filePath" value="\$PROJECT_DIR\$/test/services/${lower}_test.dart" />
<method />
</configuration>
</component>
'''
.trim();
}
_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';
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);
});
tearDown(() async {
await client.close();
app = null;
});
test('index via REST', () async {
var response = await client.get('/api/${pluralize(lower)}');
expect(response, hasStatus(HttpStatus.OK));
});
test('Index ${pluralize(lower)}', () async {
var ${pluralize(lower)} = await client.service('api/${pluralize(lower)}').index();
print(${pluralize(lower)});
});
}
''');
}
}

View file

@ -1,398 +0,0 @@
import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:console/console.dart';
import 'package:id/id.dart';
import 'package:recase/recase.dart';
import 'init.dart' show preBuild;
class ServiceCommand extends Command {
final String CUSTOM = 'Custom';
final String MEMORY = 'In-Memory';
final String MEMORY_JSON = 'In-Memory (serialized via `source_gen`)';
final String MONGO = 'MongoDB';
final String MONGO_TYPED = 'MongoDB (typed)';
final String MONGO_TYPED_JSON =
'MongoDB (typed, serialized via `source_gen`)';
final String TRESTLE = 'Trestle';
final TextPen _pen = new TextPen();
@override
String get name => 'service';
@override
String get description => 'Creates a new service within the given project.';
String _snake(name) => idFromString(name).snake;
@override
run() async {
var name = await readInput('Name of Service (not plural): ');
var chooser = new Chooser([MONGO, MONGO_TYPED, MEMORY, CUSTOM],
message: 'What type of service would you like to create? ');
var type = await chooser.choose();
fail() {
_pen.red();
_pen('Could not successfully create service $name.');
_pen();
}
String serviceSource = '';
if (type == MONGO) {
serviceSource = _generateMongoService(name);
} else if (type == MONGO_TYPED) {
serviceSource = _generateMongoTypedService(name);
await _generateMongoModel(name);
await _generateValidator(name);
} else if (type == MONGO_TYPED_JSON) {
serviceSource = _generateMongoTypedService(name);
await _generateMongoModelJson(name);
await _generateValidator(name);
} else if (type == MEMORY) {
serviceSource = _generateMemoryService(name);
await _generateMemoryModel(name);
await _generateValidator(name);
} else if (type == MEMORY_JSON) {
serviceSource = _generateMemoryService(name);
await _generateMemoryModelJson(name);
await _generateValidator(name);
} else if (type == CUSTOM) {
serviceSource = _generateCustomService(name);
} else if (type == TRESTLE) {
_pen.blue();
_pen('${Icon.STAR} Trestle services are not yet implemented. :(');
_pen();
} else {
print('Code to generate a $type service is not yet written.');
}
if (serviceSource.isEmpty) {
fail();
throw new Exception('Empty generated service code.');
}
var lower = _snake(name);
var servicesDir = new Directory('lib/src/services');
var serviceFile = new File.fromUri(servicesDir.uri.resolve('$lower.dart'));
var testDir = new Directory('test/services');
var testFile = new File.fromUri(testDir.uri.resolve('${lower}_test.dart'));
if (!await servicesDir.exists()) await servicesDir.create(recursive: true);
if (!await testDir.exists()) await testDir.create(recursive: true);
await serviceFile.writeAsString(serviceSource);
if (type == MONGO_TYPED || type == MEMORY) {
var serviceLibrary = new File('lib/src/models/models.dart');
await serviceLibrary.writeAsString("\nexport '$lower.dart';",
mode: FileMode.APPEND);
await preBuild(Directory.current);
}
await testFile.writeAsString(_generateTests(name, type));
var 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 service $name.');
_pen();
}
_generateValidator(String name) async {
var rc = new ReCase(name);
var file = new File('lib/src/validators/${rc.snakeCase}.dart');
if (!await file.exists()) await file.createSync(recursive: true);
await file.writeAsString('''
import 'package:angel_validate/angel_validate.dart';
final Validator CREATE_${rc.constantCase} =
new Validator({'name*': isString, 'desc*': isString});
'''
.trim());
}
_generateCustomService(String name) {
return '''
import 'package:angel_framework/angel_framework.dart';
class ${name}Service extends Service {
${name}Service():super() {
// Your logic here!
}
}
'''
.trim();
}
_generateMemoryModel(String name) async {
var lower = _snake(name);
var file = new File('lib/src/models/$lower.dart');
if (!await file.exists()) await file.createSync(recursive: true);
await file.writeAsString('''
library angel.models.$lower;
import 'package:angel_framework/common.dart';
class $name extends Model {
String name, desc;
$name({String id, this.name, this.desc}) {
this.id = id;
}
}
'''
.trim());
}
_generateMemoryModelJson(String name) async {
var lower = _snake(name);
var file = new File('lib/src/models/$lower.dart');
if (!await file.exists()) await file.createSync(recursive: true);
await file.writeAsString('''
library angel.models.$lower;
import 'package:angel_framework/common.dart';
import 'package:source_gen/generators/json_serializable.dart';
part '$lower.g.dart';
@JsonSerializable()
class $name extends Model with _\$${name}SerializerMixin {
@JsonKey('id')
@override
String id;
@JsonKey('name')
String name;
@JsonKey('desc')
String desc;
factory $name.fromJson(Map json) => _\$${name}FromJson(json);
$name({this.id, this.name, this.desc});
}
'''
.trim());
}
_generateMemoryService(String name) {
var rc = new ReCase(name);
var lower = rc.snakeCase;
return '''
import 'package:angel_framework/angel_framework.dart';
import '../models/$lower.dart';
export '../models/$lower.dart';
/// Manages [$name] in-memory.
class ${name}Service extends MemoryService<$name> {
${name}Service():super() {
// Your logic here!
}
}
'''
.trim();
}
_generateMongoModel(String name) async {
var lower = _snake(name);
var file = new File('lib/src/models/$lower.dart');
if (!await file.exists()) await file.createSync(recursive: true);
await file.writeAsString('''
library angel.models.$lower;
import 'package:angel_mongo/model.dart';
import 'package:source_gen/generators/json_serializable.dart';
part '$lower.g.dart';
@JsonSerializable()
class $name extends Model with _\$${name}SerializerMixin {
@JsonKey('id')
@override
String id;
@JsonKey('name')
String name;
@JsonKey('desc')
String desc;
factory $name.fromJson(Map json) => _\$${name}FromJson(json);
$name({this.id, this.name, this.desc});
}
'''
.trim());
}
_generateMongoModelJson(String name) async {
var lower = _snake(name);
var file = new File('lib/src/models/$lower.dart');
if (!await file.exists()) await file.createSync(recursive: true);
await file.writeAsString('''
library angel.models.$lower;
import 'package:angel_framework/common.dart';
import 'package:source_gen/generators/json_serializable.dart';
part '$lower.g.dart';
@JsonSerializable()
class $name extends Model with _\$${name}SerializerMixin {
@JsonKey('id')
@override
String id;
@JsonKey('name')
String name;
@JsonKey('desc')
String desc;
factory $name.fromJson(Map json) => _\$${name}FromJson(json);
$name({this.id, this.name, this.desc});
}
'''
.trim());
}
_generateMongoService(String name) {
var lower = _snake(name);
return '''
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_mongo/angel_mongo.dart';
import 'package:angel_validate/angel_validate.dart';
import 'package:angel_validate/server.dart';
import 'package:mongo_dart/mongo_dart.dart';
final Validator ${lower}Schema = new Validator({
'name*': [isString, isNotEmpty],
'desc*': [isString, isNotEmpty]
});
configureServer(Db db) {
return (Angel app) async {
app.use('/api/${lower}s', new ${name}Service(db.collection('${lower}s')));
HookedService service = app.service('api/${lower}s');
app.container.singleton(service.inner);
service
..beforeCreate.listen(validateEvent(${lower}Schema))
..beforeUpdate.listen(validateEvent(${lower}Schema));
};
}
/// Manages [$name] in the database.
class ${name}Service extends MongoService {
${name}Service(collection):super(collection) {
// Your logic here!
}
}
'''
.trim();
}
_generateMongoTypedService(String name) {
var lower = _snake(name);
return '''
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_mongo/angel_mongo.dart';
import 'package:mongo_dart/mongo_dart.dart';
import '../models/$lower.dart';
export '../models/$lower.dart';
configureServer(Db db) {
return (Angel app) async {
app.use('/api/${lower}s', new ${name}Service(db.collection('${lower}s')));
HookedService service = app.service('api/${lower}s');
app.container.singleton(service.inner);
};
}
/// Manages [$name] in the database.
class ${name}Service extends MongoTypedService<$name> {
${name}Service(collection):super(collection) {
// Your logic here!
}
}
'''
.trim();
}
_generateRunConfiguration(String name) {
var lower = _snake(name);
return '''
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="$name Tests" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true">
<option name="filePath" value="\$PROJECT_DIR\$/test/services/${lower}_test.dart" />
<method />
</configuration>
</component>
'''
.trim();
}
_generateTests(String name, String type) {
var lower = _snake(name);
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);
});
tearDown(() async {
await client.close();
app = null;
});
test('index via REST', () async {
var response = await client.get('/api/${lower}s');
expect(response, hasStatus(HttpStatus.OK));
});
test('Index ${lower}s', () async {
var ${lower}s = await client.service('api/${lower}s').index();
print(${lower}s);
});
}
'''
.trim();
}
}

View file

@ -1,141 +0,0 @@
import 'dart:async';
import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:watcher/watcher.dart';
import 'package:yaml/yaml.dart';
import 'deprecated.dart';
import 'pub.dart';
Process server;
bool watching = false;
class StartCommand extends Command {
@override
String get name => 'start';
@override
String get description =>
'Runs any `start` scripts, and then runs the server.';
StartCommand() : super() {
argParser
..addFlag('multi',
help: 'Starts bin/multi_server.dart, instead of the standard server.',
negatable: false,
defaultsTo: false)
..addFlag('production',
help: 'Starts the server in production mode.',
negatable: false,
defaultsTo: false)
..addFlag('watch',
abbr: 'w',
help: 'Restart the server on file changes.',
defaultsTo: true);
}
@override
run() async {
warnDeprecated(this.name);
stderr
..writeln(
'WARNING: `angel start` is now deprecated, in favor of `package:angel_hot`.')
..writeln(
'This new alternative supports hot reloading, which is faster and more reliable.')
..writeln()
..writeln('Find it on Pub: https://pub.dartlang.org/packages/angel_hot');
if (argResults['watch']) {
try {
new DirectoryWatcher('bin').events.listen((_) async => start());
} catch (e) {
// Fail silently...
}
try {
new DirectoryWatcher('config').events.listen((_) async => start());
} catch (e) {
// Fail silently...
}
try {
new DirectoryWatcher('lib').events.listen((_) async => start());
} catch (e) {
// Fail silently...
}
}
return await start();
}
start() async {
bool isNew = true;
if (server != null) {
isNew = false;
if (!server.kill()) {
throw new Exception('Could not kill existing server process.');
}
}
final pubspec = new File('pubspec.yaml');
if (await pubspec.exists()) {
// Run start scripts
final doc = loadYamlDocument(await pubspec.readAsString());
final scriptsNode = doc.contents.value['scripts'];
if (scriptsNode != null && scriptsNode.containsKey('start')) {
try {
var scripts = await Process.start(
resolvePub(), ['global', 'run', 'scripts', 'start']);
listen(scripts.stdout, stdout);
listen(scripts.stderr, stderr);
int code = await scripts.exitCode;
if (code != 0) {
throw new Exception('`scripts start` failed with exit code $code.');
}
} catch (e) {
// No scripts? No problem...
}
}
}
if (isNew)
print('Starting server...');
else
print('Changes detected - restarting server...');
final env = {};
if (argResults['production']) env['ANGEL_ENV'] = 'production';
server = await Process.start(
Platform.executable,
[
argResults['multi'] == true
? 'bin/multi_server.dart'
: 'bin/server.dart'
],
environment: env);
try {
listen(server.stdout, stdout);
listen(server.stderr, stderr);
} catch (e) {
print(e);
}
if (!isNew) {
print(
'${new DateTime.now().toIso8601String()}: Successfully restarted server.');
}
exitCode = await server.exitCode;
}
}
void listen(Stream<List<int>> stream, IOSink sink) {
stream.listen(sink.add);
}

View file

@ -1,85 +0,0 @@
import 'dart:io';
import 'package:args/command_runner.dart';
import "package:console/console.dart";
import 'package:dart_style/dart_style.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:recase/recase.dart';
import 'deprecated.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 {
warnDeprecated(this.name, _pen);
final name = await readInput("Name of Test: "),
lower = new ReCase(name).snakeCase;
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(new DartFormatter()
.format(_generateTest(await Pubspec.load(Directory.current), 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(Pubspec pubspec, String lower) {
return '''
import 'dart:io';
import 'package:${pubspec.name}/${pubspec.name}.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_test/angel_test.dart';
import 'package:test/test.dart';
main() async {
TestClient client;
setUp(() async {
var app = await createServer();
client = await connectTo(app);
});
tearDown(() => client.close());
test('$lower', () async {
final response = await client.get('/$lower');
expect(response, hasStatus(HttpStatus.OK));
});
}
'''
.trim();
}
}