Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit 5cf4b2b

Browse files
committed
add lucid binary with "new" command
1 parent c6161e8 commit 5cf4b2b

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"Lucid\\Console\\": "src/"
1414
}
1515
},
16+
"bin": ["lucid"],
1617
"minimum-stability": "stable",
1718
"require": {
1819
"symfony/console": "^3.1",

lucid

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
if (file_exists(__DIR__.'/../../autoload.php')) {
5+
require __DIR__.'/../../autoload.php';
6+
} else {
7+
require __DIR__.'/vendor/autoload.php';
8+
}
9+
10+
$app = new Symfony\Component\Console\Application('Lucid CLI', '0.1.0');
11+
$app->add(new Lucid\Console\Commands\NewCommand());
12+
13+
$app->run();

src/Commands/NewCommand.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the lucid-cli project.
5+
*
6+
* (c) Vinelab <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Lucid\Console\Commands;
13+
14+
use Symfony\Component\Process\Process;
15+
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Input\InputOption;
17+
use Symfony\Component\Console\Input\InputArgument;
18+
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Output\OutputInterface;
20+
21+
/**
22+
* @author Abed Halawi <[email protected]>
23+
*/
24+
class NewCommand extends Command
25+
{
26+
/**
27+
* Configure the command options.
28+
*/
29+
protected function configure()
30+
{
31+
$this
32+
->setName('new')
33+
->setDescription('Create a new Lucid-architected project')
34+
->addArgument('name', InputArgument::OPTIONAL)
35+
->addOption('laravel', null, InputOption::VALUE_NONE, 'Specify the Laravel version you wish to install');
36+
}
37+
38+
/**
39+
* Execute the command.
40+
*
41+
* @param InputInterface $input
42+
* @param OutputInterface $output
43+
*/
44+
public function execute(InputInterface $input, OutputInterface $output)
45+
{
46+
$this->verifyApplicationDoesntExist(
47+
$directory = ($input->getArgument('name')) ? getcwd().'/'.$input->getArgument('name') : getcwd(),
48+
$output
49+
);
50+
51+
$output->writeln('<info>Crafting Lucid application...</info>');
52+
53+
/*
54+
* @TODO: Get Lucid based on the Laravel version.
55+
*/
56+
$process = new Process($this->findComposer().' create-project laravel/laravel '.$directory);
57+
58+
if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
59+
$process->setTty(true);
60+
}
61+
62+
$process->run(function ($type, $line) use ($output) {
63+
$output->write($line);
64+
});
65+
66+
$output->writeln('<comment>Application ready! Make your dream a reality.</comment>');
67+
}
68+
69+
/**
70+
* Verify that the application does not already exist.
71+
*
72+
* @param string $directory
73+
*/
74+
protected function verifyApplicationDoesntExist($directory, OutputInterface $output)
75+
{
76+
if ((is_dir($directory) || is_file($directory)) && $directory != getcwd()) {
77+
throw new RuntimeException('Application already exists!');
78+
}
79+
}
80+
81+
/**
82+
* Get the composer command for the environment.
83+
*
84+
* @return string
85+
*/
86+
protected function findComposer()
87+
{
88+
$composer = 'composer';
89+
90+
if (file_exists(getcwd().'/composer.phar')) {
91+
$composer = '"'.PHP_BINARY.'" composer.phar';
92+
}
93+
94+
return $composer;
95+
}
96+
}

0 commit comments

Comments
 (0)