-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev'
- Loading branch information
Showing
10 changed files
with
329 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
namespace RockShell; | ||
|
||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
use function ProcessWire\wire; | ||
|
||
/** | ||
* Create a new module with all necessary files | ||
*/ | ||
class ModuleCreate extends Command | ||
{ | ||
|
||
public function config() | ||
{ | ||
$this->setDescription("Create a new module with all necessary files") | ||
->addOption('name', null, InputOption::VALUE_OPTIONAL, "Module name"); | ||
} | ||
|
||
private function copyFiles($name): void | ||
{ | ||
$src = __DIR__ . '/../stubs/module-create'; | ||
$dst = wire()->config->paths->siteModules . $name; | ||
$replace = [ | ||
"MyModule" => $name, | ||
"mymodule" => strtolower($name), | ||
]; | ||
wire()->files->mkdir($dst); | ||
wire()->files->copy( | ||
$src . '/.github', | ||
$dst . '/.github', | ||
); | ||
wire()->files->copy( | ||
$src . '/package.json', | ||
$dst, | ||
); | ||
wire()->files->copy( | ||
$src . '/.htaccess', | ||
$dst, | ||
); | ||
$this->stubPopulate( | ||
$src . '/MyModule.info.php', | ||
$dst . "/$name.info.php", | ||
$replace, | ||
quiet: true, | ||
brackets: false, | ||
); | ||
$this->stubPopulate( | ||
$src . '/MyModule.module.txt', | ||
$dst . "/$name.module.php", | ||
$replace, | ||
quiet: true, | ||
brackets: false, | ||
); | ||
$this->stubPopulate( | ||
$src . '/readme.md', | ||
$dst . "/readme.md", | ||
$replace, | ||
quiet: true, | ||
brackets: false, | ||
); | ||
} | ||
|
||
private function getDir($name): string | ||
{ | ||
return wire()->config->paths->siteModules . $name; | ||
} | ||
|
||
public function handle() | ||
{ | ||
$types = ['Module', 'Process Module', 'Fieldtype Module', 'Inputfield Module']; | ||
$type = $this->choice('Type of module', $types, 0); | ||
if ($type !== 'Module') { | ||
$this->warn("Sorry, not implemented yet. What a great opportunity for a PR!"); | ||
return $this->handle(); | ||
} | ||
$name = $this->moduleName(); | ||
$this->copyFiles($name); | ||
|
||
$dir = $this->getDir($name); | ||
$this->success("Module created at $dir"); | ||
$this->goodbye(); | ||
|
||
return self::SUCCESS; | ||
} | ||
|
||
private function moduleName($name = null, $reset = false) | ||
{ | ||
if (!$name) $name = $this->option('name'); | ||
if (!$name || $reset) $name = $this->ask("Please enter your module's name"); | ||
$name = ucfirst(wire()->sanitizer->camelCase($name)); | ||
|
||
if (!$name) return $this->moduleName(reset: $reset); | ||
|
||
if (!$this->confirm("Confirm module name: $name", true)) { | ||
return $this->moduleName(); | ||
} | ||
|
||
// check if it exists | ||
$dir = $this->getDir($name); | ||
if (is_dir($dir)) { | ||
$this->warn("$dir already exists"); | ||
|
||
if ($this->confirm("Create module in this folder? This will overwrite existing files.")) { | ||
return $name; | ||
} | ||
|
||
return $this->moduleName(reset: true); | ||
} | ||
|
||
return $name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace RockShell; | ||
|
||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
use function ProcessWire\wire; | ||
|
||
/** | ||
* Install a module | ||
*/ | ||
class ModuleInstall extends Command | ||
{ | ||
|
||
public function config() | ||
{ | ||
$this->setDescription("Install a module") | ||
->addOption('name', 'm', InputOption::VALUE_OPTIONAL, "Module name"); | ||
} | ||
|
||
public function handle() | ||
{ | ||
// load RockMigrations | ||
$rm = wire()->modules->get('RockMigrations'); | ||
if (!$rm) { | ||
$this->error("RockMigrations module not found"); | ||
return self::FAILURE; | ||
} | ||
|
||
// check name | ||
$name = $this->option('name'); | ||
while (!$name) $name = $this->ask("Please enter the module's name"); | ||
|
||
// install module | ||
$rm->installModule($name); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Releases | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
changelog: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: conventional Changelog Action | ||
id: changelog | ||
uses: TriPSs/conventional-changelog-action@v5 | ||
with: | ||
preset: "conventionalcommits" | ||
github-token: ${{ secrets.github_token }} | ||
# git-user-email: "[email protected]" | ||
|
||
- name: create release | ||
uses: actions/create-release@v1 | ||
if: ${{ steps.changelog.outputs.skipped == 'false' }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.github_token }} | ||
with: | ||
tag_name: ${{ steps.changelog.outputs.tag }} | ||
release_name: ${{ steps.changelog.outputs.tag }} | ||
body: ${{ steps.changelog.outputs.clean_changelog }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# block public access to all files | ||
# add exceptions as needed | ||
<IfModule mod_rewrite.c> | ||
RewriteEngine On | ||
|
||
# Example to allow access to js/css files in dst folder | ||
# RewriteCond %{REQUEST_FILENAME} !^.*/dst/.*\.(js|css)$ | ||
|
||
# 403 forbidden | ||
RewriteRule ^ - [F,L] | ||
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace ProcessWire; | ||
|
||
$info = [ | ||
'title' => 'MyModule', | ||
'version' => json_decode(file_get_contents(__DIR__ . "/package.json"))->version, | ||
'summary' => '', | ||
'autoload' => true, | ||
'singular' => true, | ||
'icon' => 'check', | ||
'requires' => [ | ||
'PHP>=8.1', | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace ProcessWire; | ||
|
||
function mymodule(): MyModule | ||
{ | ||
return wire()->modules->get('MyModule'); | ||
} | ||
|
||
// info / infoc | ||
class MyModule extends WireData implements Module, ConfigurableModule | ||
{ | ||
public function init() {} | ||
|
||
/** | ||
* Config inputfields | ||
* @param InputfieldWrapper $inputfields | ||
*/ | ||
public function getModuleConfigInputfields($inputfields) | ||
{ | ||
return $inputfields; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"version": "0.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# MyModule | ||
|