diff --git a/lib/src/commands/init.dart b/lib/src/commands/init.dart index 2676c2cd..f3c3296a 100644 --- a/lib/src/commands/init.dart +++ b/lib/src/commands/init.dart @@ -30,8 +30,8 @@ class InitCommand extends Command { @override run() async { - Directory projectDir = new Directory( - argResults.rest.isEmpty ? "." : argResults.rest[0]); + Directory projectDir = + new Directory(argResults.rest.isEmpty ? "." : argResults.rest[0]); print("Creating new Angel project in ${projectDir.absolute.path}..."); await _cloneRepo(projectDir); // await preBuild(projectDir); @@ -136,52 +136,51 @@ class InitCommand extends Command { var boilerplate = prompts.choose( 'Choose a project type before continuing', boilerplates); - print( - 'Cloning "${boilerplate.name}" boilerplate from "${boilerplate.url}"...'); - - Process git; - - if (boilerplate.ref == null) { - git = await Process.start( - "git", - ["clone", "--depth", "1", boilerplate.url, projectDir.absolute.path], - mode: ProcessStartMode.inheritStdio, - ); - } else { - // git clone --single-branch -b branch host:/dir.git - git = await Process.start( - "git", - [ - "clone", - "--depth", - "1", - "--single-branch", - "-b", - boilerplate.ref, - boilerplate.url, - projectDir.absolute.path - ], - mode: ProcessStartMode.inheritStdio, - ); - } - - if (await git.exitCode != 0) { - throw new Exception("Could not clone repo."); - } - - /* - if (boilerplate.ref != null) { - git = await Process - .start("git", ["checkout", 'origin/${boilerplate.ref}']); - - stdout.addStream(git.stdout); - stderr.addStream(git.stderr); + // Ultimately, we want a clone of every boilerplate locally on the system. + var boilerplateRootDir = Directory(p.join(angelDir.path, 'boilerplates')); + var boilerplateDir = Directory(p.join(boilerplateRootDir.path, + p.basenameWithoutExtension(boilerplate.url))); + await boilerplateRootDir.create(recursive: true); + // If there is no clone existing, clone it. + if (!await boilerplateDir.exists()) { + print( + 'Cloning "${boilerplate.name}" boilerplate from "${boilerplate.url}"...'); + var git = await Process.start( + "git", + [ + "clone", + "--depth", + "1", + boilerplate.url, + boilerplateDir.absolute.path + ], + mode: ProcessStartMode.inheritStdio); if (await git.exitCode != 0) { - throw new Exception("Could not checkout branch ${boilerplate.ref}."); + throw new Exception("Could not clone repo."); } } - */ + + // Next, check out the given branch. + var branch = boilerplate.ref ?? 'master'; + var git = await Process.start("git", ["checkout", 'origin/$branch'], + mode: ProcessStartMode.inheritStdio, + workingDirectory: boilerplateDir.absolute.path); + if (await git.exitCode != 0) { + throw new Exception("Could not checkout branch $branch."); + } + + // Next, pull from git. + git = await Process.start("git", ["pull", 'origin/$branch'], + mode: ProcessStartMode.inheritStdio, + workingDirectory: boilerplateDir.absolute.path); + if (await git.exitCode != 0) { + throw new Exception( + "Update of $branch failed. Attempting to continue with existing contents."); + } + + // Next, just copy everything into the given directory. + await copyDirectory(boilerplateDir, projectDir); if (boilerplate.needsPrebuild) { await preBuild(projectDir).catchError((_) => null); diff --git a/lib/src/commands/make/maker.dart b/lib/src/commands/make/maker.dart index 38c57121..09bf1bd9 100644 --- a/lib/src/commands/make/maker.dart +++ b/lib/src/commands/make/maker.dart @@ -40,14 +40,14 @@ Future depend(Iterable deps) async { } } - var missingDeps = deps.where((d) => !d.dev).toList()..sort(); - var missingDevDeps = deps.where((d) => d.dev).toList()..sort(); + var missingDeps = missing.where((d) => !d.dev).toList()..sort(); + var missingDevDeps = missing.where((d) => d.dev).toList()..sort(); + var totalCount = missingDeps.length + missingDevDeps.length; - if (missingDeps.isNotEmpty || missingDevDeps.isNotEmpty) { - var totalCount = missingDeps.length + missingDevDeps.length; + if (totalCount > 0) { print(yellow.wrap(totalCount == 1 ? 'You are missing one dependency.' - : 'You are missing ${missing.length} dependencies.')); + : 'You are missing $totalCount dependencies.')); print(yellow.wrap( 'Update your `pubspec.yaml` to add the following dependencies:\n')); @@ -62,6 +62,7 @@ Future depend(Iterable deps) async { printMissing('dependencies', missingDeps); printMissing('dev_dependencies', missingDevDeps); + print('\n'); } // if (isPresent) { diff --git a/lib/src/util.dart b/lib/src/util.dart index 46d48fd0..e57e41f3 100644 --- a/lib/src/util.dart +++ b/lib/src/util.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:io'; import 'package:io/ansi.dart'; +import 'package:path/path.dart' as p; import 'package:pubspec_parse/pubspec_parse.dart'; //import 'package:yamlicious/yamlicious.dart'; @@ -13,6 +14,8 @@ String get homeDirPath => Directory get homeDir => new Directory(homeDirPath); +Directory get angelDir => Directory(p.join(homeDir.path, '.angel')); + Future loadPubspec([Directory directory]) { directory ??= Directory.current; var file = new File.fromUri(directory.uri.resolve('pubspec.yaml')); @@ -21,6 +24,23 @@ Future loadPubspec([Directory directory]) { .then((yaml) => new Pubspec.parse(yaml, sourceUrl: file.uri)); } +// From: https://gist.github.com/tobischw/98dcd2563eec9a2a87bda8299055358a +Future copyDirectory(Directory source, Directory destination) async { + await for (var entity in source.list(recursive: false)) { + if (entity is Directory) { + var newDirectory = + Directory(p.join(destination.absolute.path, p.basename(entity.path))); + print('Copying dir "${entity.path}" -> "${newDirectory.path}..."'); + await newDirectory.create(); + await copyDirectory(entity.absolute, newDirectory); + } else if (entity is File) { + var newPath = p.join(destination.path, p.basename(entity.path)); + print('Copying file "${entity.path}" -> "$newPath"'); + await entity.copy(newPath); + } + } +} + Future savePubspec(Pubspec pubspec) async { // TODO: Save pubspec for real? //var text = toYamlString(pubspec);