Skip to content

Commit 781683a

Browse files
authored
Merge pull request #19 from mineadmin/2.0-dev
Mine App Store Implementation
2 parents 49d1ea7 + 60bc5b0 commit 781683a

23 files changed

+993
-148
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"ext-pdo_mysql": "*",
6262
"ext-redis": "*",
6363
"ext-swoole": ">=5.0",
64+
"ext-zip": "*",
6465
"doctrine/dbal": "^3.1",
6566
"hyperf/amqp": "~3.1.0",
6667
"hyperf/async-queue": "~3.1.0",

src/app-store/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"description": "Mineadmin 2.0 AppStore Extension",
44
"type": "library",
55
"require": {
6-
"xmo/mine-core": "v2.0.x-dev",
7-
"xmo/mine-service": "v2.0.x-dev"
6+
"hyperf/translation": "~3.1.0",
7+
"ext-zip": "*"
88
},
99
"require-dev": {
1010
"pestphp/pest": "^2.33"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact root@imoi.cn
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
use function Hyperf\Support\env;
13+
14+
return [
15+
/*
16+
* Whether to enable the Extended Store feature,
17+
* it is recommended to disable it for production environments.
18+
* Default with APP_DEBUG environment on off
19+
*
20+
* 是否开启扩展商店功能,生产环境建议禁用。默认随着 APP_DEBUG 环境开启关闭
21+
*/
22+
'enable' => env('APP_DEBUG', false),
23+
/*
24+
* MineAdmin
25+
*/
26+
'access_token' => env('MINE_ACCESS_TOKEN'),
27+
28+
/*
29+
* The root directory where the front-end code resides.
30+
*
31+
* 前端代码所在根目录.
32+
*/
33+
'front_directory' => BASE_PATH . '/web',
34+
'composer' => [
35+
/*
36+
* composer executes the program directly from composer by default,
37+
* but if there is an environment restriction,
38+
* you can specify something like /usr/bin/composer.
39+
*
40+
*
41+
* composer 执行程序 默认直接是 composer 如果有环境限制 可以指定比如 /usr/bin/composer
42+
*/
43+
'bin' => 'composer',
44+
],
45+
'front-tool' => [
46+
/*
47+
* Front-end package management execution tools Optional npm yarn pnpm, default npm is used
48+
*
49+
*
50+
* 前端包管理执行工具 可选 npm yarn pnpm,默认使用 npm
51+
*/
52+
'type' => 'npm',
53+
/*
54+
* The default directory for executing programs is npm,
55+
* but if you don't have the npm environment variable configured,
56+
* you can manually specify the program to execute, e.g. /usr/local/npm/bin/npm.
57+
*
58+
*
59+
* 执行程序所在目录 默认是直接执行 npm, 如果没有配置 npm 环境变量 则可以手动指定 执行程序 例如 /usr/local/npm/bin/npm
60+
*/
61+
'bin' => 'npm',
62+
],
63+
];

src/app-store/publish/trans/en.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* This file is part of MineAdmin.
46
*
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact root@imoi.cn
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Xmo\AppStore\Command;
14+
15+
use Hyperf\Command\Annotation\Command;
16+
use Hyperf\Command\Command as Base;
17+
use Hyperf\Context\ApplicationContext;
18+
use Symfony\Component\Console\Input\InputOption;
19+
use Xmo\AppStore\Service\AppStoreService;
20+
21+
#[Command]
22+
class ExtensionDownloadCommand extends Base
23+
{
24+
protected ?string $name = 'mine-extension:download';
25+
26+
protected string $description = 'Download the specified remote plug-in file locally';
27+
28+
public function __invoke()
29+
{
30+
$name = $this->input->getOption('name');
31+
$appStoreService = ApplicationContext::getContainer()->get(AppStoreService::class);
32+
$appStoreService->download($name);
33+
$this->output->success('Plugin Downloaded Successfully');
34+
}
35+
36+
protected function configure()
37+
{
38+
$this->addOption('name', 'n', InputOption::VALUE_REQUIRED, 'Plug-in Name');
39+
}
40+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact root@imoi.cn
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Xmo\AppStore\Command;
14+
15+
use Hyperf\Command\Annotation\Command;
16+
use Hyperf\Command\Command as Base;
17+
use Nette\Utils\FileSystem;
18+
use Symfony\Component\Console\Input\InputOption;
19+
20+
#[Command]
21+
class ExtensionInitialCommand extends Base
22+
{
23+
protected ?string $name = 'mine-extension:initial';
24+
25+
protected string $description = 'MineAdmin Extended Store Initialization Command Line';
26+
27+
public function __invoke(): void
28+
{
29+
$this->output->info('Start initialization');
30+
$this->output->info('Publishing multilingual documents');
31+
$publishPath = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'publish';
32+
$languages = BASE_PATH . '/storage/languages';
33+
FileSystem::copy($publishPath . '/trans/en.php', $languages . '/en/app-store.php');
34+
FileSystem::copy($publishPath . '/trans/zh-CN.php', $languages . '/zh_CN/app-store.php');
35+
$this->output->success('Language file published successfully');
36+
$this->output->info('Publishing Configuration Files');
37+
FileSystem::copy($publishPath . '/mine-extension.php', BASE_PATH . '/config/autoload/mine-extension.php');
38+
$this->output->success('Publishing Configuration File Succeeded');
39+
$this->output->warning('
40+
接下来选择开发模式,
41+
默认是用 ./web 目录作为前端源码所在目录,
42+
也可以配置 mine-extension.php 配置文件
43+
手动指定前端源代码开发目录');
44+
$this->output->warning('
45+
Next, select the development mode.
46+
The default is to use . /web directory as the front-end source code directory.
47+
You can also configure the mine-extension.php configuration file
48+
Manually specify the front-end source code development directory');
49+
}
50+
51+
protected function configure()
52+
{
53+
$this->addOption('force', 'f', InputOption::VALUE_NONE, 'Whether or not coverage is mandatory');
54+
}
55+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact root@imoi.cn
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Xmo\AppStore\Command;
14+
15+
use Hyperf\Command\Annotation\Command;
16+
use Hyperf\Command\Command as Base;
17+
use Symfony\Component\Console\Input\InputArgument;
18+
use Symfony\Component\Console\Input\InputOption;
19+
use Xmo\AppStore\Plugin;
20+
use Xmo\AppStore\Service\PluginService;
21+
22+
#[Command]
23+
class ExtensionInstallCommand extends Base
24+
{
25+
protected ?string $name = 'mine-extension:install';
26+
27+
protected string $description = 'Installing Plugin Commands';
28+
29+
public function __construct(
30+
private readonly PluginService $pluginService
31+
) {
32+
parent::__construct();
33+
}
34+
35+
public function __invoke()
36+
{
37+
$path = $this->input->getArgument('path');
38+
$yes = $this->input->getOption('yes');
39+
$info = Plugin::read($path);
40+
41+
$headers = ['Extension name', 'author', 'description', 'homepage'];
42+
$rows[] = [
43+
$info['name'],
44+
is_string($info['author']) ? $info['author'] : ($info['author'][0]['name'] ?? '--'),
45+
$info['description'],
46+
$info['homepage'] ?? '--',
47+
];
48+
$this->table($headers, $rows);
49+
$confirm = $yes ?: $this->confirm('Enter to start the installation', true);
50+
if (! $confirm) {
51+
$this->output->success('Installation has been successfully canceled');
52+
return;
53+
}
54+
Plugin::install($path);
55+
$this->output->success(sprintf('Plugin %s installed successfully', $path));
56+
}
57+
58+
protected function configure()
59+
{
60+
$this->addArgument('path', InputArgument::REQUIRED, 'Plug-in Catalog (relative path)');
61+
$this->addOption('yes', 'y', InputOption::VALUE_NONE, 'silent installation');
62+
}
63+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact root@imoi.cn
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Xmo\AppStore\Command;
14+
15+
use Hyperf\Command\Annotation\Command;
16+
use Hyperf\Command\Command as Base;
17+
use Hyperf\Context\ApplicationContext;
18+
use Symfony\Component\Console\Input\InputOption;
19+
use Xmo\AppStore\Service\AppStoreService;
20+
21+
#[Command]
22+
class ExtensionListCommand extends Base
23+
{
24+
protected ?string $name = 'mine-extension:list';
25+
26+
protected string $description = 'View a list of remote app store plugins';
27+
28+
public function __invoke()
29+
{
30+
$params = [];
31+
$params['type'] = $this->input->getOption('type');
32+
if (empty($params['type'])) {
33+
$type = 'all';
34+
}
35+
if ($title = $this->input->getOption('title')) {
36+
$params['title'] = $title;
37+
}
38+
$appStoreService = ApplicationContext::getContainer()->get(AppStoreService::class);
39+
$result = $appStoreService->list($params);
40+
$headers = [
41+
'extensionName', 'description', 'author', 'homePage', 'status',
42+
];
43+
$this->output->table($headers, $result);
44+
}
45+
46+
protected function configure()
47+
{
48+
$this->addOption('type', 't', InputOption::VALUE_OPTIONAL, 'Type of plugin to query');
49+
$this->addOption('title', 'title', InputOption::VALUE_OPTIONAL, 'Plugin Title');
50+
}
51+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact root@imoi.cn
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Xmo\AppStore\Command;
14+
15+
use Hyperf\Command\Annotation\Command;
16+
use Hyperf\Command\Command as Base;
17+
use Xmo\AppStore\Plugin;
18+
19+
#[Command]
20+
class ExtensionLocalListCommand extends Base
21+
{
22+
protected ?string $name = 'mine-extension:local-list';
23+
24+
protected string $description = 'List all locally installed extensions(列出本地所有已经安装的扩展)';
25+
26+
public function __invoke()
27+
{
28+
$list = Plugin::getPluginJsonPaths();
29+
30+
$headers = [
31+
'extensionName', 'description', 'author', 'homePage', 'status',
32+
];
33+
$rows = [];
34+
foreach ($list as $splFileInfo) {
35+
$info = Plugin::read($splFileInfo->getPath());
36+
$current = [];
37+
$current[] = $info['name'];
38+
$current[] = $info['description'];
39+
if (is_string($info['author'])) {
40+
$current[] = $info['author'];
41+
} else {
42+
$current[] = $info['author'][0]['name'] ?? '--';
43+
}
44+
$current[] = $info['homePage'] ?? '--';
45+
$current[] = $info['status'] ? 'installed' : 'uninstalled';
46+
$rows[] = $current;
47+
}
48+
$this->table($headers, $rows);
49+
}
50+
}

0 commit comments

Comments
 (0)