Update init command
This commit is contained in:
parent
1cc9e0b83a
commit
d0d05e4eaa
2 changed files with 48 additions and 70 deletions
|
@ -5,7 +5,6 @@ import 'package:io/ansi.dart';
|
||||||
import '../util.dart';
|
import '../util.dart';
|
||||||
|
|
||||||
class DoctorCommand extends Command {
|
class DoctorCommand extends Command {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get name => "doctor";
|
String get name => "doctor";
|
||||||
|
|
||||||
|
@ -24,7 +23,8 @@ class DoctorCommand extends Command {
|
||||||
var git = await Process.start("git", ["--version"]);
|
var git = await Process.start("git", ["--version"]);
|
||||||
if (await git.exitCode == 0) {
|
if (await git.exitCode == 0) {
|
||||||
var version = await git.stdout.transform(utf8.decoder).join();
|
var version = await git.stdout.transform(utf8.decoder).join();
|
||||||
print(green.wrap("$checkmark Git executable found: v${version.replaceAll('git version', '').trim()}"))
|
print(green.wrap(
|
||||||
|
"$checkmark Git executable found: v${version.replaceAll('git version', '').trim()}"));
|
||||||
} else
|
} else
|
||||||
throw new Exception("Git executable exit code not 0");
|
throw new Exception("Git executable exit code not 0");
|
||||||
} catch (exc) {
|
} catch (exc) {
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
|
import 'dart:async';
|
||||||
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:io/ansi.dart';
|
||||||
import 'package:random_string/random_string.dart' as rs;
|
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
import 'package:prompts/prompts.dart' as prompts;
|
||||||
|
import 'package:random_string/random_string.dart' as rs;
|
||||||
|
import '../util.dart';
|
||||||
import 'key.dart';
|
import 'key.dart';
|
||||||
import 'pub.dart';
|
import 'pub.dart';
|
||||||
import 'rename.dart';
|
import 'rename.dart';
|
||||||
|
|
||||||
class InitCommand extends Command {
|
class InitCommand extends Command {
|
||||||
final KeyCommand _key = new KeyCommand();
|
final KeyCommand _key = new KeyCommand();
|
||||||
final TextPen _pen = new TextPen();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get name => "init";
|
String get name => "init";
|
||||||
|
@ -19,14 +21,7 @@ class InitCommand extends Command {
|
||||||
"Initializes a new Angel project in the current directory.";
|
"Initializes a new Angel project in the current directory.";
|
||||||
|
|
||||||
InitCommand() {
|
InitCommand() {
|
||||||
argParser
|
argParser..addFlag('pub-get', defaultsTo: true);
|
||||||
..addFlag('pub-get', defaultsTo: true)
|
|
||||||
..addFlag(
|
|
||||||
'legacy',
|
|
||||||
help:
|
|
||||||
'Generate a project using Angel 1.0.x boilerplates, rather than 1.1.x+.',
|
|
||||||
negatable: false,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -59,26 +54,27 @@ class InitCommand extends Command {
|
||||||
await _pubGet(projectDir);
|
await _pubGet(projectDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
_pen.green();
|
print(green.wrap("$checkmark Successfully initialized Angel project."));
|
||||||
_pen("${Icon.CHECKMARK} Successfully initialized Angel project.");
|
|
||||||
_pen();
|
stdout
|
||||||
_pen
|
..writeln()
|
||||||
..reset()
|
..writeln(
|
||||||
..text('\nCongratulations! You are ready to start developing with Angel!')
|
'Congratulations! You are ready to start developing with Angel!')
|
||||||
..text('\nTo start the server (with file watching), run ')
|
..write('To start the server (with ')
|
||||||
..magenta()
|
..write(cyan.wrap('hot-reloading'))
|
||||||
..text(argResults['legacy'] ? '`dart bin/server.dart`' : '`dart bin/dev.dart`')
|
..write('), run ')
|
||||||
..normal()
|
..write(magenta.wrap('`dart --observe bin/dev.dart`'))
|
||||||
..text(' in your terminal.')
|
..writeln(' in your terminal')
|
||||||
..text('\n\nFind more documentation about Angel:')
|
..writeln()
|
||||||
..text('\n * https://angel-dart.github.io')
|
..writeln('Find more documentation about Angel:')
|
||||||
..text('\n * https://github.com/angel-dart/angel/wiki')
|
..writeln(' * https://angel-dart.github.io')
|
||||||
..text(
|
..writeln(' * https://github.com/angel-dart/angel/wiki')
|
||||||
'\n * https://www.youtube.com/playlist?list=PLl3P3tmiT-frEV50VdH_cIrA2YqIyHkkY')
|
..writeln(
|
||||||
..text('\n * https://medium.com/the-angel-framework')
|
' * https://www.youtube.com/playlist?list=PLl3P3tmiT-frEV50VdH_cIrA2YqIyHkkY')
|
||||||
..text('\n * https://dart.academy/tag/angel')
|
..writeln(' * https://medium.com/the-angel-framework')
|
||||||
..text('\n\nHappy coding!')
|
..writeln(' * https://dart.academy/tag/angel')
|
||||||
..call();
|
..writeln()
|
||||||
|
..writeln('Happy coding!');
|
||||||
}
|
}
|
||||||
|
|
||||||
_deleteRecursive(FileSystemEntity entity, [bool self = true]) async {
|
_deleteRecursive(FileSystemEntity entity, [bool self = true]) async {
|
||||||
|
@ -101,9 +97,9 @@ class InitCommand extends Command {
|
||||||
var stat = await FileStat.stat(path);
|
var stat = await FileStat.stat(path);
|
||||||
|
|
||||||
switch (stat.type) {
|
switch (stat.type) {
|
||||||
case FileSystemEntityType.DIRECTORY:
|
case FileSystemEntityType.directory:
|
||||||
return await _deleteRecursive(new Directory(path));
|
return await _deleteRecursive(new Directory(path));
|
||||||
case FileSystemEntityType.FILE:
|
case FileSystemEntityType.file:
|
||||||
return await _deleteRecursive(new File(path));
|
return await _deleteRecursive(new File(path));
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -114,11 +110,10 @@ class InitCommand extends Command {
|
||||||
_cloneRepo(Directory projectDir) async {
|
_cloneRepo(Directory projectDir) async {
|
||||||
try {
|
try {
|
||||||
if (await projectDir.exists()) {
|
if (await projectDir.exists()) {
|
||||||
var chooser = new Chooser(["Yes", "No"],
|
var shouldDelete = prompts.getBool(
|
||||||
message:
|
"Directory '${projectDir.absolute.path}' already exists. Overwrite it?");
|
||||||
"Directory '${projectDir.absolute.path}' already exists. Overwrite it? (Yes/No)");
|
|
||||||
|
|
||||||
if (await chooser.choose() != "Yes")
|
if (shouldDelete)
|
||||||
throw new Exception("Chose not to overwrite existing directory.");
|
throw new Exception("Chose not to overwrite existing directory.");
|
||||||
else if (projectDir.absolute.uri.normalizePath().toFilePath() !=
|
else if (projectDir.absolute.uri.normalizePath().toFilePath() !=
|
||||||
Directory.current.absolute.uri.normalizePath().toFilePath())
|
Directory.current.absolute.uri.normalizePath().toFilePath())
|
||||||
|
@ -129,10 +124,9 @@ class InitCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
print('Choose a project type before continuing:');
|
print('Choose a project type before continuing:');
|
||||||
var boilerplateChooser = new Chooser<BoilerplateInfo>(
|
|
||||||
argResults['legacy'] ? legacyBoilerplates : boilerplates,
|
var boilerplate = prompts.choose(
|
||||||
);
|
'Choose a project type before continuing', boilerplates);
|
||||||
var boilerplate = await boilerplateChooser.choose();
|
|
||||||
|
|
||||||
print(
|
print(
|
||||||
'Cloning "${boilerplate.name}" boilerplate from "${boilerplate.url}"...');
|
'Cloning "${boilerplate.name}" boilerplate from "${boilerplate.url}"...');
|
||||||
|
@ -157,13 +151,14 @@ class InitCommand extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (boilerplate.needsPrebuild) {
|
||||||
|
await preBuild(projectDir).catchError((_) => null);
|
||||||
|
}
|
||||||
|
|
||||||
var gitDir = new Directory.fromUri(projectDir.uri.resolve(".git"));
|
var gitDir = new Directory.fromUri(projectDir.uri.resolve(".git"));
|
||||||
if (await gitDir.exists()) await gitDir.delete(recursive: true);
|
if (await gitDir.exists()) await gitDir.delete(recursive: true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(red.wrap("$ballot Could not initialize Angel project."));
|
||||||
_pen.red();
|
|
||||||
_pen("${Icon.BALLOT_X} Could not initialize Angel project.");
|
|
||||||
_pen();
|
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,11 +175,11 @@ class InitCommand extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
preBuild(Directory projectDir) async {
|
Future preBuild(Directory projectDir) async {
|
||||||
// Run build
|
// Run build
|
||||||
print('Pre-building resources...');
|
print('Running `pub run build_runner build`...');
|
||||||
|
|
||||||
var build = await Process.start(Platform.executable, ['tool/build.dart'],
|
var build = await Process.start(resolvePub(), ['run', 'build'],
|
||||||
workingDirectory: projectDir.absolute.path);
|
workingDirectory: projectDir.absolute.path);
|
||||||
|
|
||||||
stdout.addStream(build.stdout);
|
stdout.addStream(build.stdout);
|
||||||
|
@ -195,31 +190,12 @@ preBuild(Directory projectDir) async {
|
||||||
if (buildCode != 0) throw new Exception('Failed to pre-build resources.');
|
if (buildCode != 0) throw new Exception('Failed to pre-build resources.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const BoilerplateInfo fullApplicationBoilerplate = const BoilerplateInfo(
|
|
||||||
'Full Application',
|
|
||||||
'A complete project including authentication, multi-threading, and more.',
|
|
||||||
'https://github.com/angel-dart/angel.git',
|
|
||||||
ref: '1.0.x',
|
|
||||||
);
|
|
||||||
|
|
||||||
const BoilerplateInfo lightBoilerplate = const BoilerplateInfo(
|
|
||||||
'Light',
|
|
||||||
'Minimal starting point for new users.',
|
|
||||||
'https://github.com/angel-dart/boilerplate_light.git',
|
|
||||||
);
|
|
||||||
|
|
||||||
const BoilerplateInfo ormBoilerplate = const BoilerplateInfo(
|
const BoilerplateInfo ormBoilerplate = const BoilerplateInfo(
|
||||||
'ORM',
|
'ORM',
|
||||||
"A starting point for applications that use Angel's ORM.",
|
"A starting point for applications that use Angel's ORM.",
|
||||||
'https://github.com/angel-dart/boilerplate_orm.git',
|
'https://github.com/angel-dart/boilerplate_orm.git',
|
||||||
);
|
);
|
||||||
|
|
||||||
const List<BoilerplateInfo> legacyBoilerplates = const [
|
|
||||||
fullApplicationBoilerplate,
|
|
||||||
lightBoilerplate,
|
|
||||||
ormBoilerplate
|
|
||||||
];
|
|
||||||
|
|
||||||
const BoilerplateInfo basicBoilerplate = const BoilerplateInfo(
|
const BoilerplateInfo basicBoilerplate = const BoilerplateInfo(
|
||||||
'Basic',
|
'Basic',
|
||||||
'Minimal starting point - A simple server with only a few additional packages.',
|
'Minimal starting point - A simple server with only a few additional packages.',
|
||||||
|
@ -233,8 +209,10 @@ const List<BoilerplateInfo> boilerplates = const [
|
||||||
|
|
||||||
class BoilerplateInfo {
|
class BoilerplateInfo {
|
||||||
final String name, description, url, ref;
|
final String name, description, url, ref;
|
||||||
|
final bool needsPrebuild;
|
||||||
|
|
||||||
const BoilerplateInfo(this.name, this.description, this.url, {this.ref});
|
const BoilerplateInfo(this.name, this.description, this.url,
|
||||||
|
{this.ref, this.needsPrebuild: false});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => '$name ($description)';
|
String toString() => '$name ($description)';
|
||||||
|
|
Loading…
Reference in a new issue