diff --git a/src/CreatePluginCommand.php b/src/CreatePluginCommand.php index 3d9a1ac..a6d5681 100644 --- a/src/CreatePluginCommand.php +++ b/src/CreatePluginCommand.php @@ -42,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $variables = [ 'NAME' => $name, 'PLUGIN' => $name, - 'PLUGIN_CLASS' => 'plgSystem' . strtr($name, ['-' => '', '_' => '']), + 'PLUGIN_CLASS' => 'plgSystem' . ucfirst(strtr($name, ['-' => '', '_' => ''])), 'TITLE' => $ask(new Question('Enter plugin title: ', $name)), ]; @@ -63,6 +63,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int ); } + if ($ask(new Question('Do you want to create a module?', 'yes')) === 'yes') { + $finder = (new Finder())->in("{$this->stubs}/module"); + + foreach ($finder->files() as $file) { + $fs->dumpFile("{$file->getRelativePathname()}", $file->getContents()); + } + } + $output->writeln("Plugin '{$name}' created successfully."); return Command::SUCCESS; diff --git a/src/stubs/module/bootstrap.php b/src/stubs/module/bootstrap.php new file mode 100644 index 0000000..4d570d8 --- /dev/null +++ b/src/stubs/module/bootstrap.php @@ -0,0 +1,19 @@ + [], + + // Register event handlers + 'events' => [], + + // Load builder elements + 'extend' => [ + Builder::class => function (Builder $builder) { + $builder->addTypePath(Path::get('./elements/*/element.json')); + }, + ], +]; diff --git a/src/stubs/plugin/Taskfile.yml b/src/stubs/plugin/Taskfile.yml index f638c5e..eb278ba 100644 --- a/src/stubs/plugin/Taskfile.yml +++ b/src/stubs/plugin/Taskfile.yml @@ -15,8 +15,12 @@ vars: AUTHORURL: '{{ AUTHORURL }}' tasks: - copy-joomla: - internal: true + build: + deps: + - for: [joomla, wordpress] + task: build-{{ .ITEM }} + + build-joomla: cmds: - task: utils:copy vars: @@ -24,6 +28,72 @@ tasks: src: '**' dest: dist/joomla + - task: copy-module + vars: + SYSTEM: joomla + + - task: copy-elements + vars: + SYSTEM: joomla + + - task: placeholder-joomla + + - task: utils:zip + vars: + cwd: dist/joomla + src: '**' + dest: dist/{{ .NAME }}-{{ .VERSION }}.zip + + #- defer: + # task: clear-dist-joomla + + build-wordpress: + cmds: + - task: utils:copy + vars: + cwd: build/wordpress + src: '*.php' + dest: dist/wordpress + + - task: copy-module + vars: + SYSTEM: wordpress + + - task: copy-elements + vars: + SYSTEM: wordpress + + - task: placeholder-wordpress + + - task: utils:zip + vars: + cwd: dist/wordpress + src: '**' + dest: dist/wp-{{ .NAME }}-{{ .VERSION }}.zip + + - defer: + task: clear-dist-wordpress + + copy-module: + internal: true + cmds: + - task: utils:copy + vars: + src: 'bootstrap.php' + dest: dist/{{ .SYSTEM }} + + copy-elements: + internal: true + cmds: + - task: utils:copy + vars: + cwd: elements + src: '**' + dest: dist/{{ .SYSTEM }}/elements + + placeholder-joomla: + internal: true + cmds: - task: utils:placeholder vars: src: 'dist/joomla/**/*.xml' @@ -40,15 +110,9 @@ tasks: "NAME" "{{ .NAME }}" "VERSION" "{{ .VERSION }}" - copy-wordpress: + placeholder-wordpress: internal: true cmds: - - task: utils:copy - vars: - cwd: build/wordpress - src: '*.php' - dest: dist/wordpress - - task: utils:placeholder vars: src: dist/wordpress/{{ .NAME }}.php @@ -65,65 +129,54 @@ tasks: "NAME" "{{ .NAME }}" "VERSION" "{{ .VERSION }}" - remove-dist-joomla: + clear-dist-joomla: internal: true cmds: - task: utils:remove vars: src: dist/joomla - remove-dist-wordpress: + clear-dist-wordpress: internal: true cmds: - task: utils:remove vars: src: dist/wordpress - build-joomla: - deps: - - copy-joomla - cmds: - - task: utils:zip - vars: - cwd: dist/joomla - src: '**' - dest: dist/{{ .NAME }}-{{ .VERSION }}.zip - - defer: - task: remove-dist-joomla - - build-wordpress: - deps: - - copy-wordpress + setup-joomla: cmds: - - task: utils:zip + - task: utils:copy vars: - cwd: dist/wordpress + cwd: build/joomla src: '**' - dest: dist/wp-{{ .NAME }}-{{ .VERSION }}.zip - - defer: - task: remove-dist-wordpress + dest: dist/joomla - build: - deps: - - build-joomla - - build-wordpress + - task: placeholder-joomla - setup-joomla: - deps: - - copy-dist-joomla - cmds: - task: utils:copy vars: cwd: dist/joomla src: '**' - dest: ../joomla/plugins + dest: ./ + + - defer: + task: clear-dist-joomla setup-wordpress: - deps: - - copy-dist-wordpress cmds: + - task: utils:copy + vars: + cwd: build/wordpress + src: '*.php' + dest: dist/wordpress + + - task: placeholder-wordpress + - task: utils:copy vars: cwd: dist/wordpress src: '**' - dest: ../wordpress/wp-content/plugins + dest: ./ + + - defer: + task: clear-dist-wordpress