laravel-shift/blueprint

Global package so I can use it like Laravel pint

Closed this issue · 3 comments

Synopsis:

Proposed Syntax:

Expected Behavior:

Hey @muath-ye,

I'm not quite sure I understood your request.

If you are asking if you can install a blueprint globally on your machine,

You can use this command: composer global require laravel-shift/blueprint

If that was not what you were asking, or if the above command did not work for you let us know, please include all relevant details.

Please disregard my last comment, I just realized what your request was.

Currently, Blueprint is not a standalone command-line application.

Blueprint instead adds custom commands on top of Laravel's artisan command-line application. (which means Blueprint can not run globally by itself)

We have two options:

  • Convert blueprint into standalone command-line application. (requires JMac's approval)
  • Setup a custom artisan command globally
To use `artisan` globally I have prepared a script that you can use.

#!/usr/bin/env php
<?php

define('LARAVEL_START', microtime(true));

$currentWorkingDirectory = getcwd();

if(!$currentWorkingDirectory)
{
    echo 'can not get current working directory' . PHP_EOL;
    exit(-1);
}

$composerFile = $currentWorkingDirectory . '/composer.json';

if (! file_exists($composerFile))
{
    echo 'composer.json not found' . PHP_EOL;
    echo 'please go to you project root directory' . PHP_EOL;
    exit(-2);
}

$contents = file_get_contents($composerFile);
if($contents === false)
{
    echo 'can not read composer.json' . PHP_EOL;
    exit(-3);
}

try {
    $json = json_decode($contents, true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
    echo $e->getMessage() . PHP_EOL;
    exit(-4);
}

if (! is_array($json)) 
{
    echo 'can not parse composer.json' . PHP_EOL;
    exit(-5);
}

if (isset($json['name']) === false || $json['name'] !== 'laravel/laravel') {
    echo 'Unable to confirm that laravel is installed in this directory' . PHP_EOL;
    exit(-6);
}

unset($json);

require $currentWorkingDirectory.'/vendor/autoload.php';

$app = require_once $currentWorkingDirectory.'/bootstrap/app.php';

$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);

$status = $kernel->handle(
    $input = new Symfony\Component\Console\Input\ArgvInput(),
    new Symfony\Component\Console\Output\ConsoleOutput()
);

$kernel->terminate($input, $status);

exit($status);
  1. create a global-artisan.php file using the code above.
  2. run sudo mv ./global-artisan.php /usr/local/bin/gartisan
  3. run sudo chmod +x /usr/local/bin/gartisan
  4. use gartisan

I do not want to rework this as a stand-alone application at this time. It would break support for community add-ons. Maybe something to consider in Blueprint v3.