Skip to content

Commit

Permalink
Fixes site install and improve init (#59)
Browse files Browse the repository at this point in the history
* Fix load site install services file.

* Remove site-path message on generated files.

* Auto-detect web-root directory.
  • Loading branch information
jmolivas authored Sep 30, 2016
1 parent 98b6d48 commit 7672acf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Bootstrap/DrupalConsoleCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function boot()
$loader->load('services.yml');
}

if (file_exists($this->root.DRUPAL_CONSOLE.'/services-drupal-install')) {
if (file_exists($this->root.DRUPAL_CONSOLE.'/services-drupal-install.yml')) {
$loader->load(
$this->root . DRUPAL_CONSOLE . '/services-drupal-install'
$this->root . DRUPAL_CONSOLE . '/services-drupal-install.yml'
);
}

Expand Down
15 changes: 13 additions & 2 deletions src/Command/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class InitCommand extends Command
'generate_chain' => false
];

private $webRootDirectories = [
'web',
'docroot'
];

/**
* InitCommand constructor.
* @param ShowFile $showFile
Expand Down Expand Up @@ -107,7 +112,13 @@ protected function interact(InputInterface $input, OutputInterface $output)
}

if ($local) {
$this->configParameters['root'] = $io->askEmpty(
$root = null;
foreach($this->webRootDirectories as $webRootDirectory) {
if (!$root && is_dir(getcwd().'/'.$webRootDirectory)) {
$root = $webRootDirectory;
}
}
$this->configParameters['root'] = $root?:$io->askEmpty(
$this->trans('commands.init.questions.root')
);
}
Expand Down Expand Up @@ -178,7 +189,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if ($copiedFiles) {
$this->showFile->copiedFiles($io, $copiedFiles);
$this->showFile->copiedFiles($io, $copiedFiles, false);
$io->newLine();
}

Expand Down
2 changes: 1 addition & 1 deletion src/EventSubscriber/ShowGeneratedFilesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function showGeneratedFiles(ConsoleTerminateEvent $event)

$files = $this->fileQueue->getFiles();
if ($files) {
$this->showFile->generatedFiles($io, $files);
$this->showFile->generatedFiles($io, $files, false);
}
}

Expand Down
40 changes: 29 additions & 11 deletions src/Utils/ShowFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,44 @@ public function __construct(
/**
* @param DrupalStyle $io
* @param string $files
* @param boolean $showPath
*/
public function generatedFiles($io, $files)
public function generatedFiles($io, $files, $showPath = true)
{
$pathKey = null;
$path = null;
if ($showPath){
$pathKey = 'application.user.messages.path';
$path = $this->root;
}
$this->showFiles(
$io,
$files,
'application.messages.files.generated',
'application.site.messages.path',
$this->root
$pathKey,
$path
);
}

/**
* @param DrupalStyle $io
* @param string $files
* @param boolean $showPath
*/
public function copiedFiles($io, $files)
public function copiedFiles($io, $files, $showPath = true)
{
$pathKey = null;
$path = null;
if ($showPath){
$pathKey = 'application.user.messages.path';
$path = rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '/\\').'/.console/';
}
$this->showFiles(
$io,
$files,
'application.messages.files.copied',
'application.user.messages.path',
rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '/\\').'/.console/'
$pathKey,
$path
);
}

Expand All @@ -76,11 +90,15 @@ private function showFiles($io, $files, $headerKey, $pathKey, $path)

$io->writeln($this->translator->trans($headerKey));

$io->info(
sprintf('%s:', $this->translator->trans($pathKey)),
false
);
$io->comment($path, false);
if ($pathKey) {
$io->info(
sprintf('%s:', $this->translator->trans($pathKey)),
false
);
}
if ($path) {
$io->comment($path, false);
}
$io->newLine();

$index = 1;
Expand Down

0 comments on commit 7672acf

Please sign in to comment.