Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/install command #14

Merged
merged 22 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
767271d
add install & version commands
gwleuverink May 28, 2024
e1c06eb
add install command to the docs
gwleuverink May 28, 2024
5127fe5
fix crash when no runnable install commands set
gwleuverink May 28, 2024
6eeb53e
use twoColumnDetail in stead of prompts table
gwleuverink May 28, 2024
22cc7ef
add bundle:version command instruction in issue template
gwleuverink May 28, 2024
a4db9f5
added version command sanity check
gwleuverink May 29, 2024
0c19e2d
bump internal bun runtime
gwleuverink May 29, 2024
56b3b8c
update testing dependencies
gwleuverink May 29, 2024
c00956c
boyscouting
gwleuverink May 29, 2024
83829f7
added install command sanity checks
gwleuverink May 29, 2024
8f68d94
add install & version commands
gwleuverink May 28, 2024
933ff95
add install command to the docs
gwleuverink May 28, 2024
46b592d
fix crash when no runnable install commands set
gwleuverink May 28, 2024
a37931a
use twoColumnDetail in stead of prompts table
gwleuverink May 28, 2024
4c5bafb
add bundle:version command instruction in issue template
gwleuverink May 28, 2024
98aaedf
added version command sanity check
gwleuverink May 29, 2024
b3d89de
bump internal bun runtime
gwleuverink May 29, 2024
27461a5
update testing dependencies
gwleuverink May 29, 2024
03727b9
boyscouting
gwleuverink May 29, 2024
a2ff55f
added install command sanity checks
gwleuverink May 29, 2024
60c341f
Merge branch 'feature/install-command' of https://github.com/gwleuver…
gwleuverink May 29, 2024
e7a9f3e
add manual workflow triggers
gwleuverink May 29, 2024
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
14 changes: 8 additions & 6 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

title: ""
labels: ""
assignees: ""
---

Please provide the following info. You may run `artisan bundle:version` to dump all relevant package versions.

- Bundle: #.#.#
- Bun: #.#.#
- Laravel: #.#.#
- PHP: #.#.#
- Operating System: e.g. macOS 14.2.1
- Operating System: e.g. macOS 14.2.1

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Run `npm install ...`
2. Add import component to template '....'
2. Add import component to template '....'
3. Use the import in the following code '...'
4. See error

Expand Down
8 changes: 8 additions & 0 deletions docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ You may configure what paths are scanned by publishing the Bundle config file an

`artisan bundle:clear` Clear all bundled scripts.

### bundle:version

`artisan bundle:version` Dumps Bundle's version & it's dependencies (Bun & optionally LightningCSS & Sass).

### bundle:install

`artisan bundle:install` Prompts you through installing Bun & optional CSS loader dependencies.

## Testing fake

When writing Unit or Feature tests in your application you don't need Bundle to process & serve your imports.
Expand Down
8 changes: 6 additions & 2 deletions docs/css-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ We provide a custom CSS loader plugin that just works™. Built on top of [Light
You'll need to install Lightning CSS as a dependency.

```bash
npm install lightningcss --save-dev
php artisan bundle:install
```

You will be prompted to select a CSS loading method. Choose `CSS`.

Afterwards you may use `x-import` to load css files directly. Bundle transpiles it and injects it on your page with zero effort.

```html
Expand Down Expand Up @@ -44,9 +46,11 @@ npm install lightningcss --save-dev
You can use Bundle to compile [Sass](https://sass-lang.com/) on the fly. You'll need to install both Sass & Lightning CSS in your project. Bundle takes care of the rest.

```bash
npm install sass lightningcss --save-dev
php artisan bundle:install
```

You will be prompted to select a CSS loading method. Choose `Sass`.

{: .note }

> Due to a unresolved issue Bun is not able to auto-install LightningCSS & Sass on the fly. When this issue is fixed you won't have to install these dependencies yourself. Bun will automatically install them when needed 💅
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ composer require leuverink/bundle
```

```bash
npm install bun --save-dev
php artisan bundle:install
```

This is all you need to start using Bundle!
Expand Down
118 changes: 118 additions & 0 deletions src/Commands/Install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

namespace Leuverink\Bundle\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Process;

use function Laravel\Prompts\note;
use function Laravel\Prompts\intro;
use function Laravel\Prompts\outro;
use function Laravel\Prompts\select;
use function Laravel\Prompts\confirm;
use function Laravel\Prompts\warning;
use function Laravel\Prompts\progress;

class Install extends Command
{
protected $signature = 'bundle:install';
protected $description = 'Installs Bun, LightningCSS & Sass';

protected $installCommands = [];

public function handle(): int
{
$this->callSilent('bundle:clear');

$this->printAscii();
$this->printIntro();

$this->promptToInstallBun();
$this->promptToInstallCssLoading();

$this->install();

$this->call('bundle:version');

$this->printOutro();

return static::SUCCESS;
}

protected function printAscii()
{
note(<<< TEXT
____ __ __ _ __ ____ __ ______
/ __ ) / / / // | / // __ \ / / / ____/
/ __ |/ / / // |/ // / / // / / __/
/ /_/ // /_/ // /| // /_/ // /___ / /___
/_____/ \____//_/ |_//_____//_____//_____/
TEXT);
}

protected function printIntro()
{
intro(PHP_EOL . ' Thank you for installing Bundle! This wizard will set everything up for you. ' . PHP_EOL);
}

protected function promptToInstallBun()
{
$confirmed = confirm(
default: true,
label: 'Do you want to install Bun?',
hint: 'Bun needs to be installed in order to use Bundle. Skip this if you\'ve installed it manually.'
);

if ($confirmed) {
$this->installCommands[] = 'npm install bun@^1 --save-dev';
}
}

protected function promptToInstallCssLoading()
{
$choice = select(
label: 'Would you like to use CSS loading?',
options: [
'css' => 'CSS (installs LightningCSS)',
'sass' => 'Sass (installs Sass & LightningCSS)',
'none' => 'None',
],
default: 'css',
);

match ($choice) {
'css' => $this->installCommands[] = 'npm install lightningcss --save-dev',
'sass' => $this->installCommands = array_merge($this->installCommands, [
'npm install lightningcss --save-dev',
'npm install sass --save-dev',
]),
default => null,
};
}

protected function install()
{
if (empty($this->installCommands)) {
warning('Nothing to install.');

return;
}

progress(
label: 'Installing dependencies.',
steps: $this->installCommands,
callback: function ($command, $progress) {
$progress->hint($command);

Process::run($command);
},
hint: 'This may take some time.',
);
}

protected function printOutro()
{
outro(PHP_EOL . " You're all set! Check out https://laravel-bundle.dev/ to get started! " . PHP_EOL);
}
}
43 changes: 43 additions & 0 deletions src/Commands/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Leuverink\Bundle\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Process;

class Version extends Command
{
protected $signature = 'bundle:version';
protected $description = 'Lists Bundle and it\'s dependencies versions.';

public function handle(): int
{
$this->components->twoColumnDetail(' <fg=green;options=bold>Back-end</>');
$this->components->twoColumnDetail('Bundle', $this->composerPackageVersion('leuverink/bundle'));
$this->components->twoColumnDetail('Laravel', phpversion());
$this->components->twoColumnDetail('PHP', $this->laravel->version());

$this->newLine();
$this->components->twoColumnDetail(' <fg=green;options=bold>Front-end</>');
$this->components->twoColumnDetail('Bun', $this->npmPackageVersion('bun'));
$this->components->twoColumnDetail('LightningCSS', $this->npmPackageVersion('lightningcss'));
$this->components->twoColumnDetail('Sass', $this->npmPackageVersion('sass'));

return static::SUCCESS;
}

protected function composerPackageVersion(string $name): string
{
$packageInfo = json_decode(Process::run("composer show {$name} --format=json")->output());
$versions = data_get($packageInfo, 'versions', ['Not installed']);

return head($versions);
}

protected function npmPackageVersion(string $name): string
{
$packageInfo = json_decode(Process::run("npm list {$name} --json")->output());

return data_get($packageInfo, "dependencies.{$name}.version", 'Not installed');
}
}
4 changes: 4 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Route;
use Leuverink\Bundle\Bundlers\Bun\Bun;
use Leuverink\Bundle\Commands\Install;
use Leuverink\Bundle\Commands\Version;
use Leuverink\Bundle\Components\Import;
use Illuminate\Foundation\Http\Events\RequestHandled;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
Expand Down Expand Up @@ -64,6 +66,8 @@ protected function injectCore()

protected function registerCommands()
{
$this->commands(Install::class);
$this->commands(Version::class);
$this->commands(Build::class);
$this->commands(Clear::class);
}
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/Commands/VersionCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use Illuminate\Console\Command;

it('runs without crashing')
->artisan('bundle:version')
->assertExitCode(Command::SUCCESS)
->expectsOutputToContain('Bundle')
->expectsOutputToContain('Laravel')
->expectsOutputToContain('PHP')
->expectsOutputToContain('Bun')
->expectsOutputToContain('LightningCSS')
->expectsOutputToContain('Sass');
2 changes: 1 addition & 1 deletion workbench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"IE 11"
],
"devDependencies": {
"bun": "^1.0.33",
"bun": "^1.1.10",
"lodash": "^4.17.21",
"alpinejs": "^3.13.3",
"@alpinejs/persist": "^3.13.3"
Expand Down
Loading