From 4c1e6f5cf9cccc80749fbed0db8aeb541c8a6dec Mon Sep 17 00:00:00 2001 From: NEKGod <1559096467@qq.com> Date: Wed, 17 Apr 2024 14:49:41 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E7=94=9F=E6=88=90mine.json=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=AF=E8=A7=86=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app-store/src/Command/CreateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app-store/src/Command/CreateCommand.php b/src/app-store/src/Command/CreateCommand.php index a1c43b5c..176ec741 100644 --- a/src/app-store/src/Command/CreateCommand.php +++ b/src/app-store/src/Command/CreateCommand.php @@ -94,7 +94,7 @@ public function createMineJson(string $path, string $name, PluginTypeEnum $plugi ]; } - $output = json_encode($output, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE, 512); + $output = json_encode($output, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE, 512); file_put_contents($path . '/mine.json', $output); $this->output->success(sprintf('%s 创建成功', $path . '/mine.json')); } From 042ea74b3146719891f25f3de0ad3a09febd04ce Mon Sep 17 00:00:00 2001 From: NEKGod <1559096467@qq.com> Date: Wed, 17 Apr 2024 15:28:42 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0mine-extension:create?= =?UTF-8?q?=EF=BC=8Cname=E5=BF=85=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app-store/src/Command/CreateCommand.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app-store/src/Command/CreateCommand.php b/src/app-store/src/Command/CreateCommand.php index 176ec741..4d7f6597 100644 --- a/src/app-store/src/Command/CreateCommand.php +++ b/src/app-store/src/Command/CreateCommand.php @@ -30,6 +30,10 @@ public function __invoke() $name = $this->input->getOption('name'); $type = $this->input->getOption('type') ?? 'mix'; $type = PluginTypeEnum::fromValue($type); + if (empty($name)) { + $this->output->error("Plugin name is empty"); + return; + } if ($type === null) { $this->output->error('Plugin type is empty'); return; From 6fed885fd92ddbf255d3a648be1a15437b97e03a Mon Sep 17 00:00:00 2001 From: NEKGod <1559096467@qq.com> Date: Wed, 17 Apr 2024 17:13:50 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E7=94=9F=E6=88=90=E4=B8=BAPlugin=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=9B=E5=BB=BAweb=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app-store/src/Command/CreateCommand.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app-store/src/Command/CreateCommand.php b/src/app-store/src/Command/CreateCommand.php index 4d7f6597..1c87ead6 100644 --- a/src/app-store/src/Command/CreateCommand.php +++ b/src/app-store/src/Command/CreateCommand.php @@ -75,11 +75,12 @@ public function createMineJson(string $path, string $name, PluginTypeEnum $plugi ], ]; if ($pluginType === PluginTypeEnum::Backend || $pluginType === PluginTypeEnum::Mix) { - $namespace = 'Mine\\' . Str::snake($author) . '\\' . Str::snake($name); + $namespace = 'Plugin\\' . Str::studly($name); $this->createInstallScript($namespace, $path); $this->createUninstallScript($namespace, $path); $this->createConfigProvider($namespace, $path); + $this->createViewScript($namespace, $path); $output->composer = [ 'require' => [], 'psr-4' => [ @@ -127,6 +128,11 @@ public function createUninstallScript(string $namespace, string $path): void $this->output->success(sprintf('%s Created Successfully', $installScriptPath)); } + private function createViewScript(string $namespace, string $path): void + { + @mkdir($path. '/web', 0775); + } + public function buildStub(string $stub, array $replace): string { $stubPath = $this->getStubDirectory() . '/' . $stub . '.stub'; From 0870201b66cc3977bc590769be74e859a8bede19 Mon Sep 17 00:00:00 2001 From: NEKGod <1559096467@qq.com> Date: Wed, 17 Apr 2024 17:26:05 +0800 Subject: [PATCH 4/6] cs-edit --- src/app-store/src/Command/CreateCommand.php | 62 +++++++++++---------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/src/app-store/src/Command/CreateCommand.php b/src/app-store/src/Command/CreateCommand.php index 1c87ead6..f6f4d74e 100644 --- a/src/app-store/src/Command/CreateCommand.php +++ b/src/app-store/src/Command/CreateCommand.php @@ -14,6 +14,8 @@ use Hyperf\Command\Annotation\Command; use Mine\Helper\Str; +use RuntimeException; +use stdClass; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Xmo\AppStore\Enums\PluginTypeEnum; @@ -48,22 +50,17 @@ public function __invoke() $pluginPath, $pluginPath . '/src', $pluginPath . '/Database', ]; foreach ($createDirectors as $directory) { - if (! mkdir($directory, 0755, true) && ! is_dir($directory)) { - throw new \RuntimeException(sprintf('Directory "%s" was not created', $directory)); + if (!mkdir($directory, 0755, true) && !is_dir($directory)) { + throw new RuntimeException(sprintf('Directory "%s" was not created', $directory)); } } $this->createMineJson($pluginPath, $name, $type); } - public function commandName(): string - { - return 'create'; - } - public function createMineJson(string $path, string $name, PluginTypeEnum $pluginType): void { - $output = new \stdClass(); + $output = new stdClass(); $output->name = $name; $output->version = '1.0.0'; $output->type = $pluginType->value; @@ -104,14 +101,6 @@ public function createMineJson(string $path, string $name, PluginTypeEnum $plugi $this->output->success(sprintf('%s 创建成功', $path . '/mine.json')); } - public function createConfigProvider(string $namespace, string $path): void - { - $installScript = $this->buildStub('ConfigProvider', compact('namespace')); - $installScriptPath = $path . '/src/ConfigProvider.php'; - file_put_contents($installScriptPath, $installScript); - $this->output->success(sprintf('%s Created Successfully', $installScriptPath)); - } - public function createInstallScript(string $namespace, string $path): void { $installScript = $this->buildStub('InstallScript', compact('namespace')); @@ -120,6 +109,24 @@ public function createInstallScript(string $namespace, string $path): void $this->output->success(sprintf('%s Created Successfully', $installScriptPath)); } + public function buildStub(string $stub, array $replace): string + { + $stubPath = $this->getStubDirectory() . '/' . $stub . '.stub'; + if (!file_exists($stubPath)) { + throw new RuntimeException(sprintf('File %s does not exist', $stubPath)); + } + $stubBody = file_get_contents($stubPath); + foreach ($replace as $key => $value) { + $stubBody = str_replace('%' . $key . '%', $value, $stubBody); + } + return $stubBody; + } + + public function getStubDirectory(): string + { + return realpath(__DIR__) . '/Stub'; + } + public function createUninstallScript(string $namespace, string $path): void { $installScript = $this->buildStub('UninstallScript', compact('namespace')); @@ -128,27 +135,22 @@ public function createUninstallScript(string $namespace, string $path): void $this->output->success(sprintf('%s Created Successfully', $installScriptPath)); } - private function createViewScript(string $namespace, string $path): void + public function createConfigProvider(string $namespace, string $path): void { - @mkdir($path. '/web', 0775); + $installScript = $this->buildStub('ConfigProvider', compact('namespace')); + $installScriptPath = $path . '/src/ConfigProvider.php'; + file_put_contents($installScriptPath, $installScript); + $this->output->success(sprintf('%s Created Successfully', $installScriptPath)); } - public function buildStub(string $stub, array $replace): string + private function createViewScript(string $namespace, string $path): void { - $stubPath = $this->getStubDirectory() . '/' . $stub . '.stub'; - if (! file_exists($stubPath)) { - throw new \RuntimeException(sprintf('File %s does not exist', $stubPath)); - } - $stubBody = file_get_contents($stubPath); - foreach ($replace as $key => $value) { - $stubBody = str_replace('%' . $key . '%', $value, $stubBody); - } - return $stubBody; + !is_dir($path . '/web') && mkdir($path . '/web', 0775); } - public function getStubDirectory(): string + public function commandName(): string { - return realpath(__DIR__) . '/Stub'; + return 'create'; } protected function configure() From f4c22b91dbb8a5b72a785ece8b35a2580330074f Mon Sep 17 00:00:00 2001 From: NEKGod <1559096467@qq.com> Date: Wed, 17 Apr 2024 17:41:14 +0800 Subject: [PATCH 5/6] csfix --- src/app-store/src/Command/CreateCommand.php | 24 ++++++++++----------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/app-store/src/Command/CreateCommand.php b/src/app-store/src/Command/CreateCommand.php index f6f4d74e..241b16e9 100644 --- a/src/app-store/src/Command/CreateCommand.php +++ b/src/app-store/src/Command/CreateCommand.php @@ -14,8 +14,6 @@ use Hyperf\Command\Annotation\Command; use Mine\Helper\Str; -use RuntimeException; -use stdClass; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Xmo\AppStore\Enums\PluginTypeEnum; @@ -33,7 +31,7 @@ public function __invoke() $type = $this->input->getOption('type') ?? 'mix'; $type = PluginTypeEnum::fromValue($type); if (empty($name)) { - $this->output->error("Plugin name is empty"); + $this->output->error('Plugin name is empty'); return; } if ($type === null) { @@ -50,8 +48,8 @@ public function __invoke() $pluginPath, $pluginPath . '/src', $pluginPath . '/Database', ]; foreach ($createDirectors as $directory) { - if (!mkdir($directory, 0755, true) && !is_dir($directory)) { - throw new RuntimeException(sprintf('Directory "%s" was not created', $directory)); + if (! mkdir($directory, 0755, true) && ! is_dir($directory)) { + throw new \RuntimeException(sprintf('Directory "%s" was not created', $directory)); } } @@ -60,7 +58,7 @@ public function __invoke() public function createMineJson(string $path, string $name, PluginTypeEnum $pluginType): void { - $output = new stdClass(); + $output = new \stdClass(); $output->name = $name; $output->version = '1.0.0'; $output->type = $pluginType->value; @@ -112,8 +110,8 @@ public function createInstallScript(string $namespace, string $path): void public function buildStub(string $stub, array $replace): string { $stubPath = $this->getStubDirectory() . '/' . $stub . '.stub'; - if (!file_exists($stubPath)) { - throw new RuntimeException(sprintf('File %s does not exist', $stubPath)); + if (! file_exists($stubPath)) { + throw new \RuntimeException(sprintf('File %s does not exist', $stubPath)); } $stubBody = file_get_contents($stubPath); foreach ($replace as $key => $value) { @@ -143,11 +141,6 @@ public function createConfigProvider(string $namespace, string $path): void $this->output->success(sprintf('%s Created Successfully', $installScriptPath)); } - private function createViewScript(string $namespace, string $path): void - { - !is_dir($path . '/web') && mkdir($path . '/web', 0775); - } - public function commandName(): string { return 'create'; @@ -161,4 +154,9 @@ protected function configure() $this->addOption('description', 'desc', InputOption::VALUE_OPTIONAL, 'Plug-in Introduction'); $this->addOption('author', 'author', InputOption::VALUE_OPTIONAL, 'Plugin Author Information'); } + + private function createViewScript(string $namespace, string $path): void + { + ! is_dir($path . '/web') && mkdir($path . '/web', 0775); + } } From 14d5160cf9a07a4c717de51806dd49cc3606e35c Mon Sep 17 00:00:00 2001 From: NEKGod <1559096467@qq.com> Date: Thu, 18 Apr 2024 10:33:17 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=8F=92=E4=BB=B6web?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=94=9F=E6=88=90=E4=BD=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E7=94=9F=E6=88=90=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app-store/src/Command/CreateCommand.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/app-store/src/Command/CreateCommand.php b/src/app-store/src/Command/CreateCommand.php index 241b16e9..671a5666 100644 --- a/src/app-store/src/Command/CreateCommand.php +++ b/src/app-store/src/Command/CreateCommand.php @@ -45,7 +45,7 @@ public function __invoke() return; } $createDirectors = [ - $pluginPath, $pluginPath . '/src', $pluginPath . '/Database', + $pluginPath, $pluginPath . '/src', $pluginPath . '/Database', $pluginPath . '/Database/Migrations', $pluginPath . '/Database/Seeder', $pluginPath . '/web', ]; foreach ($createDirectors as $directory) { if (! mkdir($directory, 0755, true) && ! is_dir($directory)) { @@ -75,7 +75,6 @@ public function createMineJson(string $path, string $name, PluginTypeEnum $plugi $this->createInstallScript($namespace, $path); $this->createUninstallScript($namespace, $path); $this->createConfigProvider($namespace, $path); - $this->createViewScript($namespace, $path); $output->composer = [ 'require' => [], 'psr-4' => [ @@ -154,9 +153,4 @@ protected function configure() $this->addOption('description', 'desc', InputOption::VALUE_OPTIONAL, 'Plug-in Introduction'); $this->addOption('author', 'author', InputOption::VALUE_OPTIONAL, 'Plugin Author Information'); } - - private function createViewScript(string $namespace, string $path): void - { - ! is_dir($path . '/web') && mkdir($path . '/web', 0775); - } }