|
8 | 8 |
|
9 | 9 | class Customizer {
|
10 | 10 |
|
| 11 | + protected string $extenstion_name; |
| 12 | + protected string $extenstion_machine_name; |
| 13 | + protected string $extenstion_type; |
| 14 | + protected string $ci_provider; |
| 15 | + protected string $command_wrapper; |
| 16 | + |
| 17 | + /** |
| 18 | + * Construct. |
| 19 | + * |
| 20 | + * @param string $extenstion_name |
| 21 | + * Extension name. |
| 22 | + * @param string $extenstion_machine_name |
| 23 | + * Extension machine name. |
| 24 | + * @param string $extenstion_type |
| 25 | + * Extenstion type: module or theme. |
| 26 | + * @param string $ci_provider |
| 27 | + * CI Provider: gha or circleci |
| 28 | + * @param string $command_wrapper |
| 29 | + * Command wrapper: ahoy, makefile or none. |
| 30 | + */ |
| 31 | + public function __construct( |
| 32 | + string $extenstion_name, |
| 33 | + string $extenstion_machine_name, |
| 34 | + string $extenstion_type = 'module', |
| 35 | + string $ci_provider = 'gha', |
| 36 | + string $command_wrapper = 'ahoy') { |
| 37 | + |
| 38 | + $this->extenstion_name = $extenstion_name; |
| 39 | + $this->extenstion_machine_name = $extenstion_machine_name; |
| 40 | + $this->extenstion_type = $extenstion_type; |
| 41 | + $this->ci_provider = $ci_provider; |
| 42 | + $this->command_wrapper = $command_wrapper; |
| 43 | + } |
| 44 | + |
| 45 | + public function process() { |
| 46 | + // Remove CI Provider. |
| 47 | + $this->removeCiProvider(); |
| 48 | + // Remove command wrapper. |
| 49 | + $this->removeCommandWrapper(); |
| 50 | + // Process README. |
| 51 | + $this->processReadme(); |
| 52 | + // Process internal replacement. |
| 53 | + $this->processInternalReplacement(); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Process README.md. |
| 58 | + */ |
| 59 | + protected function processReadme(): void { |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Internal process to replace scaffold string and remove scaffold files. |
| 65 | + */ |
| 66 | + protected function processInternalReplacement(): void { |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Remove CI provider depends on CI provider selected. |
| 72 | + */ |
| 73 | + protected function removeCiProvider(): void { |
| 74 | + $ci_provider = $this->ci_provider; |
| 75 | + if ($ci_provider === 'gha') { |
| 76 | + $this->removeCircleciCiProvider(); |
| 77 | + }else { |
| 78 | + $this->removeGhaCiProvider(); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Remove CircleCi (circleci) CI provider. |
| 84 | + */ |
| 85 | + protected function removeCircleciCiProvider(): void { |
| 86 | + |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Remove Github Action (gha) CI provider. |
| 91 | + */ |
| 92 | + protected function removeGhaCiProvider(): void { |
| 93 | + |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Remove command wrappers depends on command wrapper selected. |
| 98 | + */ |
| 99 | + protected function removeCommandWrapper(): void { |
| 100 | + $command_wrapper = $this->command_wrapper; |
| 101 | + switch ($command_wrapper) { |
| 102 | + case 'ahoy': |
| 103 | + $this->removeMakeCommandWrapper(); |
| 104 | + break; |
| 105 | + case 'make': |
| 106 | + $this->removeAhoyCommandWrapper(); |
| 107 | + break; |
| 108 | + default: |
| 109 | + $this->removeAhoyCommandWrapper(); |
| 110 | + $this->removeMakeCommandWrapper(); |
| 111 | + break; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Remove 'Ahoy' command wrapper. |
| 117 | + */ |
| 118 | + protected function removeAhoyCommandWrapper(): void { |
| 119 | + |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Remove 'Make' command wrapper. |
| 124 | + */ |
| 125 | + protected function removeMakeCommandWrapper(): void { |
| 126 | + |
| 127 | + } |
| 128 | + |
11 | 129 | public static function main(Event $event) {
|
12 | 130 | $extension_name = $event->getIO()->ask('Name', 'Your Extenstion');
|
13 |
| - $extension_machine_name = $event->getIO()->ask('Machine Name', 'Your Extenstion'); |
| 131 | + $extension_machine_name = $event->getIO()->ask('Machine Name', 'your_extension'); |
14 | 132 | $extension_type = 'module';
|
15 | 133 | $extension_type = $event->getIO()->ask('Type: module or theme', $extension_type);
|
16 | 134 | $ci_provider = 'gha';
|
17 | 135 | $ci_provider = $event->getIO()->ask('CI Provider: GitHub Actions (gha) or CircleCI (circleci)', $ci_provider);
|
18 | 136 | $command_wrapper = 'ahoy';
|
19 | 137 | $command_wrapper = $event->getIO()->ask('Command wrapper: Ahoy (ahoy), Makefile (makefile), None (none)', $command_wrapper);
|
20 | 138 |
|
21 |
| - // Summary |
22 |
| - |
23 |
| - // Handle replacement |
| 139 | + $customizer = new static($extension_name, $extension_machine_name, $extension_type, $ci_provider, $command_wrapper); |
| 140 | + try { |
| 141 | + $customizer->process(); |
| 142 | + } catch (\Exception $exception) { |
| 143 | + throw new \Exception(printf('Initialization is not completed. Error %s', $exception->getMessage()), $exception->getCode(), $exception); |
| 144 | + } |
24 | 145 | }
|
25 | 146 | }
|
0 commit comments