Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 33 additions & 23 deletions src/app-store/src/Command/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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' => [
Expand All @@ -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'));
Expand All @@ -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';
Expand All @@ -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');
Expand All @@ -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);
}
}