Snake
This commit is contained in:
parent
08e12d9f4a
commit
0790b41110
2 changed files with 28 additions and 23 deletions
|
@ -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:id/id.dart';
|
||||||
|
|
||||||
class ServiceCommand extends Command {
|
class ServiceCommand extends Command {
|
||||||
final String CUSTOM = 'Custom';
|
final String CUSTOM = 'Custom';
|
||||||
|
@ -16,6 +17,8 @@ class ServiceCommand extends Command {
|
||||||
@override
|
@override
|
||||||
String get description => 'Creates a new service within the given project.';
|
String get description => 'Creates a new service within the given project.';
|
||||||
|
|
||||||
|
String _snake(name) => idFromString(name).snake;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
run() async {
|
run() async {
|
||||||
var name = await readInput('Name of Service (not plural): ');
|
var name = await readInput('Name of Service (not plural): ');
|
||||||
|
@ -54,12 +57,11 @@ class ServiceCommand extends Command {
|
||||||
throw new Exception('Empty generated service code.');
|
throw new Exception('Empty generated service code.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lower = _snake(name);
|
||||||
var servicesDir = new Directory('lib/src/services');
|
var servicesDir = new Directory('lib/src/services');
|
||||||
var serviceFile =
|
var serviceFile = new File.fromUri(servicesDir.uri.resolve('$lower.dart'));
|
||||||
new File.fromUri(servicesDir.uri.resolve('${name.toLowerCase()}.dart'));
|
|
||||||
var testDir = new Directory('test/services');
|
var testDir = new Directory('test/services');
|
||||||
var testFile = new File.fromUri(
|
var testFile = new File.fromUri(testDir.uri.resolve('${lower}_test.dart'));
|
||||||
testDir.uri.resolve('${name.toLowerCase()}_test.dart'));
|
|
||||||
|
|
||||||
if (!await servicesDir.exists()) await servicesDir.create(recursive: true);
|
if (!await servicesDir.exists()) await servicesDir.create(recursive: true);
|
||||||
|
|
||||||
|
@ -69,14 +71,13 @@ class ServiceCommand extends Command {
|
||||||
|
|
||||||
if (type == MONGO_TYPED || type == MEMORY) {
|
if (type == MONGO_TYPED || type == MEMORY) {
|
||||||
var serviceLibrary = new File('lib/src/models/models.dart');
|
var serviceLibrary = new File('lib/src/models/models.dart');
|
||||||
await serviceLibrary.writeAsString(
|
await serviceLibrary.writeAsString("\nexport '$lower.dart';",
|
||||||
'\nexport "${name.toLowerCase()}.dart";',
|
|
||||||
mode: FileMode.APPEND);
|
mode: FileMode.APPEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
await testFile.writeAsString(_generateTests(name, type));
|
await testFile.writeAsString(_generateTests(name, type));
|
||||||
|
|
||||||
final runConfig = new File('./.idea/runConfigurations/${name}_tests.xml');
|
var runConfig = new File('./.idea/runConfigurations/${name}_Tests.xml');
|
||||||
|
|
||||||
if (!await runConfig.exists()) {
|
if (!await runConfig.exists()) {
|
||||||
await runConfig.create(recursive: true);
|
await runConfig.create(recursive: true);
|
||||||
|
@ -102,8 +103,8 @@ class ${name}Service extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
_generateMemoryModel(String name) async {
|
_generateMemoryModel(String name) async {
|
||||||
final lower = name.toLowerCase();
|
var lower = _snake(name);
|
||||||
final 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);
|
||||||
|
|
||||||
|
@ -179,8 +180,8 @@ class ${name}Service extends MemoryService<$name> {
|
||||||
}
|
}
|
||||||
|
|
||||||
_generateMongoModel(String name) async {
|
_generateMongoModel(String name) async {
|
||||||
final lower = name.toLowerCase();
|
var lower = _snake(name);
|
||||||
final 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);
|
||||||
|
|
||||||
|
@ -217,7 +218,7 @@ class $name extends Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
_generateMongoService(String name) {
|
_generateMongoService(String name) {
|
||||||
final lower = name.toLowerCase();
|
var lower = _snake(name);
|
||||||
|
|
||||||
return '''
|
return '''
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
|
@ -244,7 +245,7 @@ class ${name}Service extends MongoService {
|
||||||
}
|
}
|
||||||
|
|
||||||
_generateMongoTypedService(String name) {
|
_generateMongoTypedService(String name) {
|
||||||
final lower = name.toLowerCase();
|
var lower = _snake(name);
|
||||||
|
|
||||||
return '''
|
return '''
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
|
@ -273,7 +274,7 @@ class ${name}Service extends MongoTypedService<$name> {
|
||||||
}
|
}
|
||||||
|
|
||||||
_generateRunConfiguration(String name) {
|
_generateRunConfiguration(String name) {
|
||||||
final lower = name.toLowerCase();
|
var lower = _snake(name);
|
||||||
|
|
||||||
return '''
|
return '''
|
||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
@ -287,6 +288,8 @@ class ${name}Service extends MongoTypedService<$name> {
|
||||||
}
|
}
|
||||||
|
|
||||||
_generateTests(String name, String type) {
|
_generateTests(String name, String type) {
|
||||||
|
var lower = _snake(name);
|
||||||
|
|
||||||
return '''
|
return '''
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:angel/angel.dart';
|
import 'package:angel/angel.dart';
|
||||||
|
@ -309,13 +312,13 @@ main() async {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('index via REST', () async {
|
test('index via REST', () async {
|
||||||
final response = await client.get('/api/${name.toLowerCase()}');
|
var response = await client.get('/api/${lower}s');
|
||||||
expect(response, hasStatus(HttpStatus.OK));
|
expect(response, hasStatus(HttpStatus.OK));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Index ${name.toLowerCase()}s', () async {
|
test('Index ${lower}s', () async {
|
||||||
final ${name.toLowerCase()}s = await client.service('api/${name.toLowerCase()}').index();
|
var ${lower}s = await client.service('api/${lower}s').index();
|
||||||
print(${name.toLowerCase()}s);
|
print(${lower}s);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
pubspec.yaml
12
pubspec.yaml
|
@ -1,12 +1,14 @@
|
||||||
name: angel_cli
|
name: angel_cli
|
||||||
version: 1.0.0-dev+7
|
version: 1.0.0-dev+8
|
||||||
description: Command-line tools for the Angel framework.
|
description: Command-line tools for the Angel framework.
|
||||||
|
environment:
|
||||||
|
sdk: ">=1.19.0"
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_cli
|
homepage: https://github.com/angel-dart/angel_cli
|
||||||
executables:
|
executables:
|
||||||
angel: angel
|
angel: angel
|
||||||
dependencies:
|
dependencies:
|
||||||
analyzer: ">=0.28.1 <1.0.0"
|
args: ^0.13.7
|
||||||
args: ">=0.3.4 <1.0.0"
|
id: ^1.0.0
|
||||||
console: ">=2.2.3 <3.0.0"
|
console: ^2.2.3
|
||||||
yaml: ">=2.0.0 <3.0.0"
|
yaml: ^2.0.0
|
Loading…
Reference in a new issue