Skip to content

Commit

Permalink
Merge branch 'release/v0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
joeworkman committed Dec 22, 2021
2 parents 7213538 + 40afb93 commit 4810fd0
Show file tree
Hide file tree
Showing 27 changed files with 2,085 additions and 126 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/node_modules
/vendor
/.idea
/.vscode
/.vagrant
.phpunit.result.cache

/sample/dist
/.proton-cache
/sample-dist
/.proton-cache
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ This project is meant to replace the popular [panini](https://github.com/foundat

```
This project is in beta. Any feedback would be appreciated.
PLEASE DO NOT USE THIS FOR PRODUCTION PROJECTS.
```

## Documentation
Expand Down
59 changes: 7 additions & 52 deletions app/Commands/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
class Build extends Command
{
// The signature of the command.
protected $signature = 'build';
protected $signature = 'build
{--clean : Clean previous build (optional)}';

// The description of the command.
protected $description = 'Build all pages';
Expand All @@ -20,58 +22,11 @@ class Build extends Command
public function handle()
{
//----------------------------------
// Config Load
//----------------------------------
$config = new \App\Proton\Config();
if ($config->settings->debug) {
$this->info('Configuration:');
$config->dump();
}

//----------------------------------
// Clear out dist files
//----------------------------------
$fsManager = new \App\Proton\FilesystemManager($config);
if (!$fsManager->pathsExist()) {
$this->error('Not all required paths exist to build site. You can run `proton init` to ensure everything is setup.');
return;
}
$this->info('Cleaning previous builds');
$fsManager->cleanupDist();

//----------------------------------
// Load in Data
//----------------------------------
$this->info('Loading data');
$data = new \App\Proton\Data($config);

if ($config->settings->debug) {
$this->info('Collected Data:');
$data->dump();
}

//----------------------------------
// Process all pages
//----------------------------------
$this->info('Compiling Pages');
$pageManger = new \App\Proton\PageManager($config, $data);
$pageManger->compilePages();

//----------------------------------
// Create Sitemap
//----------------------------------
if ($config->settings->sitemap) {
$this->info('Building Sitemap');
$sitemap = new \App\Proton\Sitemap($config);
$sitemap->write();
}

//----------------------------------
// Copy Assets
// Build
//----------------------------------
$this->info('Copying Assets');
$assetManger = new \App\Proton\AssetManager($config);
$assetManger->copyAssets();
$builder = new \App\Proton\Builder($this);
$builder->clean(boolval($this->option('clean')));
$builder->build();

$this->info('Build Complete');
}
Expand Down
21 changes: 19 additions & 2 deletions app/Commands/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Commands;

use LaravelZero\Framework\Commands\Command;
use App\Proton\FilesystemManager;
use App\Proton\TerminalCommand;

class Init extends Command
{
Expand All @@ -13,7 +15,8 @@ class Init extends Command
*/
protected $signature = 'init
{--config : Init a config file with default values (optional)}';
{--config : Init a config file with default values (optional)}
{--template= : Clone a Proton template via `sites` or Github *.git URL (optional)}';

/**
* The description of the command.
Expand All @@ -31,6 +34,20 @@ public function handle()
{
$config = new \App\Proton\Config();

if ($this->option('template')) {
$clone = \App\Proton\Config::SITES_TEMPLATE;
if ($this->option('template') !== "sites") {
$clone = strval($this->option('template'));
}
if (preg_match("/^http\S+git$/", $clone)) {
$this->info("Cloning $clone");
$command = "git clone $clone .";
$process = new TerminalCommand($command);
$process->start();
FilesystemManager::rm_rf(".git");
}
}

// Create config file
if ($this->option('config')) {
$this->info('Initiating Proton config');
Expand All @@ -42,7 +59,7 @@ public function handle()
}

// Setup Folders
$fsManager = new \App\Proton\FilesystemManager($config);
$fsManager = new FilesystemManager($config);
$this->info('Initiating Proton Folders');
$fsManager->initPaths();
$this->info('Folders Created:');
Expand Down
36 changes: 36 additions & 0 deletions app/Commands/Watch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Commands;

use LaravelZero\Framework\Commands\Command;

class Watch extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'watch';

/**
* The description of the command.
*
* @var string
*/
protected $description = 'Watch the template folders for changes and rebuild';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//----------------------------------
// Watch
//----------------------------------
$watcher = new \App\Proton\Watcher($this);
$watcher->watch();
}
}
53 changes: 53 additions & 0 deletions app/Proton/BrowserSyncServer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Proton;

use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\Process;

//---------------------------------------------------------------------------------
// Proton BrowserSyncServer
//---------------------------------------------------------------------------------
class BrowserSyncServer implements ProcessInterface
{
public string $path;
public Process $process;

public function __construct(string $path)
{
$this->path = $path;

$command = [
(new ExecutableFinder)->find('node'),
realpath(__DIR__ . '/../bin/browser-sync.js'),
$this->path,
];
$this->process = new Process(
command: $command,
timeout: null,
);
}

public function stop(): void
{
$this->process->stop();
}

public function start(): void
{
$this->process->start();

if (! $this->process->isRunning()) {
throw new \Exception("Could not start server. Make sure you have required browser-sync. Error output: " . $this->process->getErrorOutput());
}

$this->process->waitUntil(function ($type, $buffer) {
if (Process::ERR === $type) {
echo 'ERR:'.$buffer;
} else {
echo $buffer;
}
return false !== strpos($buffer, 'Watching files');
});
}
}
93 changes: 93 additions & 0 deletions app/Proton/Builder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace App\Proton;

use LaravelZero\Framework\Commands\Command;

//---------------------------------------------------------------------------------
// Proton Builder
//---------------------------------------------------------------------------------
class Builder
{
protected Config $config;
protected Data $data;
protected AssetManager $assetManager;
protected FilesystemManager $fsManager;
protected PageManager $pageManager;
protected Command $cmd;

public function __construct(Command $cmd)
{
$this->cmd = $cmd;
$this->config = new Config();

$this->fsManager = new FilesystemManager($this->config);
$this->fsManager->pathChecker();

$data = new Data($this->config);
$this->pageManager = new PageManager($this->config, $data);
$this->assetManager = new AssetManager($this->config);
}

public function build(): void
{
if ($this->config->settings->debug) {
$this->cmd->info('Configuration:');
$this->config->dump();
$this->cmd->info('Collected Data:');
$this->data->dump();
}
$this->compilePages();
$this->buildSitemap();
$this->copyAssets();
$this->runNPMBuild();
}

public function runNPMBuild(): void
{
$command = $this->config->settings->npmBuild;
if ($command) {
$this->cmd->info("Running NPM Build: $command");
$process = new TerminalCommand($command);
$process->start();
}
}

public function buildSitemap(): void
{
if ($this->config->settings->sitemap) {
$this->cmd->info('Building Sitemap');
$sitemap = new \App\Proton\Sitemap($this->config);
$sitemap->write();
}
}

public function clean(bool $clean=false): void
{
if ($clean) {
$this->cmd->info('Cleaning previous builds');
$this->fsManager->cleanupDist();
}
$this->fsManager->clearCache();
}

public function copyAssets(): void
{
$this->cmd->info('Copying Assets');
$this->assetManager->copyAssets();
}

public function compilePages(): void
{
$this->cmd->info('Compiling Pages');
$this->pageManager->compilePages();
}

public function refreshData(): void
{
$this->cmd->info("Refreshing Data");
$this->pageManager->refreshData();
$this->cmd->info("Recompiling All Pages");
$this->pageManager->compilePages();
}
}
4 changes: 4 additions & 0 deletions app/Proton/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//---------------------------------------------------------------------------------
class Config
{
const SITES_TEMPLATE = "https://github.com/foundation/proton-sites-template.git";
const CONFIGFILES = [
"proton.yml",
".proton.yml",
Expand All @@ -21,6 +22,8 @@ class Config
"pretty" => true,
"minify" => false,
"sitemap" => true,
"npmBuild" => "yarn build",
"devserver" => "browsersync",
"layouts" => [
"default" => "default.html",
"rules" => [
Expand All @@ -35,6 +38,7 @@ class Config
"macros" => "src/macros",
"pages" => "src/pages",
"partials" => "src/partials",
"watch" => "src",
],
];

Expand Down
6 changes: 6 additions & 0 deletions app/Proton/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public function dump(): void
print_r($this->data);
}

public function refresh(): void
{
$this->data = [];
$this->initDataFiles();
}

private function initDataFiles(): void
{
$directory = new \RecursiveDirectoryIterator($this->dir);
Expand Down
Loading

0 comments on commit 4810fd0

Please sign in to comment.