Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #13 from mateusjunges/junges-patch-1
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
ajthinking authored Jun 10, 2019
2 parents 7a7ece3 + b5768ab commit 8cd81d1
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 67 deletions.
3 changes: 2 additions & 1 deletion src/Commands/DumpAutoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DumpAutoload extends Command
* Create a new command instance.
*
* @param Composer $composer
*
* @return void
*/
public function __construct(Composer $composer)
Expand All @@ -54,4 +55,4 @@ public function handle()
$this->composer->dumpOptimized()
);
}
}
}
33 changes: 16 additions & 17 deletions src/Controllers/PipeDreamAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace PipeDream\Laravel\Controllers;

use Artisan;
use File;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use File;
use Illuminate\Routing\Controller as BaseController;
use PipeDream\Laravel\ProjectFileManager;
use Artisan;

class PipeDreamAPIController extends BaseController
{
Expand All @@ -21,17 +21,16 @@ public function __construct()

public function templates()
{

return $this->getTemplates();
}

public function scripts()
{
return [
"migrate",
"seed"
'migrate',
'seed',
];
}
}

public function build()
{
Expand All @@ -40,7 +39,7 @@ public function build()

// Optionally reverse the previous design iteration
// This is useful to remove previous mistakes and timestamp conflicts
$this->args->reverseHistory? $this->project->reverseHistory() : null;
$this->args->reverseHistory ? $this->project->reverseHistory() : null;

// Write the files generated
$this->project->write($this->args->reviewFiles);
Expand All @@ -54,12 +53,10 @@ public function build()
// Ensure migrations are autoloaded
exec('cd .. && composer dumpautoload');
// whats wrong with this package command??!!
//Artisan::call('dump-autoload');


//Artisan::call('dump-autoload');

return response([
"message" => "Successfully stored files!"
'message' => 'Successfully stored files!',
], 200);
}

Expand All @@ -70,7 +67,8 @@ private function setupProjectEnvironment()
);
}

private function deleteDefaultMigrations() {
private function deleteDefaultMigrations()
{
$this->project->delete(json_decode('
[
{
Expand All @@ -82,17 +80,18 @@ private function deleteDefaultMigrations() {
]
'));
}

private function pathToFileName($path)
{
return substr($path, strrpos($path, '/') + 1);
}

private function getTemplates()
{
return collect(glob(__DIR__ . '/../templates/*'))->reduce(function($allFiles, $path) {
return collect(glob(__DIR__.'/../templates/*'))->reduce(function ($allFiles, $path) {
$allFiles[$this->pathToFileName($path)] = File::get($path);

return $allFiles;
}, collect([]));
}
}
}
12 changes: 6 additions & 6 deletions src/Controllers/PipeDreamWebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public function index()
PipeDreamServiceProvider::publishAssets();

return view('pipe-dream::spa')->with([
"settings" => [
"isSandboxed" => env('PIPEDREAM_IS_SANDBOXED', false),
"appName" => request()->path()
]
]);
'settings' => [
'isSandboxed' => env('PIPEDREAM_IS_SANDBOXED', false),
'appName' => request()->path(),
],
]);
}
}
}
30 changes: 15 additions & 15 deletions src/PipeDreamServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace PipeDream\Laravel;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Collection;
use PipeDream\Laravel\Commands\DumpAutoload;

class PipeDreamServiceProvider extends ServiceProvider
Expand All @@ -16,7 +15,7 @@ class PipeDreamServiceProvider extends ServiceProvider
public function register()
{
$this->commands([
DumpAutoload::class
DumpAutoload::class,
]);
}

Expand All @@ -38,33 +37,34 @@ public function boot()
* So resorting to do it every new page load
* Please fix this
*/
public static function publishAssets() {
public static function publishAssets()
{
\File::copyDirectory(
__DIR__ . '/public',
__DIR__.'/public',
public_path('vendor/pipe-dream/laravel')
);

\File::copy(
__DIR__ . '/../data/dataTypeGithubDump.js',
__DIR__.'/../data/dataTypeGithubDump.js',
public_path('vendor/pipe-dream/laravel/data/github.js')
);
);
}

private function registerStorages()
{
$this->app['config']["filesystems.disks.self"] = [
$this->app['config']['filesystems.disks.self'] = [
'driver' => 'local',
'root' => base_path(),
'root' => base_path(),
];

$this->app['config']["filesystems.disks.pipe-dream"] = [
$this->app['config']['filesystems.disks.pipe-dream'] = [
'driver' => 'local',
'root' => storage_path('pipe-dream'),
'root' => storage_path('pipe-dream'),
];
$this->app['config']["filesystems.disks.pipe-dream.sandbox"] = [

$this->app['config']['filesystems.disks.pipe-dream.sandbox'] = [
'driver' => 'local',
'root' => storage_path('pipe-dream/sandbox'),
];
'root' => storage_path('pipe-dream/sandbox'),
];
}
}
46 changes: 24 additions & 22 deletions src/ProjectFileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

namespace PipeDream\Laravel;

use stdClass;
use Storage;
use File;
use Storage;

class ProjectFileManager {
class ProjectFileManager
{
public function __construct($isSandboxed)
{
$this->isSandboxed = $isSandboxed;
if($this->isSandboxed) $this->setupSandboxProject();
if ($this->isSandboxed) {
$this->setupSandboxProject();
}
$this->history = [];
}

Expand All @@ -23,27 +25,27 @@ public function write($files)
{
$this->recordCurrentStateFor($files);

collect($files)->each(function($file) {
collect($files)->each(function ($file) {
$this->storage()->put($file->path, $file->content);
});
});
}

public function delete($files)
{
$this->recordCurrentStateFor($files);

collect($files)->each(function($file) {
collect($files)->each(function ($file) {
$this->storage()->delete($file->path);
});
}
});
}

public function reverseHistory()
{
collect($this->loadHistory())->each(function($content, $path) {
if($content == null) {
collect($this->loadHistory())->each(function ($content, $path) {
if ($content == null) {
return $this->storage()->delete($path);
}

$this->storage()->put($path, $content);
});
}
Expand All @@ -59,15 +61,15 @@ public function persistHistory()
/*********** PRIVATE ************************************************** */
private function setupSandboxProject()
{
app()['config']["filesystems.disks.pipe-dream-sandbox-project"] = [
app()['config']['filesystems.disks.pipe-dream-sandbox-project'] = [
'driver' => 'local',
'root' => storage_path("pipe-dream/sandbox/test-project"),
];
if(!Storage::disk('pipe-dream')->exists('sandbox/test-project')) {
'root' => storage_path('pipe-dream/sandbox/test-project'),
];

if (!Storage::disk('pipe-dream')->exists('sandbox/test-project')) {
File::copyDirectory(
storage_path('pipe-dream/laravel-including-vendors'),
storage_path("pipe-dream/sandbox/test-project")
storage_path('pipe-dream/sandbox/test-project')
);
}
}
Expand All @@ -81,17 +83,17 @@ private function loadHistory()
private function storage()
{
return Storage::disk(
$this->isSandboxed ? "pipe-dream-sandbox-project" : 'self'
$this->isSandboxed ? 'pipe-dream-sandbox-project' : 'self'
);
}

private function recordCurrentStateFor($files)
{
collect($files)->each(function($file) {
$this->history[$file->path] =
collect($files)->each(function ($file) {
$this->history[$file->path] =
$this->storage()->has($file->path) ?
$this->storage()->get($file->path) :
null;
});
}
}
}
11 changes: 5 additions & 6 deletions src/routes/routes.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
<?php


Route::get('/pipe-dream', '\PipeDream\Laravel\Controllers\PipeDreamWebController@index');
Route::get('/pipe-dream/test', function() {
Route::get('/pipe-dream/test', function () {
return \Artisan::call('dump-autoload');
});


Route::prefix('pipe-dream/api')->group(function () {
Route::post('/build', '\PipeDream\Laravel\Controllers\PipeDreamAPIController@build');
Route::post('/build', '\PipeDream\Laravel\Controllers\PipeDreamAPIController@build');
Route::get('/scripts', '\PipeDream\Laravel\Controllers\PipeDreamAPIController@scripts');
Route::get('/templates', '\PipeDream\Laravel\Controllers\PipeDreamAPIController@templates');

});
});

0 comments on commit 8cd81d1

Please sign in to comment.