Skip to content

Commit

Permalink
feat: add option to directly download and install the new rockfronten…
Browse files Browse the repository at this point in the history
…d site profile
  • Loading branch information
BernhardBaumrock committed Mar 16, 2024
1 parent 4ce3253 commit b4389da
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
2 changes: 2 additions & 0 deletions App/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ public function trailingSlash($path)
public function wire()
{
if ($this->wire) return $this->wire;
if ($this->wire === false) return;
chdir($this->app->rootPath());

// pw is not yet there, eg when using pw:install
Expand All @@ -433,6 +434,7 @@ public function wire()
// pw is here but not installed
if (is_file("install.php")) {
$this->alert("ProcessWire exists but is not installed");
$this->wire = false;
return false;
}

Expand Down
40 changes: 27 additions & 13 deletions App/Commands/PwInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public function handle()

/** ##### steps ##### */

public function nextStep($reload = false)
public function nextStep($reload = false, $noConfirm = false)
{
$this->stepCount = $this->stepCount + 1;
if ($this->stepCount > 30) return; // hard limit to prevent endless loops
if ($this->stepCount > 50) return; // hard limit to prevent endless loops

// if a reload is required we fire another request
if ($reload) $this->browser->request('GET', $this->host('install.php'));
Expand Down Expand Up @@ -90,7 +90,7 @@ public function nextStep($reload = false)
// next step?
// if the last step returned false we break
if ($next !== false) {
if ($this->skipNextConfirm) return $this->nextStep();
if ($this->skipNextConfirm || $noConfirm) return $this->nextStep();
if ($this->confirm("Continue to next step?", true)) return $this->nextStep();
}
}
Expand All @@ -103,14 +103,28 @@ public function stepWelcome()

public function stepProfile()
{
$this->write("Installing profile...");
// offer to download the rockfrontend site profile
$zip = 'https://github.com/baumrock/site-rockfrontend/archive/refs/heads/main.zip';
$exists = is_dir("site-rockfrontend-main");
if (!$exists && $this->confirm("Download Site-Profile \"RockFrontend + UIkit + TailwindCSS\" from $zip?")) {
if (!file_exists('main.zip')) {
$this->exec("wget $zip");
}
$this->write("Site Profile already exists");
$this->write('Extracting files ...');
$this->exec('unzip -q main.zip');
$this->nextStep(true, true);
return;
}

$this->write("Install site profile ...");

$profiles = $this->browser
->getCrawler()
->filter('select[name=profile] > option')
->extract(['value']);
if (!count($profiles)) {
$this->error("No profiles found - aborting...");
$this->error("No profiles found - aborting ...");
die();
}
$profiles = array_values(array_filter($profiles));
Expand All @@ -121,15 +135,15 @@ public function stepProfile()
$profiles[0]
);
}
$this->write("Using profile $profile...");
$this->write("Using profile $profile ...");
$this->browser->submitForm("Continue", [
'profile' => $profile,
]);
}

public function stepCompatibility()
{
$this->write("Checking compatibility...");
$this->write("Checking compatibility ...");
$errors = 0;
$this->browser
->getCrawler()
Expand All @@ -153,7 +167,7 @@ public function stepCompatibility()
$this->skipNextConfirm = true;
$this->browser->submitForm('Continue to Next Step');
} else {
$this->warn('Aborting...');
$this->warn('Aborting ...');
die();
}
}
Expand Down Expand Up @@ -196,7 +210,7 @@ public function stepAdmin()

public function stepFinish()
{
$this->success("Finishing installation...");
$this->success("Finishing installation ...");
$this->writeNotes();
return $this->stepReloadAdmin();
}
Expand All @@ -219,7 +233,7 @@ public function stepReloadAdmin($notice = true)
$this->write($el->text());
});
if ($notices) {
$this->warn("Reloading...");
$this->warn("Reloading ...");
return $this->stepReloadAdmin(false);
} else {
$this->success("\n"
Expand Down Expand Up @@ -387,7 +401,7 @@ public function getStep()
$this->write('No ProcessWire Installer found');
if (is_file($this->app->rootPath() . "index.php")) {
$this->write("");
$this->error("Found index.php - aborting...");
$this->error("Found index.php - aborting ...");
$this->write("");
die();
}
Expand All @@ -402,7 +416,7 @@ public function getStep()

return $this->nextStep(true);
}
$this->warn("Aborting...");
$this->warn("Aborting ...");
die();
}

Expand Down Expand Up @@ -440,7 +454,7 @@ public function host($site)
$status = $this->browser->getInternalResponse()->getStatusCode();
if ($status !== 404) {
$this->error("Your host $host must be reachable via HTTP!");
$this->error("When using DDEV make sure it is running...");
$this->error("When using DDEV make sure it is running ");
exit(1);
} else {
$this->success("HTTP status check for host $host was OK");
Expand Down

0 comments on commit b4389da

Please sign in to comment.