1.1.1
This commit is contained in:
parent
1af44cab90
commit
dea34baf4e
16 changed files with 203 additions and 45 deletions
8
.idea/runConfigurations/Controller.xml
Normal file
8
.idea/runConfigurations/Controller.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Controller" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
|
||||||
|
<option name="arguments" value="controller" />
|
||||||
|
<option name="filePath" value="$PROJECT_DIR$/bin/angel.dart" />
|
||||||
|
<option name="workingDirectory" value="$PROJECT_DIR$/sample_project" />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
8
.idea/runConfigurations/Update.xml
Normal file
8
.idea/runConfigurations/Update.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Update" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
|
||||||
|
<option name="arguments" value="update" />
|
||||||
|
<option name="filePath" value="$PROJECT_DIR$/bin/angel.dart" />
|
||||||
|
<option name="workingDirectory" value="$PROJECT_DIR$" />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -1,12 +1,9 @@
|
||||||
#!/usr/bin/env dart
|
#!/usr/bin/env dart
|
||||||
library demon.tool;
|
library angel_cli.tool;
|
||||||
|
|
||||||
import "dart:io";
|
import "dart:io";
|
||||||
import "package:args/command_runner.dart";
|
import "package:args/command_runner.dart";
|
||||||
import 'package:angel_cli/angel_cli.dart';
|
import 'package:angel_cli/angel_cli.dart';
|
||||||
import 'package:angel_cli/pubspec.dart';
|
|
||||||
import 'package:console/console.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
|
|
||||||
final String DOCTOR = "doctor";
|
final String DOCTOR = "doctor";
|
||||||
|
|
||||||
|
@ -15,6 +12,7 @@ main(List<String> args) async {
|
||||||
new CommandRunner("angel", "Command-line tools for the Angel framework.");
|
new CommandRunner("angel", "Command-line tools for the Angel framework.");
|
||||||
|
|
||||||
runner
|
runner
|
||||||
|
..addCommand(new ControllerCommand())
|
||||||
..addCommand(new DoctorCommand())
|
..addCommand(new DoctorCommand())
|
||||||
..addCommand(new KeyCommand())
|
..addCommand(new KeyCommand())
|
||||||
..addCommand(new ServiceCommand())
|
..addCommand(new ServiceCommand())
|
||||||
|
@ -22,29 +20,8 @@ main(List<String> args) async {
|
||||||
..addCommand(new TestCommand())
|
..addCommand(new TestCommand())
|
||||||
..addCommand(new PluginCommand())
|
..addCommand(new PluginCommand())
|
||||||
..addCommand(new StartCommand())
|
..addCommand(new StartCommand())
|
||||||
..addCommand(new RenameCommand());
|
..addCommand(new RenameCommand())
|
||||||
|
..addCommand(new UpdateCommand());
|
||||||
stdout.write('Checking for update... ');
|
|
||||||
|
|
||||||
try {
|
|
||||||
var client = new http.Client();
|
|
||||||
var update = await checkForUpdate(client);
|
|
||||||
client.close();
|
|
||||||
|
|
||||||
if (update != null) {
|
|
||||||
stdout.writeln();
|
|
||||||
var pen = new TextPen();
|
|
||||||
pen.cyan();
|
|
||||||
pen.text(
|
|
||||||
'ATTENTION: There is a new version of the Angel CLI available (version $update).');
|
|
||||||
pen.text('\nTo update, run `pub global activate angel_cli`.');
|
|
||||||
pen();
|
|
||||||
stdout.writeln();
|
|
||||||
} else
|
|
||||||
stdout.writeln('No update available.');
|
|
||||||
} catch (e) {
|
|
||||||
stdout.writeln('Failed to check for update.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return await runner.run(args).then((_) {}).catchError((exc) {
|
return await runner.run(args).then((_) {}).catchError((exc) {
|
||||||
stderr.writeln("Oops, something went wrong: $exc");
|
stderr.writeln("Oops, something went wrong: $exc");
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
library demon;
|
library angel_cli;
|
||||||
|
|
||||||
export 'src/commands/commands.dart';
|
export 'src/commands/commands.dart';
|
|
@ -1 +0,0 @@
|
||||||
export 'src/pubspec.update.g.dart';
|
|
|
@ -1,5 +1,6 @@
|
||||||
library angel_cli.commands;
|
library angel_cli.commands;
|
||||||
|
|
||||||
|
export 'controller.dart';
|
||||||
export "doctor.dart";
|
export "doctor.dart";
|
||||||
export "key.dart";
|
export "key.dart";
|
||||||
export "init.dart";
|
export "init.dart";
|
||||||
|
@ -7,4 +8,5 @@ export "plugin.dart";
|
||||||
export "rename.dart";
|
export "rename.dart";
|
||||||
export "service.dart";
|
export "service.dart";
|
||||||
export "start.dart";
|
export "start.dart";
|
||||||
export "test.dart";
|
export "test.dart";
|
||||||
|
export 'update.dart';
|
66
lib/src/commands/controller.dart
Normal file
66
lib/src/commands/controller.dart
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:args/command_runner.dart';
|
||||||
|
import 'package:code_builder/code_builder.dart';
|
||||||
|
import "package:console/console.dart";
|
||||||
|
import 'package:pubspec/pubspec.dart';
|
||||||
|
import 'package:recase/recase.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 {
|
||||||
|
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) => new TypeBuilder('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 ImportBuilder('package:angel_common/angel_common.dart'));
|
||||||
|
|
||||||
|
var clazz = new ClassBuilder('${recase.pascalCase}Controller',
|
||||||
|
asExtends: new TypeBuilder('Controller'));
|
||||||
|
|
||||||
|
// Add @Expose()
|
||||||
|
clazz.addAnnotation(_expose('/$lower'));
|
||||||
|
|
||||||
|
// Add
|
||||||
|
// @Expose(path: '/')
|
||||||
|
// String foo() => 'bar';
|
||||||
|
|
||||||
|
var meth = new MethodBuilder('foo',
|
||||||
|
returns: literal('bar'), returnType: new TypeBuilder('String'));
|
||||||
|
meth.addAnnotation(_expose('/'));
|
||||||
|
clazz.addMethod(meth);
|
||||||
|
|
||||||
|
lib.addMember(clazz);
|
||||||
|
|
||||||
|
return prettyToSource(lib.buildAst());
|
||||||
|
}
|
||||||
|
}
|
|
@ -64,7 +64,14 @@ class InitCommand extends Command {
|
||||||
..text('`angel start`')
|
..text('`angel start`')
|
||||||
..normal()
|
..normal()
|
||||||
..text(' in your terminal.')
|
..text(' in your terminal.')
|
||||||
..text('\nHappy coding!')
|
..text('\n\nFind more documentation about Angel:')
|
||||||
|
..text('\n * https://angel-dart.github.io')
|
||||||
|
..text('\n * https://github.com/angel-dart/angel/wiki')
|
||||||
|
..text(
|
||||||
|
'\n * https://www.youtube.com/playlist?list=PLl3P3tmiT-frEV50VdH_cIrA2YqIyHkkY')
|
||||||
|
..text('\n * https://medium.com/the-angel-framework')
|
||||||
|
..text('\n * https://dart.academy/tag/angel')
|
||||||
|
..text('\n\nHappy coding!')
|
||||||
..call();
|
..call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +152,8 @@ class InitCommand extends Command {
|
||||||
static String resolvePub() {
|
static 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) pubPath = pubPath.replaceAll(_leadingSlashes, '') + '.bat';
|
if (Platform.isWindows)
|
||||||
|
pubPath = pubPath.replaceAll(_leadingSlashes, '') + '.bat';
|
||||||
pubPath = Uri.decodeFull(pubPath);
|
pubPath = Uri.decodeFull(pubPath);
|
||||||
return pubPath;
|
return pubPath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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, 0);
|
final Version PACKAGE_VERSION = new Version(1, 1, 1);
|
||||||
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');
|
|
@ -10,6 +10,7 @@ import 'init.dart' show preBuild;
|
||||||
|
|
||||||
const List<ServiceGenerator> GENERATORS = const [
|
const List<ServiceGenerator> GENERATORS = const [
|
||||||
const MapServiceGenerator(),
|
const MapServiceGenerator(),
|
||||||
|
const FileServiceGenerator(),
|
||||||
const MongoServiceGenerator(),
|
const MongoServiceGenerator(),
|
||||||
const RethinkServiceGenerator(),
|
const RethinkServiceGenerator(),
|
||||||
const CustomServiceGenerator()
|
const CustomServiceGenerator()
|
||||||
|
@ -70,7 +71,7 @@ class ServiceCommand extends Command {
|
||||||
await runConfig.writeAsString(_generateRunConfiguration(name, lower));
|
await runConfig.writeAsString(_generateRunConfiguration(name, lower));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generator.createsModel == true) {
|
if (generator.createsModel == true || typed == true) {
|
||||||
await _generateModel(pubspec, name, lower);
|
await _generateModel(pubspec, name, lower);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +79,7 @@ class ServiceCommand extends Command {
|
||||||
await _generateValidator(pubspec, lower, rc.constantCase);
|
await _generateValidator(pubspec, lower, rc.constantCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generator.exportedInServiceLibrary == true) {
|
if (generator.exportedInServiceLibrary == true || typed == true) {
|
||||||
var serviceLibrary = new File('lib/src/models/models.dart');
|
var serviceLibrary = new File('lib/src/models/models.dart');
|
||||||
await serviceLibrary.writeAsString("\nexport '$lower.dart';",
|
await serviceLibrary.writeAsString("\nexport '$lower.dart';",
|
||||||
mode: FileMode.APPEND);
|
mode: FileMode.APPEND);
|
||||||
|
|
26
lib/src/commands/service_generators/file_service.dart
Normal file
26
lib/src/commands/service_generators/file_service.dart
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import 'generator.dart';
|
||||||
|
import 'package:code_builder/code_builder.dart';
|
||||||
|
import 'package:inflection/inflection.dart';
|
||||||
|
|
||||||
|
class FileServiceGenerator extends ServiceGenerator {
|
||||||
|
const FileServiceGenerator() : super('Persistent JSON File');
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get createsModel => false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void applyToLibrary(LibraryBuilder library, String name, String lower) {
|
||||||
|
library.addMember(new ImportBuilder('dart:io'));
|
||||||
|
library.addMember(new ImportBuilder(
|
||||||
|
'package:angel_file_service/angel_file_service.dart'));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
ExpressionBuilder createInstance(
|
||||||
|
MethodBuilder methodBuilder, String name, String lower) {
|
||||||
|
return new TypeBuilder('JsonFileService').newInstance([
|
||||||
|
new TypeBuilder('File')
|
||||||
|
.newInstance([literal(pluralize(lower) + '_db.json')])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
export 'custom.dart';
|
export 'custom.dart';
|
||||||
|
export 'file_service.dart';
|
||||||
export 'generator.dart';
|
export 'generator.dart';
|
||||||
export 'map.dart';
|
export 'map.dart';
|
||||||
export 'mongo.dart';
|
export 'mongo.dart';
|
||||||
|
|
|
@ -61,18 +61,14 @@ import 'package:angel_test/angel_test.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
main() async {
|
main() async {
|
||||||
Angel app;
|
|
||||||
TestClient client;
|
TestClient client;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
app = await createServer();
|
var app = await createServer();
|
||||||
client = await connectTo(app);
|
client = await connectTo(app);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() => client.close());
|
||||||
await client.close();
|
|
||||||
app = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
test('$lower', () async {
|
test('$lower', () async {
|
||||||
final response = await client.get('/$lower');
|
final response = await client.get('/$lower');
|
||||||
|
|
66
lib/src/commands/update.dart
Normal file
66
lib/src/commands/update.dart
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:args/command_runner.dart';
|
||||||
|
import 'package:console/console.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'init.dart';
|
||||||
|
import 'pubspec.update.g.dart';
|
||||||
|
|
||||||
|
class UpdateCommand extends Command {
|
||||||
|
@override
|
||||||
|
String get name => 'update';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get description => 'Updates the Angel CLI, if an update is available.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
run() async {
|
||||||
|
stdout.write('Checking for update... ');
|
||||||
|
|
||||||
|
try {
|
||||||
|
var client = new http.Client();
|
||||||
|
var update = await checkForUpdate(client);
|
||||||
|
client.close();
|
||||||
|
|
||||||
|
if (update != null) {
|
||||||
|
stdout.writeln();
|
||||||
|
var pen = new TextPen();
|
||||||
|
pen.cyan();
|
||||||
|
pen.text(
|
||||||
|
'ATTENTION: There is a new version of the Angel CLI available (version $update).');
|
||||||
|
pen.call();
|
||||||
|
var prompt = new Chooser<String>(['Yes', 'No']);
|
||||||
|
print('Update now?');
|
||||||
|
var choice = await prompt.choose();
|
||||||
|
|
||||||
|
if (choice != 'Yes') {
|
||||||
|
pen.reset();
|
||||||
|
pen.cyan();
|
||||||
|
pen.text(
|
||||||
|
'When you are ready to update, run `pub global activate angel_cli`.');
|
||||||
|
pen();
|
||||||
|
stdout.writeln();
|
||||||
|
} else {
|
||||||
|
var pubPath = InitCommand.resolvePub();
|
||||||
|
print('Running `pub global activate` using $pubPath...');
|
||||||
|
var p =
|
||||||
|
await Process.start(pubPath, ['global', 'activate', 'angel_cli']);
|
||||||
|
p.stderr.listen(stderr.add);
|
||||||
|
p.stdout.listen(stdout.add);
|
||||||
|
var exitCode = await p.exitCode;
|
||||||
|
|
||||||
|
if (exitCode != 0)
|
||||||
|
throw 'Pub terminated with a non-zero exit code.';
|
||||||
|
else {
|
||||||
|
pen.reset();
|
||||||
|
pen.green();
|
||||||
|
pen("${Icon.CHECKMARK} Successfully updated the Angel CLI to version $update.\n");
|
||||||
|
pen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
stdout.writeln('No update available.');
|
||||||
|
} catch (e) {
|
||||||
|
stdout.writeln('Failed to check for update.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,11 +2,11 @@ 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.0
|
version: 1.1.1
|
||||||
dependencies:
|
dependencies:
|
||||||
# analyzer: "^0.29.0"
|
# analyzer: "^0.29.0"
|
||||||
args: "^0.13.7"
|
args: ^0.13.4
|
||||||
code_builder: "^1.0.0-beta"
|
code_builder: ^1.0.0
|
||||||
console: "^2.2.3"
|
console: "^2.2.3"
|
||||||
glob: "^1.1.0"
|
glob: "^1.1.0"
|
||||||
http: ^0.11.3
|
http: ^0.11.3
|
||||||
|
|
|
@ -2,5 +2,5 @@ import 'package:build_runner/build_runner.dart';
|
||||||
import 'package:check_for_update/builder.dart';
|
import 'package:check_for_update/builder.dart';
|
||||||
|
|
||||||
final PhaseGroup phaseGroup = new PhaseGroup.singleAction(
|
final PhaseGroup phaseGroup = new PhaseGroup.singleAction(
|
||||||
new CheckForUpdateBuilder(subDirectory: 'lib/src'),
|
new CheckForUpdateBuilder(subDirectory: 'lib/src/commands'),
|
||||||
new InputSet('angel_cli', const ['pubspec.yaml']));
|
new InputSet('angel_cli', const ['pubspec.yaml']));
|
||||||
|
|
Loading…
Reference in a new issue