5 * Contains \Drupal\Console\Generator\ModuleGenerator.
8 namespace Drupal\Console\Generator;
10 use Drupal\Console\Core\Generator\Generator;
13 * Class ModuleGenerator
15 * @package Drupal\Console\Generator
17 class ModuleGenerator extends Generator
27 * @param $featuresBundle
29 * @param $dependencies
31 * @param $twigtemplate
33 public function generate(
47 $dir .= '/'.$machineName;
48 if (file_exists($dir)) {
50 throw new \RuntimeException(
52 'Unable to generate the module as the target directory "%s" exists but is a file.',
57 $files = scandir($dir);
58 if ($files != ['.', '..']) {
59 throw new \RuntimeException(
61 'Unable to generate the module as the target directory "%s" is not empty.',
66 if (!is_writable($dir)) {
67 throw new \RuntimeException(
69 'Unable to generate the module as the target directory "%s" is not writable.',
78 'machine_name' => $machineName,
81 'description' => $description,
82 'package' => $package,
83 'dependencies' => $dependencies,
85 'twigtemplate' => $twigtemplate,
89 'module/info.yml.twig',
90 $dir.'/'.$machineName.'.info.yml',
94 if (!empty($featuresBundle)) {
96 'module/features.yml.twig',
97 $dir.'/'.$machineName.'.features.yml',
99 'bundle' => $featuresBundle,
105 // Generate '.module' file.
106 $this->createModuleFile($dir, $parameters);
111 'module/composer.json.twig',
112 $dir.'/'.'composer.json',
119 'module/src/Tests/load-test.php.twig',
120 $dir . '/tests/src/Functional/' . 'LoadTest.php',
125 // If module file is not created earlier, create now.
127 // Generate '.module' file.
128 $this->createModuleFile($dir, $parameters);
131 'module/module-twig-template-append.twig',
132 $dir .'/' . $machineName . '.module',
136 $dir .= '/templates/';
137 if (file_exists($dir)) {
139 throw new \RuntimeException(
141 'Unable to generate the templates directory as the target directory "%s" exists but is a file.',
146 $files = scandir($dir);
147 if ($files != ['.', '..']) {
148 throw new \RuntimeException(
150 'Unable to generate the templates directory as the target directory "%s" is not empty.',
155 if (!is_writable($dir)) {
156 throw new \RuntimeException(
158 'Unable to generate the templates directory as the target directory "%s" is not writable.',
165 'module/twig-template-file.twig',
166 $dir . str_replace("_", "-", $machineName) . '.html.twig',
173 * Generate the '.module' file.
176 * The directory name.
177 * @param array $parameters
178 * The parameter array.
180 protected function createModuleFile($dir, $parameters)
183 'module/module.twig',
184 $dir . '/' . $parameters['machine_name'] . '.module',