Compare commits

..

No commits in common. "master" and "0.1.1" have entirely different histories.

14 changed files with 2225 additions and 111 deletions

1
.gitignore vendored
View file

@ -1,2 +1 @@
/vendor/ /vendor/
/composer.lock

View file

@ -1,14 +0,0 @@
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude(['fixtures']);
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => true,
'phpdoc_order' => true,
])
->setFinder($finder);

View file

@ -1,17 +0,0 @@
language: php
php:
- 7.2
- 7.3
- 7.4
env:
matrix:
- COMPOSER_FLAGS="--prefer-lowest"
- COMPOSER_FLAGS=""
before_script:
- composer install --dev --prefer-source --no-interaction
script:
- vendor/bin/phpunit

View file

@ -1,28 +1,7 @@
# Drupal Module Generator (dmg) # Drupal Module Generator (dmg)
A scaffolding tool for generating new modules for Drupal 7 and (soon) 8. A scaffolding tool for generating new modules for Drupal 7 and 8.
[Watch a short demo][demo].
[demo]: https://opdavi.es/6i3YZ 'A short demo video on YouTube'
## Installation
The Drupal Module Generator is installed via [Composer][]:
```bash
composer global require opdavies/drupal-module-generator
```
[composer]: https://getcomposer.org
## Usage ## Usage
### Drupal 7 TODO
```bash
dmg generate:drupal-7-module {name}
```
Generated Drupal 7 modules contain the appropriately named `.info` and `.module` files,
as well as a test case located in `src/Tests/Functional` which [is loaded automatically](https://www.oliverdavies.uk/articles/psr4-autoloading-test-cases-drupal-7).

View file

@ -13,7 +13,7 @@ if (file_exists(__DIR__.'/../../../autoload.php')) {
require __DIR__.'/../vendor/autoload.php'; require __DIR__.'/../vendor/autoload.php';
} }
$app = new Application('Drupal Module Generator'); $app = new Application();
$finder = new Finder(); $finder = new Finder();
$moduleNameConverter = new ModuleNameConverter(); $moduleNameConverter = new ModuleNameConverter();

View file

@ -3,17 +3,16 @@
"description": "Generates boilerplate code for Drupal modules.", "description": "Generates boilerplate code for Drupal modules.",
"type": "project", "type": "project",
"require": { "require": {
"php": "^7.2", "symfony/console": "^3.0 || ^4.0 || ^5.0",
"symfony/console": "^4.0 || ^5.0", "symfony/dependency-injection": "^3.0 || ^4.0 || ^5.0",
"symfony/dependency-injection": "^4.0 || ^5.0", "symfony/filesystem": "^3.0 || ^4.0 || ^5.0",
"symfony/filesystem": "^4.0 || ^5.0", "symfony/finder": "^3.0 || ^4.0 || ^5.0",
"symfony/finder": "^4.0 || ^5.0",
"tightenco/collect": "^6.14" "tightenco/collect": "^6.14"
}, },
"require-dev": { "require-dev": {
"friendsofphp/php-cs-fixer": "^2.16", "php": "5.6 || ^7.0",
"phpunit/phpunit": "^8.5", "phpunit/phpunit": "^9.0",
"symfony/var-dumper": "^4.0 || ^5.0" "symfony/var-dumper": "^3.0 || ^4.0 || ^5.0"
}, },
"license": "MIT", "license": "MIT",
"authors": [ "authors": [
@ -36,9 +35,6 @@
"bin/dmg" "bin/dmg"
], ],
"config": { "config": {
"platform": {
"php": "7.2.5"
},
"sort-packages": true "sort-packages": true
} }
} }

2200
composer.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,3 @@
name = {{ name }} name = {{ name }}
description = {{ name }} module. description = The description for {{ name }}.
core = 7.x core = 7.x

View file

@ -1,21 +1,5 @@
<?php <?php
namespace Drupal\{{ machine_name }}\Tests\Functional; namespace Drupal\{{ name }}\Tests\Functional;
final class {{ test_name }} extends \DrupalWebTestCase { final class {{ test_name }} extends \DrupalWebTestCase {}
public static function getInfo() {
return array(
'name' => '{{ name }}',
'description' => '{{ name }} tests.',
'group' => '{{ name }}',
);
}
public function test_that_the_front_page_loads() {
$this->drupalGet('<front>');
$this->assertResponse(200);
}
}

View file

@ -10,11 +10,12 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo; use Symfony\Component\Finder\SplFileInfo;
use Tightenco\Collect\Support\Collection; use Tightenco\Collect\Support\Collection;
final class GenerateDrupal7Command extends Command class GenerateDrupal7Command extends Command
{ {
private $moduleName; private $moduleName;
private $machineName; private $machineName;
@ -41,7 +42,7 @@ final class GenerateDrupal7Command extends Command
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected static $defaultName = 'generate:drupal-7-module'; protected static $defaultName = 'generate-drupal-7-module';
/** /**
* {@inheritDoc} * {@inheritDoc}
@ -49,10 +50,8 @@ final class GenerateDrupal7Command extends Command
protected function configure() protected function configure()
{ {
$this $this
->setDescription('Generate a new Drupal 7 module') ->setDescription('Generate a new Drupal 7 module.')
->addArgument('module-name', InputArgument::REQUIRED, 'The name of the module to create') ->addArgument('module-name', InputArgument::REQUIRED, 'The name of the module to create');
->setAliases(['d7', 'drupal7'])
;
} }
/** /**
@ -62,8 +61,6 @@ final class GenerateDrupal7Command extends Command
{ {
$this->io = new SymfonyStyle($input, $output); $this->io = new SymfonyStyle($input, $output);
$this->io->title("Drupal Module Generator (D7)");
$this->machineName = $input->getArgument('module-name'); $this->machineName = $input->getArgument('module-name');
$this->moduleName = $this->moduleNameConverter->__invoke($this->machineName); $this->moduleName = $this->moduleNameConverter->__invoke($this->machineName);
$this->testName = $this->testNameConverter->__invoke($this->machineName); $this->testName = $this->testNameConverter->__invoke($this->machineName);
@ -98,6 +95,7 @@ final class GenerateDrupal7Command extends Command
private function createFiles() private function createFiles()
{ {
$createdFiles = new Collection(); $createdFiles = new Collection();
$testNameConverter = new TestNameConverter();
/** @var SplFileInfo $file */ /** @var SplFileInfo $file */
foreach ($this->finder->in(__DIR__.'/../../fixtures/drupal7_module')->files() as $file) { foreach ($this->finder->in(__DIR__.'/../../fixtures/drupal7_module')->files() as $file) {
@ -117,16 +115,11 @@ final class GenerateDrupal7Command extends Command
$createdFiles->push($filename); $createdFiles->push($filename);
} }
if ($createdFiles->isNotEmpty()) { $this->io->listing($createdFiles->filter()->sort()->toArray());
$this->io->block('Files generated:');
$this->io->listing($createdFiles->sort()->toArray());
}
} }
private function updateFileContents($contents) private function updateFileContents($contents)
{ {
$contents = str_replace('{{ machine_name }}', $this->machineName, $contents);
$contents = str_replace('{{ name }}', $this->moduleName, $contents); $contents = str_replace('{{ name }}', $this->moduleName, $contents);
$contents = str_replace('{{ test_name }}', $this->testName, $contents); $contents = str_replace('{{ test_name }}', $this->testName, $contents);

View file

@ -2,7 +2,7 @@
namespace Opdavies\DrupalModuleGenerator\Exception; namespace Opdavies\DrupalModuleGenerator\Exception;
final class CannotCreateModuleException extends \RuntimeException class CannotCreateModuleException extends \RuntimeException
{ {
public static function directoryAlreadyExists() public static function directoryAlreadyExists()
{ {

View file

@ -2,7 +2,7 @@
namespace Opdavies\DrupalModuleGenerator\Service; namespace Opdavies\DrupalModuleGenerator\Service;
final class ModuleNameConverter class ModuleNameConverter
{ {
public function __invoke(string $moduleName) public function __invoke(string $moduleName)
{ {

View file

@ -2,7 +2,7 @@
namespace Opdavies\DrupalModuleGenerator\Service; namespace Opdavies\DrupalModuleGenerator\Service;
final class TestNameConverter class TestNameConverter
{ {
public function __invoke(string $moduleName) public function __invoke(string $moduleName)
{ {

View file

@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
final class GenerateDrupal7ModuleCommandTest extends TestCase class GenerateDrupal7ModuleCommandTest extends TestCase
{ {
protected function tearDown(): void protected function tearDown(): void
{ {
@ -69,7 +69,7 @@ final class GenerateDrupal7ModuleCommandTest extends TestCase
$contents = file_get_contents('test_module/test_module.info'); $contents = file_get_contents('test_module/test_module.info');
$this->assertStringContainsString('name = Test Module', $contents); $this->assertStringContainsString('name = Test Module', $contents);
$this->assertStringContainsString('description = Test Module module.', $contents); $this->assertStringContainsString('description = The description for Test Module.', $contents);
} }
/** @test */ /** @test */
@ -109,12 +109,6 @@ final class GenerateDrupal7ModuleCommandTest extends TestCase
$contents = file_get_contents('test_module/src/Tests/Functional/TestModuleTest.php'); $contents = file_get_contents('test_module/src/Tests/Functional/TestModuleTest.php');
$this->assertStringContainsString('namespace Drupal\\test_module\\Tests\\Functional', $contents);
$this->assertStringContainsString('final class TestModuleTest', $contents); $this->assertStringContainsString('final class TestModuleTest', $contents);
$this->assertStringContainsString("'name' => 'Test Module'", $contents);
$this->assertStringContainsString("'description' => 'Test Module tests.'", $contents);
$this->assertStringContainsString("'group' => 'Test Module'", $contents);
} }
} }