Skip to content

Commit

Permalink
Simplify #225
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Feb 19, 2019
1 parent 8a19e78 commit 7b8c87b
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions bref
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ use Symfony\Component\Process\Process;
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/../autoload.php')) {
/** @noinspection PhpIncludeInspection */
require_once __DIR__ . '/../autoload.php';
} else {
/** @noinspection PhpIncludeInspection */
require_once __DIR__ . '/../../autoload.php';
}

$app = new Silly\Application('Deploy serverless PHP applications');

$app->command('init', function (SymfonyStyle $io) {
$baseTemplateDir = __DIR__ . "/template";
$exeFinder = new ExecutableFinder();
if (! $exeFinder->find('sam')) {
$io->error(
Expand Down Expand Up @@ -67,37 +68,24 @@ $app->command('init', function (SymfonyStyle $io) {
][$choice];

$fs = new Filesystem;
$rootPath = "$baseTemplateDir/$templateDirectory";
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootPath));
foreach ($files as $file) {
/**
* @var RecursiveDirectoryIterator $dir
*/
$dir = $files->getInnerIterator();
$fileName = $dir->getSubPathname();
$srcFile = "$rootPath/$fileName";
if ($file->isFile() && $fs->exists($srcFile)) {
$io->writeln("Creating $fileName");
$fs->copy($srcFile, $fileName);
$rootPath = __DIR__ . "/template/$templateDirectory";
$filesToGitAdd = [];
foreach (scandir($rootPath, SCANDIR_SORT_NONE) as $file) {
if (in_array($file, ['.', '..'])) {
continue;
}
$io->writeln("Creating $file");
$fs->copy("$rootPath/$file", $file);
$filesToGitAdd[] = $file;
}

/*
* We check if this is a git repository to automatically add files to git.
*/
if ((new Process(['git', 'rev-parse', '--is-inside-work-tree']))->run() === 0) {
foreach ($files as $file) {
/**
* @var RecursiveDirectoryIterator $dir
*/
$dir = $files->getInnerIterator();
$fileName = $dir->getSubPathname();
$srcFile = "$rootPath/$fileName";
if ($file->isFile() && $fs->exists($srcFile)) {
(new Process(['git', 'add', $fileName]))->run();
}
foreach ($filesToGitAdd as $file) {
(new Process(['git', 'add', $file]))->run();
}

$io->success([
'Project initialized and ready to test or deploy.',
'The files created were automatically added to git.',
Expand Down

0 comments on commit 7b8c87b

Please sign in to comment.