Skip to content

Commit

Permalink
Complete laravel setup
Browse files Browse the repository at this point in the history
  • Loading branch information
robbplo committed Dec 21, 2021
1 parent 55f9b96 commit fce451d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
8 changes: 4 additions & 4 deletions autopilot
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ use Symfony\Component\Console\Style\SymfonyStyle;
$io->title("Bit Academy Autopilot");

$io->writeln("Cloning repository...");
$repository = new Repository($input->getFirstArgument());
$repository->clone();
$repo = new Repository($input->getFirstArgument());
$repo->clone();

$driver = (new ProjectClassifier($repository))->selectDriver();
$driver = (new ProjectClassifier($repo))->selectDriver();
$type = (new ReflectionClass($driver))->getShortName();

$io->writeln("Identified project type: <options=bold>{$type}</>");

// @todo allow user to select program
$io->writeln('Opening text editor');
(new TextEditor("code"))->open($repository->getPath());
(new TextEditor("code"))->open($repo->dir()->getPath());

$driver->setUp();

Expand Down
31 changes: 25 additions & 6 deletions src/Drivers/LaravelDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ public function matches(): bool

public function setUp(): Driver
{
$this->installDependencies();
$this->createEnvFile();
$this->generateAppKey();
$this->createDatabase();
$this->setEnvDatabase();
$this->installDependencies();
$this->migrateAndSeed();

return $this;
}
Expand All @@ -30,27 +32,30 @@ public function serve(): Driver

public function getDatabaseName(): string
{
return basename($this->repository->dir()->getPath());
return "autopilot";
}

private function createDatabase(): void
{
// @todo this seems really unsafe :) maybe replace with db drivers
exec(sprintf('mysql -q --user=bit_academy --password=bit_academy -e "create database %s" > /dev/null 2>&1', $this->getDatabaseName()));
// @todo this seems really unsafe :) maybe replace with proper sql client
exec(sprintf(
'mysql -q --user=bit_academy --password=bit_academy -e "drop database if exists %s; create database %s" > /dev/null 2>&1',
$this->getDatabaseName(),
$this->getDatabaseName()
));
}

private function createEnvFile(): void
{
copy($this->repository->dir()->getPath('.env.example'), $this->repository->dir()->getPath('.env'));
exec('php artisan key:generate');
}

private function setEnvDatabase(): void
{
$path = $this->repository->dir()->getPath('.env');

$envFile = file_get_contents($path);
$envFile = str_replace('DB_DATABASE=', 'DB_DATABASE=' . $this->getDatabaseName(), $envFile);
$envFile = preg_replace("/DB_DATABASE=.+/", 'DB_DATABASE=' . $this->getDatabaseName(), $envFile);
file_put_contents($path, $envFile);
}

Expand All @@ -59,4 +64,18 @@ private function installDependencies(): void
$dir = $this->repository->dir()->getPath();
exec("composer install -q --working-dir=$dir");
}

private function migrateAndSeed(): void
{
$artisan = $this->repository->dir()->getPath('artisan');

exec("php {$artisan} migrate --seed");
}

private function generateAppKey(): void
{
$artisan = $this->repository->dir()->getPath('artisan');

passthru("php {$artisan} key:generate");
}
}
9 changes: 9 additions & 0 deletions src/Tasks/Task.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Autopilot\Tasks;

abstract class Task
{


}

0 comments on commit fce451d

Please sign in to comment.