From b3fe0c514610a6fa530187566028f79926a14070 Mon Sep 17 00:00:00 2001 From: thosakwe Date: Tue, 13 Dec 2016 12:50:53 -0500 Subject: [PATCH] Added start --- .DS_Store | Bin 0 -> 6148 bytes .idea/angel_cli.iml | 26 ++++++++++++++ .idea/modules.xml | 8 +++++ README.md | 14 +++++++- bin/angel.dart | 3 +- lib/src/commands/commands.dart | 1 + lib/src/commands/start.dart | 63 +++++++++++++++++++++++++++++++++ pubspec.yaml | 2 +- 8 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 .DS_Store create mode 100644 .idea/angel_cli.iml create mode 100644 .idea/modules.xml create mode 100644 lib/src/commands/start.dart diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c2e90e8119a896a5bda0104623306eb0a7172b7d GIT binary patch literal 6148 zcmeHKO-sW-5Pj1YnxcmuJ?7}C;6I495ejOd^#{}>3Su-u>A_omhCj;xq;GbYlBD%2 zDl;(q_G8}e3hd9I)=D0wL8?2DFqh;BNKE^Ay zOlU*AM~(^CsEAK(9yGo8Mtb|aH{9VFWrwHPHF+Z}nb|pJxF$}>DB28{VUsb$Ef$Pl z9E#SwBx>Zv<;+Y0Q@|AXZ3^fSPK%B_T4@TH0;a%D0X-jLx?&Qr_UMid7VZf^9I)FN z>+a{D7;6VH30Qk%4^2Fk=&2H(7!uwN;^`buLVWGf(;;qU&J$La@IsOB^pMzvLlTcx zngXUkTY + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..5f91449b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 5f33cd5b..87776e1c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ # angel_cli -Command-line tools for the Angel framework. \ No newline at end of file +Command-line tools for the Angel framework. + +To install: + +```bash +$ pub global activate angel_cli +``` + +And then, for information on each command: + +```bash +$ angel --help +``` \ No newline at end of file diff --git a/bin/angel.dart b/bin/angel.dart index fd9e44d0..d16d4266 100644 --- a/bin/angel.dart +++ b/bin/angel.dart @@ -16,7 +16,8 @@ main(List args) { ..addCommand(new ServiceCommand()) ..addCommand(new InitCommand()) ..addCommand(new TestCommand()) - ..addCommand(new PluginCommand()); + ..addCommand(new PluginCommand()) + ..addCommand(new StartCommand()); return runner.run(args).then((_) {}).catchError((exc) { stderr.writeln("Oops, something went wrong: $exc"); diff --git a/lib/src/commands/commands.dart b/lib/src/commands/commands.dart index 14041531..7e82dcc3 100644 --- a/lib/src/commands/commands.dart +++ b/lib/src/commands/commands.dart @@ -4,4 +4,5 @@ export "doctor.dart"; export "init.dart"; export "plugin.dart"; export "service.dart"; +export "start.dart"; export "test.dart"; \ No newline at end of file diff --git a/lib/src/commands/start.dart b/lib/src/commands/start.dart new file mode 100644 index 00000000..23ceff96 --- /dev/null +++ b/lib/src/commands/start.dart @@ -0,0 +1,63 @@ +import 'dart:io'; +import 'package:args/command_runner.dart'; +import 'package:yaml/yaml.dart'; + +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('production', + help: 'Starts the server in production mode.', + negatable: false, + defaultsTo: false); + } + + @override + run() async { + final pubspec = new File('pubspec.yaml'); + + if (await pubspec.exists()) { + // Run start scripts + final doc = loadYamlDocument(await pubspec.readAsString()); + final scriptsNode = doc.contents['scripts']; + + if (scriptsNode != null && scriptsNode.containsKey('start')) { + final scripts = scriptsNode['start'] is List + ? scriptsNode['start'] + : [scriptsNode['start']]; + + for (String script in scripts) { + final split = script.split(' '); + final result = await Process.run(split.first, split.skip(1).toList(), + stdoutEncoding: null, stderrEncoding: null); + final code = result.exitCode; + + stdout.add(result.stdout); + stderr.add(result.stderr); + + if (code != 0) { + throw new Exception("Command '$script' exited with code $code."); + } + } + } + } + + print('Starting server...'); + + final env = {}; + + if (argResults['production']) env['ANGEL_ENV'] = 'production'; + + final server = await Process.start(Platform.executable, ['bin/server.dart'], + environment: env); + server.stdout.pipe(stdout); + server.stderr.pipe(stderr); + + exitCode = await server.exitCode; + } +} diff --git a/pubspec.yaml b/pubspec.yaml index e434f181..75278ac7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_cli -version: 1.0.0-dev+5 +version: 1.0.0-dev+6 description: Command-line tools for the Angel framework. author: Tobe O homepage: https://github.com/angel-dart/angel_cli