Skip to content

Commit

Permalink
refactor: createPluginCommand creates Taskfile
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikbehncke committed Jul 29, 2024
1 parent 4e39933 commit 213e22a
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/CreatePluginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$cwd = getcwd();

$name = $input->getArgument('name');
$path = Path::join($cwd, 'build');

$fn = [$this->getHelper('question'), 'ask'];
$ask = $this->partial($fn, $input, $output);
Expand All @@ -47,10 +46,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'TITLE' => $ask(new Question('Enter plugin title: ', $name)),
];

$questions = $variables + [
'DESCRIPTION' => $ask(new Question('Enter plugin description: ')),
'AUTHOR' => $ask(new Question('Enter author name: ')),
'AUTHOREMAIL' => $ask(new Question('Enter author email: ')),
'AUTHORURL' => $ask(new Question('Enter author url: ')),
];

foreach ($finder->files() as $file) {
$fs->dumpFile(
strtr("{$path}/{$file->getRelativePathname()}", $filemap),
Str::placeholder($file->getContents(), $variables),
strtr("{$cwd}/{$file->getRelativePathname()}", $filemap),
Str::placeholder(
$file->getContents(),
$file->getBasename() === 'Taskfile.yml' ? $questions : $variables,
),
);
}

Expand Down
129 changes: 129 additions & 0 deletions src/stubs/plugin/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
version: '3'

includes:
utils: vendor/yootheme/starter-utils

vars:
NAME: '{{ TITLE }}'
VERSION: '0.0.1'
DESCRIPTION: '{{ DESCRIPTION }}'
DATE: '{{ now | date "2006-01-02" }}'
COPYRIGHT: 'Copyright (C)'
LICENSE: 'GNU General Public License'
AUTHOR: '{{ AUTHOR }}'
AUTHOREMAIL: '{{ AUTHOREMAIL }}'
AUTHORURL: '{{ AUTHORURL }}'

tasks:
copy-joomla:
internal: true
cmds:
- task: utils:copy
vars:
cwd: build/joomla
src: '**'
dest: dist/joomla

- task: utils:placeholder
vars:
src: 'dist/joomla/**/*.xml'
replace:
ref: >
dict
"AUTHOR" "{{ .AUTHOR }}"
"AUTHOREMAIL" "{{ .AUTHOREMAIL }}"
"AUTHORURL" "{{ .AUTHORURL }}"
"COPYRIGHT" "{{ .COPYRIGHT }}"
"DATE" "{{ .DATE }}"
"DESCRIPTION" "{{ .DESCRIPTION }}"
"LICENSE" "{{ .LICENSE }}"
"NAME" "{{ .NAME }}"
"VERSION" "{{ .VERSION }}"
copy-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
replace:
ref: >
dict
"AUTHOR" "{{ .AUTHOR }}"
"AUTHOREMAIL" "{{ .AUTHOREMAIL }}"
"AUTHORURL" "{{ .AUTHORURL }}"
"COPYRIGHT" "{{ .COPYRIGHT }}"
"DATE" "{{ .DATE }}"
"DESCRIPTION" "{{ .DESCRIPTION }}"
"LICENSE" "{{ .LICENSE }}"
"NAME" "{{ .NAME }}"
"VERSION" "{{ .VERSION }}"
remove-dist-joomla:
internal: true
cmds:
- task: utils:remove
vars:
src: dist/joomla

remove-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
cmds:
- task: utils:zip
vars:
cwd: dist/wordpress
src: '**'
dest: dist/wp-{{ .NAME }}-{{ .VERSION }}.zip
- defer:
task: remove-dist-wordpress

build:
deps:
- build-joomla
- build-wordpress

setup-joomla:
deps:
- copy-dist-joomla
cmds:
- task: utils:copy
vars:
cwd: dist/joomla
src: '**'
dest: ../joomla/plugins

setup-wordpress:
deps:
- copy-dist-wordpress
cmds:
- task: utils:copy
vars:
cwd: dist/wordpress
src: '**'
dest: ../wordpress/wp-content/plugins
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 213e22a

Please sign in to comment.