diff --git a/src/app-store/src/Command/CreateCommand.php b/src/app-store/src/Command/CreateCommand.php index a1c43b5c..241b16e9 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; @@ -52,11 +56,6 @@ public function __invoke() $this->createMineJson($pluginPath, $name, $type); } - public function commandName(): string - { - return 'create'; - } - public function createMineJson(string $path, string $name, PluginTypeEnum $pluginType): void { $output = new \stdClass(); @@ -71,11 +70,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' => [ @@ -94,19 +94,11 @@ 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')); } - 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')); @@ -115,14 +107,6 @@ public function createInstallScript(string $namespace, string $path): void $this->output->success(sprintf('%s Created Successfully', $installScriptPath)); } - public function createUninstallScript(string $namespace, string $path): void - { - $installScript = $this->buildStub('UninstallScript', compact('namespace')); - $installScriptPath = $path . '/src/UninstallScript.php'; - file_put_contents($installScriptPath, $installScript); - $this->output->success(sprintf('%s Created Successfully', $installScriptPath)); - } - public function buildStub(string $stub, array $replace): string { $stubPath = $this->getStubDirectory() . '/' . $stub . '.stub'; @@ -141,6 +125,27 @@ public function getStubDirectory(): string return realpath(__DIR__) . '/Stub'; } + public function createUninstallScript(string $namespace, string $path): void + { + $installScript = $this->buildStub('UninstallScript', compact('namespace')); + $installScriptPath = $path . '/src/UninstallScript.php'; + file_put_contents($installScriptPath, $installScript); + $this->output->success(sprintf('%s Created Successfully', $installScriptPath)); + } + + 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 commandName(): string + { + return 'create'; + } + protected function configure() { $this->addArgument('path', InputArgument::REQUIRED, 'Plugin Path'); @@ -149,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); + } }