Skip to content

Commit

Permalink
feat: ask for module namespace in createModuleCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikbehncke committed Aug 9, 2024
1 parent cb76f3b commit bcc9b97
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/CreateModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;
use Symfony\Component\Finder\Finder;
Expand Down Expand Up @@ -36,6 +37,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$fn = [$this->getHelper('question'), 'ask'];
$ask = $this->partial($fn, $input, $output);
$namespace = $ask(new Question('Enter module namespace: '));
$assets = $ask(new ConfirmationQuestion('Add module assets example? [Y/n] ', true));
$settings = $ask(new ConfirmationQuestion('Add settings example? [Y/n] ', true));

Expand All @@ -55,7 +57,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$fs->dumpFile("{$path}/{$file->getRelativePathname()}", $file->getContents());
}

// namespace
$this->replaceInFile(
"{$path}/bootstrap.php",
['#// namespace#'],
$namespace ? ["namespace {$namespace};"] : [''],
);

if ($assets) {
// add AssetsListener
$find = ['#// includes#', '#// add event handlers ...#'];
$replace = [
"\${0}\ninclude_once __DIR__ . 'src/AssetsListener';",
Expand All @@ -65,9 +75,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
];

$this->replaceInFile("{$path}/bootstrap.php", $find, $replace);

// namespace
$this->replaceInFile(
"{$path}/src/AssetsListener.php",
['#// namespace#'],
$namespace ? ["namespace {$namespace};"] : [''],
);
}

if ($settings) {
// add SettingsListener
$find = ['#// includes#', '#// add event handlers ...#'];
$replace = [
"\${0}\ninclude_once __DIR__ . 'src/SettingsListener';",
Expand All @@ -77,6 +95,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
];

$this->replaceInFile("{$path}/bootstrap.php", $find, $replace);

// namespace
$this->replaceInFile(
"{$path}/src/SettingsListener.php",
['#// namespace#'],
$namespace ? ["namespace {$namespace};"] : [''],
);
}

$output->writeln('Module created successfully.');
Expand Down
2 changes: 2 additions & 0 deletions src/stubs/module/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

// namespace

use YOOtheme\Builder;
use YOOtheme\Path;

Expand Down
2 changes: 2 additions & 0 deletions src/stubs/module/src/AssetsListener.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

// namespace

use YOOtheme\Metadata;
use YOOtheme\Path;

Expand Down
2 changes: 2 additions & 0 deletions src/stubs/module/src/SettingsListener.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

// namespace

use YOOtheme\Config;
use YOOtheme\Path;

Expand Down

0 comments on commit bcc9b97

Please sign in to comment.