/
PublishPackage.php
69 lines (54 loc) · 2.42 KB
/
PublishPackage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace JeroenG\Packager\Commands;
use Illuminate\Console\Command;
use JeroenG\Packager\Conveyor;
use JeroenG\Packager\FileHandlerInterface;
use JeroenG\Packager\ProgressBar;
/**
* Get an existing package from a remote Github repository with its git repository.
*
* @author JeroenG
**/
class PublishPackage extends Command
{
use ProgressBar;
protected $signature = 'packager:publish
{vendor : The vendor part of the namespace}
{name : The name of package for the namespace}
{url : The url of the Github repository}';
protected $description = 'Publish your package to Github with git.';
/**
* Packages roll off of the conveyor.
*/
protected Conveyor $conveyor;
protected FileHandlerInterface $fileHandler;
public function __construct(Conveyor $conveyor, FileHandlerInterface $fileHandler)
{
parent::__construct();
$this->conveyor = $conveyor;
$this->fileHandler = $fileHandler;
}
public function handle(): void
{
// Start the progress bar
$this->startProgressBar(5);
// Defining vendor/package
$this->conveyor->vendor($this->argument('vendor'));
$this->conveyor->package($this->argument('name'));
$this->info('Initialising Git if not already done so...');
if (! file_exists($this->fileHandler->packagePath($this->conveyor->vendor(), $this->conveyor->package()).'/.git/')) {
exec('cd '.$this->fileHandler->packagePath($this->conveyor->vendor(), $this->conveyor->package()).' && git init && git add --all && git commit -m "Initial commit"');
}
$this->makeProgress();
$this->info('Git is set up, adding the remote repository...');
exec('cd '.$this->fileHandler->packagePath($this->conveyor->vendor(), $this->conveyor->package()).' && git remote add origin '.$this->argument('url'));
$this->makeProgress();
$this->info('Pushing to Github...');
exec('cd '.$this->fileHandler->packagePath($this->conveyor->vendor(), $this->conveyor->package()).' && git push -u origin master');
$this->makeProgress();
// Finished publishing the package, end of the progress bar
$this->finishProgress('Package created successfully!');
$this->info('Go ahead and submit it to Packagist: https://packagist.org/packages/submit');
}
}