Store boilerplates offline
This commit is contained in:
parent
0e63ee9e77
commit
ecdfacce27
3 changed files with 69 additions and 49 deletions
|
@ -30,8 +30,8 @@ class InitCommand extends Command {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
run() async {
|
run() async {
|
||||||
Directory projectDir = new Directory(
|
Directory projectDir =
|
||||||
argResults.rest.isEmpty ? "." : argResults.rest[0]);
|
new Directory(argResults.rest.isEmpty ? "." : argResults.rest[0]);
|
||||||
print("Creating new Angel project in ${projectDir.absolute.path}...");
|
print("Creating new Angel project in ${projectDir.absolute.path}...");
|
||||||
await _cloneRepo(projectDir);
|
await _cloneRepo(projectDir);
|
||||||
// await preBuild(projectDir);
|
// await preBuild(projectDir);
|
||||||
|
@ -136,52 +136,51 @@ class InitCommand extends Command {
|
||||||
var boilerplate = prompts.choose(
|
var boilerplate = prompts.choose(
|
||||||
'Choose a project type before continuing', boilerplates);
|
'Choose a project type before continuing', boilerplates);
|
||||||
|
|
||||||
|
// 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(
|
print(
|
||||||
'Cloning "${boilerplate.name}" boilerplate from "${boilerplate.url}"...');
|
'Cloning "${boilerplate.name}" boilerplate from "${boilerplate.url}"...');
|
||||||
|
var git = await Process.start(
|
||||||
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",
|
"git",
|
||||||
[
|
[
|
||||||
"clone",
|
"clone",
|
||||||
"--depth",
|
"--depth",
|
||||||
"1",
|
"1",
|
||||||
"--single-branch",
|
|
||||||
"-b",
|
|
||||||
boilerplate.ref,
|
|
||||||
boilerplate.url,
|
boilerplate.url,
|
||||||
projectDir.absolute.path
|
boilerplateDir.absolute.path
|
||||||
],
|
],
|
||||||
mode: ProcessStartMode.inheritStdio,
|
mode: ProcessStartMode.inheritStdio);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await git.exitCode != 0) {
|
if (await git.exitCode != 0) {
|
||||||
throw new Exception("Could not clone repo.");
|
throw new Exception("Could not clone repo.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
// Next, check out the given branch.
|
||||||
if (boilerplate.ref != null) {
|
var branch = boilerplate.ref ?? 'master';
|
||||||
git = await Process
|
var git = await Process.start("git", ["checkout", 'origin/$branch'],
|
||||||
.start("git", ["checkout", 'origin/${boilerplate.ref}']);
|
mode: ProcessStartMode.inheritStdio,
|
||||||
|
workingDirectory: boilerplateDir.absolute.path);
|
||||||
stdout.addStream(git.stdout);
|
|
||||||
stderr.addStream(git.stderr);
|
|
||||||
|
|
||||||
if (await git.exitCode != 0) {
|
if (await git.exitCode != 0) {
|
||||||
throw new Exception("Could not checkout branch ${boilerplate.ref}.");
|
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) {
|
if (boilerplate.needsPrebuild) {
|
||||||
await preBuild(projectDir).catchError((_) => null);
|
await preBuild(projectDir).catchError((_) => null);
|
||||||
|
|
|
@ -40,14 +40,14 @@ Future depend(Iterable<MakerDependency> deps) async {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var missingDeps = deps.where((d) => !d.dev).toList()..sort();
|
var missingDeps = missing.where((d) => !d.dev).toList()..sort();
|
||||||
var missingDevDeps = deps.where((d) => d.dev).toList()..sort();
|
var missingDevDeps = missing.where((d) => d.dev).toList()..sort();
|
||||||
|
|
||||||
if (missingDeps.isNotEmpty || missingDevDeps.isNotEmpty) {
|
|
||||||
var totalCount = missingDeps.length + missingDevDeps.length;
|
var totalCount = missingDeps.length + missingDevDeps.length;
|
||||||
|
|
||||||
|
if (totalCount > 0) {
|
||||||
print(yellow.wrap(totalCount == 1
|
print(yellow.wrap(totalCount == 1
|
||||||
? 'You are missing one dependency.'
|
? 'You are missing one dependency.'
|
||||||
: 'You are missing ${missing.length} dependencies.'));
|
: 'You are missing $totalCount dependencies.'));
|
||||||
print(yellow.wrap(
|
print(yellow.wrap(
|
||||||
'Update your `pubspec.yaml` to add the following dependencies:\n'));
|
'Update your `pubspec.yaml` to add the following dependencies:\n'));
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ Future depend(Iterable<MakerDependency> deps) async {
|
||||||
|
|
||||||
printMissing('dependencies', missingDeps);
|
printMissing('dependencies', missingDeps);
|
||||||
printMissing('dev_dependencies', missingDevDeps);
|
printMissing('dev_dependencies', missingDevDeps);
|
||||||
|
print('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (isPresent) {
|
// if (isPresent) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:io/ansi.dart';
|
import 'package:io/ansi.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
import 'package:pubspec_parse/pubspec_parse.dart';
|
import 'package:pubspec_parse/pubspec_parse.dart';
|
||||||
//import 'package:yamlicious/yamlicious.dart';
|
//import 'package:yamlicious/yamlicious.dart';
|
||||||
|
|
||||||
|
@ -13,6 +14,8 @@ String get homeDirPath =>
|
||||||
|
|
||||||
Directory get homeDir => new Directory(homeDirPath);
|
Directory get homeDir => new Directory(homeDirPath);
|
||||||
|
|
||||||
|
Directory get angelDir => Directory(p.join(homeDir.path, '.angel'));
|
||||||
|
|
||||||
Future<Pubspec> loadPubspec([Directory directory]) {
|
Future<Pubspec> loadPubspec([Directory directory]) {
|
||||||
directory ??= Directory.current;
|
directory ??= Directory.current;
|
||||||
var file = new File.fromUri(directory.uri.resolve('pubspec.yaml'));
|
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));
|
.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 {
|
Future savePubspec(Pubspec pubspec) async {
|
||||||
// TODO: Save pubspec for real?
|
// TODO: Save pubspec for real?
|
||||||
//var text = toYamlString(pubspec);
|
//var text = toYamlString(pubspec);
|
||||||
|
|
Loading…
Reference in a new issue