'init' command
This commit is contained in:
parent
034ede4dad
commit
57d95e71c4
7 changed files with 87 additions and 19 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -74,3 +74,4 @@ doc/api/
|
|||
pubspec.lock
|
||||
/sample_project/lib/src/services/
|
||||
/sample_project/test/services/
|
||||
/sample_project/
|
||||
|
|
8
.idea/runConfigurations/Init.xml
Normal file
8
.idea/runConfigurations/Init.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Init" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
|
||||
<option name="arguments" value="init sample_project" />
|
||||
<option name="filePath" value="$PROJECT_DIR$/bin/angel.dart" />
|
||||
<option name="workingDirectory" value="$PROJECT_DIR$" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
|
@ -13,6 +13,7 @@ main(List<String> args) {
|
|||
|
||||
runner.addCommand(new DoctorCommand());
|
||||
runner.addCommand(new ServiceCommand());
|
||||
runner.addCommand(new InitCommand());
|
||||
|
||||
return runner.run(args).then((_) {}).catchError((exc) {
|
||||
stderr.writeln("Oops, something went wrong: $exc");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
library angel_cli.commands;
|
||||
|
||||
export "doctor.dart";
|
||||
export "init.dart";
|
||||
export "service.dart";
|
76
lib/src/commands/init.dart
Normal file
76
lib/src/commands/init.dart
Normal file
|
@ -0,0 +1,76 @@
|
|||
import "dart:convert";
|
||||
import "dart:io";
|
||||
import "package:args/command_runner.dart";
|
||||
import "package:console/console.dart";
|
||||
|
||||
class InitCommand extends Command {
|
||||
final TextPen _pen = new TextPen();
|
||||
|
||||
@override
|
||||
String get name => "init";
|
||||
|
||||
@override
|
||||
String get description =>
|
||||
"Initializes a new Angel project in the current directory.";
|
||||
|
||||
InitCommand() {}
|
||||
|
||||
@override
|
||||
run() async {
|
||||
Directory projectDir = new Directory(
|
||||
argResults.arguments.isEmpty ? "." : argResults.arguments[0]);
|
||||
print("Creating new Angel project in ${projectDir.absolute.path}...");
|
||||
await _cloneRepo(projectDir);_pen.green();
|
||||
_pen("${Icon.CHECKMARK} Successfully initialized Angel project. Now running pub get...");
|
||||
_pen();
|
||||
await _pubGet();
|
||||
}
|
||||
|
||||
_cloneRepo(Directory projectDir) async {
|
||||
try {
|
||||
if (await projectDir.exists()) {
|
||||
var chooser = new Chooser(["Yes", "No"],
|
||||
message:
|
||||
"Directory '${projectDir.absolute.path}' exists. Overwrite it? (Yes/No)");
|
||||
|
||||
if (await chooser.choose() != "Yes")
|
||||
throw new Exception("Chose not to overwrite existing directory.");
|
||||
await projectDir.delete(recursive: true);
|
||||
}
|
||||
|
||||
var git = await Process.start("git", [
|
||||
"clone",
|
||||
"--depth",
|
||||
"1",
|
||||
"https://github.com/angel-dart/angel",
|
||||
projectDir.absolute.path
|
||||
]);
|
||||
|
||||
git.stdout.transform(UTF8.decoder).listen(stdout.write);
|
||||
git.stderr.transform(UTF8.decoder).listen(stderr.write);
|
||||
|
||||
if (await git.exitCode != 0) {
|
||||
throw new Exception("Could not clone repo.");
|
||||
}
|
||||
|
||||
var gitDir = new Directory.fromUri(projectDir.uri.resolve(".git"));
|
||||
|
||||
if (await gitDir.exists())
|
||||
await gitDir.delete(recursive: true);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
_pen.red();
|
||||
_pen("${Icon.BALLOT_X} Could not initialize Angel project.");
|
||||
_pen();
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
_pubGet() async {
|
||||
var pub = await Process.start("pub", ["get"]);
|
||||
pub.stdout.pipe(stdout);
|
||||
pub.stderr.pipe(stderr);
|
||||
var code = await pub.exitCode;
|
||||
print("Pub process exited with code $code");
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
import "dart:async";
|
||||
import "dart:io";
|
||||
import "package:angel_framework/angel_framework.dart";
|
||||
import "package:angel/src/services/services.dart";
|
||||
|
||||
class SampleServer extends Angel {
|
||||
@override
|
||||
startServer(address, port) async {
|
||||
return await super.startServer(address, port);
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
name: angel
|
||||
publish_to: none
|
||||
dependencies:
|
||||
angel_framework: ^1.0.0-dev
|
||||
angel_mongo: ^1.0.0-dev
|
||||
dev_dependencies:
|
||||
http: ^0.11.3
|
||||
test: ^0.12.13
|
Loading…
Reference in a new issue