|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace UnikCodes\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
8
|
|
|
use UnikCodes\Console\Commander; |
|
9
|
|
|
|
|
10
|
|
|
class MakeNewCommand extends Commander |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Configure the command options. |
|
14
|
|
|
*/ |
|
15
|
|
|
protected function configure() |
|
16
|
|
|
{ |
|
17
|
|
|
$this |
|
18
|
|
|
->setName('new') |
|
19
|
|
|
->setDescription('Create a new Ark project') |
|
20
|
|
|
->addArgument('name', InputArgument::REQUIRED, 'Project name') |
|
21
|
|
|
->addArgument('path', InputArgument::OPTIONAL, 'Path of the project to be create'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Execute the command. |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
28
|
|
|
{ |
|
29
|
|
|
$name = $this->cleanupName($input->getArgument('name')); |
|
30
|
|
|
$path = $input->getArgument('path') |
|
31
|
|
|
? $input->getArgument('path') . DIRECTORY_SEPARATOR . $name |
|
|
|
|
|
|
32
|
|
|
: getcwd() . DIRECTORY_SEPARATOR . $name; |
|
33
|
|
|
|
|
34
|
|
|
if (file_exists($path)) { |
|
35
|
|
|
$output->writeln('<error>Git: ' . $path . ' already exists!</error>'); |
|
36
|
|
|
|
|
37
|
|
|
return 1; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$output->writeln('<info>Git:</info> Creating new Ark project named ' . $name); |
|
41
|
|
|
exec('composer create-project unik-codes/ark "' . $path . '" --prefer-dist'); |
|
42
|
|
|
|
|
43
|
|
|
if (file_exists($path)) { |
|
44
|
|
|
chdir($path); |
|
45
|
|
|
$this->gitInit(); |
|
46
|
|
|
$output->writeln('<info>Git:</info> Initialise, add all files and commit...'); |
|
47
|
|
|
$this->composerUpdate(); |
|
48
|
|
|
$output->writeln('<info>Composer:</info> Update dependencies...'); |
|
49
|
|
|
$this->gitCommitUpdateDependecies(); |
|
50
|
|
|
$output->writeln('<info>Git:</info> Commit dependencies...'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$output->writeln('<info>New Ark created: </info> ' . $input->getArgument('name') . ' is created at ' . $path); |
|
|
|
|
|
|
54
|
|
|
$output->writeln('<info>Thank you for using Ark!</info>'); |
|
55
|
|
|
|
|
56
|
|
|
return 0; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|