Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/pr-welcome.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: PR Welcome & Assign

on:
pull_request:
types: [opened]

jobs:
welcome-and-assign:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- name: Get PR Author
id: pr_author
run: echo "AUTHOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV

- name: 'Auto-assign issue'
uses: pozil/auto-assign-issue@39c06395cbac76e79afc4ad4e5c5c6db6ecfdd2e
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
assignees: HichemTab-tech
numOfAssignee: 1

- name: Comment on PR (if not the maintainer)
#if: env.AUTHOR != 'HichemTab-tech'
uses: actions/github-script@v6
with:
script: |
github.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "Thank you @${{ env.AUTHOR }} for your contribution! 🎉\n\nYour PR has been received and is awaiting review. Please be patient while we check it. 🚀"
});
5 changes: 4 additions & 1 deletion bin/laravelfs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ if (file_exists(__DIR__.'/../../../autoload.php')) {
}

// Define our own version and the Laravel Installer version we aim to match.
$laravelFSVersion = '1.0.0';
$laravelFSVersion = '2.0.0';
$laravelInstallerVersion = '5.13.0';

// Compose the displayed version string.
$displayVersion = sprintf('%s (advanced from Laravel Installer %s)', $laravelFSVersion, $laravelInstallerVersion);

$app = new Symfony\Component\Console\Application('LaravelFS Installer', $displayVersion);
$app->add(new HichemTabTech\LaravelFS\Console\NewCommand);
$app->add(new HichemTabTech\LaravelFS\Console\NewTemplateCommand);
$app->add(new HichemTabTech\LaravelFS\Console\ShowTemplatesCommand);
$app->add(new HichemTabTech\LaravelFS\Console\UseTemplateCommand);

/** @noinspection PhpUnhandledExceptionInspection */
$app->run();
162 changes: 162 additions & 0 deletions src/Concerns/CommandsUtils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?php

namespace HichemTabTech\LaravelFS\Console\Concerns;

use Illuminate\Support\ProcessUtils;
use Illuminate\Support\Str;
use RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
use function Illuminate\Support\php_binary;
use function Laravel\Prompts\error;

trait CommandsUtils
{

private function getGlobalTemplatesPath(): string
{
// Determine OS-specific config directory
if (windows_os()) {
$configDir = (getenv('APPDATA') ?: $_SERVER['APPDATA']) . '\laravelfs';
} else {
$configDir = (getenv('XDG_CONFIG_HOME') ?: $_SERVER['HOME']) . '\.config\laravelfs';
}

return $configDir . '\templates.json';
}

private function getSavedTemplates(bool $noInteract = false): array
{
// Get the global templates path
$configPath = $this->getGlobalTemplatesPath();
$noTemplates = false;

// Check if the template file exists
if (!file_exists($configPath)) {
$noTemplates = true;
}

if (!$noTemplates) {
// Load the templates
$templatesConfig = json_decode(file_get_contents($configPath), true);
$templates = [];

if (empty($templatesConfig)) {
$noTemplates = true;
}
elseif (empty($templatesConfig['templates'])) {
$noTemplates = true;
}
else {
$templates = $templatesConfig['templates'];
}

}

if ($noTemplates) {
if (!$noInteract) {
error('No templates found. Create one using `laravelfs template:new <template-name>`');
}
return [
'templates' => [],
'path' => $configPath,
];
}

return [
'templates' => $templates,
'path' => $configPath,
];
}

/**
* Get the path to the appropriate PHP binary.
*
* @return string
*/
protected function phpBinary(): string
{
$phpBinary = function_exists('Illuminate\Support\php_binary')
? php_binary()
: (new PhpExecutableFinder)->find(false);

return $phpBinary !== false
? ProcessUtils::escapeArgument($phpBinary)
: 'php';
}

/**
* Run the given commands.
*
* @param array $commands
* @param InputInterface $input
* @param OutputInterface $output
* @param string|null $workingPath
* @param array $env
* @return Process
*/
protected function runCommands(array $commands, InputInterface $input, OutputInterface $output, ?string $workingPath = null, array $env = []): Process
{
if (!$output->isDecorated()) {
$commands = array_map(function ($value) {
if (Str::startsWith($value, ['chmod', 'git', $this->phpBinary().' ./vendor/bin/pest'])) {
return $value;
}

return $value.' --no-ansi';
}, $commands);
}

if ($input->getOption('quiet')) {
$commands = array_map(function ($value) {
if (Str::startsWith($value, ['chmod', 'git', $this->phpBinary().' ./vendor/bin/pest'])) {
return $value;
}

return $value.' --quiet';
}, $commands);
}

$process = Process::fromShellCommandline(implode(' && ', $commands), $workingPath, $env, null, null);

if ('\\' !== DIRECTORY_SEPARATOR AND file_exists('/dev/tty') AND is_readable('/dev/tty')) {
try {
$process->setTty(true);
} catch (RuntimeException $e) {
$output->writeln(' <bg=yellow;fg=black> WARN </> '.$e->getMessage().PHP_EOL);
}
}

$process->run(function ($type, $line) use ($output) {
$output->write(' '.$line);
});

return $process;
}

/**
* Get the installation directory.
*
* @param string $name
* @return string
*/
protected function getInstallationDirectory(string $name): string
{
return $name !== '.' ? getcwd().'/'.$name : '.';
}

/**
* Verify that the application does not already exist.
*
* @param string $directory
* @return void
*/
protected function verifyApplicationDoesntExist(string $directory): void
{
if ((is_dir($directory) || is_file($directory)) AND $directory != getcwd()) {
throw new RuntimeException('Application already exists!');
}
}
}
23 changes: 12 additions & 11 deletions src/Concerns/ConfiguresPrompts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace HichemTabTech\LaravelFS\Console\Concerns;

use Closure;
use Laravel\Prompts\ConfirmPrompt;
use Laravel\Prompts\MultiSelectPrompt;
use Laravel\Prompts\PasswordPrompt;
Expand All @@ -19,11 +20,11 @@ trait ConfiguresPrompts
/**
* Configure the prompt fallbacks.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param InputInterface $input
* @param OutputInterface $output
* @return void
*/
protected function configurePrompts(InputInterface $input, OutputInterface $output)
protected function configurePrompts(InputInterface $input, OutputInterface $output): void
{
Prompt::fallbackWhen(! $input->isInteractive() || PHP_OS_FAMILY === 'Windows');

Expand Down Expand Up @@ -99,18 +100,18 @@ function () use ($prompt, $input, $output) {
/**
* Prompt the user until the given validation callback passes.
*
* @param \Closure $prompt
* @param bool|string $required
* @param \Closure|null $validate
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param Closure $prompt
* @param bool|string $required
* @param Closure|null $validate
* @param OutputInterface $output
* @return mixed
*/
protected function promptUntilValid($prompt, $required, $validate, $output)
protected function promptUntilValid(Closure $prompt, bool|string $required, ?Closure $validate, OutputInterface $output): mixed
{
while (true) {
$result = $prompt();

if ($required && ($result === '' || $result === [] || $result === false)) {
if ($required AND ($result === '' || $result === [] || $result === false)) {
$output->writeln('<error>'.(is_string($required) ? $required : 'Required.').'</error>');

continue;
Expand All @@ -119,8 +120,8 @@ protected function promptUntilValid($prompt, $required, $validate, $output)
if ($validate) {
$error = $validate($result);

if (is_string($error) && strlen($error) > 0) {
$output->writeln("<error>{$error}</error>");
if (is_string($error) AND strlen($error) > 0) {
$output->writeln("<error>$error</error>");

continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/InteractsWithHerdOrValet.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function isParkedOnHerdOrValet(string $directory): bool

$decodedOutput = json_decode($output);

return is_array($decodedOutput) && in_array(dirname($directory), $decodedOutput);
return is_array($decodedOutput) AND in_array(dirname($directory), $decodedOutput);
}

/**
Expand Down
Loading
Loading