Store boilerplates offline

This commit is contained in:
thosakwe 2019-07-17 11:56:52 -04:00
parent 0e63ee9e77
commit ecdfacce27
3 changed files with 69 additions and 49 deletions

View file

@ -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);

View file

@ -40,14 +40,14 @@ Future depend(Iterable<MakerDependency> 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<MakerDependency> deps) async {
printMissing('dependencies', missingDeps);
printMissing('dev_dependencies', missingDevDeps);
print('\n');
}
// if (isPresent) {

View file

@ -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<Pubspec> loadPubspec([Directory directory]) {
directory ??= Directory.current;
var file = new File.fromUri(directory.uri.resolve('pubspec.yaml'));
@ -21,6 +24,23 @@ Future<Pubspec> loadPubspec([Directory directory]) {
.then((yaml) => new Pubspec.parse(yaml, sourceUrl: file.uri));
}
// From: https://gist.github.com/tobischw/98dcd2563eec9a2a87bda8299055358a
Future<void> 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);