mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 22:55:36 +00:00
feat(Terminal):安装环境检查接口增加多种NPM包管理器的支持、版本对比类优化
This commit is contained in:
parent
344d3861b1
commit
23695262e8
@ -284,6 +284,9 @@ class Install extends Api
|
||||
$this->error('', [], 2);
|
||||
}
|
||||
|
||||
$packageManager = request()->post('manager', 'none');
|
||||
|
||||
// npm
|
||||
$npmVersion = Version::getVersion('npm');
|
||||
$npmVersionCompare = Version::compare(self::$needDependentVersion['npm'], $npmVersion);
|
||||
if (!$npmVersionCompare || !$npmVersion) {
|
||||
@ -303,6 +306,53 @@ class Install extends Api
|
||||
];
|
||||
}
|
||||
|
||||
// 包管理器
|
||||
if (in_array($packageManager, ['npm', 'cnpm', 'pnpm', 'yarn'])) {
|
||||
$pmVersion = Version::getVersion($packageManager);
|
||||
$pmVersionCompare = Version::compare(self::$needDependentVersion[$packageManager], $pmVersion);
|
||||
|
||||
if (!$pmVersion) {
|
||||
// 安装
|
||||
$pmVersionLink[] = [
|
||||
// 需要版本
|
||||
'name' => __('need') . ' >= ' . self::$needDependentVersion[$packageManager],
|
||||
'type' => 'text'
|
||||
];
|
||||
if ($npmVersionCompare) {
|
||||
$pmVersionLink[] = [
|
||||
// 点击安装
|
||||
'name' => __('Click Install %s', [$packageManager]),
|
||||
'title' => '',
|
||||
'type' => 'install-package-manager'
|
||||
];
|
||||
} else {
|
||||
$pmVersionLink[] = [
|
||||
// 请先安装npm
|
||||
'name' => __('Please install NPM first'),
|
||||
'type' => 'text'
|
||||
];
|
||||
}
|
||||
} elseif (!$pmVersionCompare) {
|
||||
// 版本不足
|
||||
$pmVersionLink[] = [
|
||||
// 需要版本
|
||||
'name' => __('need') . ' >= ' . self::$needDependentVersion[$packageManager],
|
||||
'type' => 'text'
|
||||
];
|
||||
$pmVersionLink[] = [
|
||||
// 请升级
|
||||
'name' => __('Please upgrade %s version', [$packageManager]),
|
||||
'type' => 'text'
|
||||
];
|
||||
}
|
||||
} elseif ($packageManager == 'ni') {
|
||||
$pmVersion = __('nothing');
|
||||
$pmVersionCompare = true;
|
||||
} else {
|
||||
$pmVersion = __('nothing');
|
||||
$pmVersionCompare = false;
|
||||
}
|
||||
|
||||
$cnpmVersion = Version::getCnpmVersion();
|
||||
$cnpmVersionCompare = Version::compare(self::$needDependentVersion['cnpm'], $cnpmVersion);
|
||||
if (!$cnpmVersionCompare || !$cnpmVersion) {
|
||||
@ -341,6 +391,7 @@ class Install extends Api
|
||||
];
|
||||
}
|
||||
|
||||
// nodejs
|
||||
$nodejsVersion = Version::getVersion('node');
|
||||
$nodejsVersionCompare = Version::compare(self::$needDependentVersion['node'], $nodejsVersion);
|
||||
if (!$nodejsVersionCompare || !$nodejsVersion) {
|
||||
@ -361,20 +412,20 @@ class Install extends Api
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'npm_version' => [
|
||||
'npm_version' => [
|
||||
'describe' => $npmVersion ? $npmVersion : __('Acquisition failed'),
|
||||
'state' => $npmVersionCompare ? self::$ok : self::$warn,
|
||||
'link' => $npmVersionLink ?? [],
|
||||
],
|
||||
'nodejs_version' => [
|
||||
'nodejs_version' => [
|
||||
'describe' => $nodejsVersion ? $nodejsVersion : __('Acquisition failed'),
|
||||
'state' => $nodejsVersionCompare ? self::$ok : self::$warn,
|
||||
'link' => $nodejsVersionLink ?? []
|
||||
],
|
||||
'cnpm_version' => [
|
||||
'describe' => $cnpmVersion ? $cnpmVersion : __('Acquisition failed'),
|
||||
'state' => $cnpmVersionCompare ? self::$ok : self::$warn,
|
||||
'link' => $cnpmVersionLink ?? []
|
||||
'npm_package_manager' => [
|
||||
'describe' => $pmVersion ? $pmVersion : __('Acquisition failed'),
|
||||
'state' => $pmVersionCompare ? self::$ok : self::$warn,
|
||||
'link' => $pmVersionLink ?? [],
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
@ -12,8 +12,7 @@ return [
|
||||
'disabled' => 'disabled',
|
||||
'Allow operation' => 'Allow operation',
|
||||
'Acquisition failed' => 'Check failed',
|
||||
'It is recommended to add cnpm. Click Install' => 'It is recommended to add cnpm. Click Install',
|
||||
'Click Install cnpm' => 'Click Install cnpm',
|
||||
'Click Install %s' => '点击安装%s',
|
||||
'Writable' => 'Writable',
|
||||
'No write permission' => 'No write permission',
|
||||
'already installed' => 'Already installed',
|
||||
@ -40,4 +39,6 @@ return [
|
||||
'Please install NPM first' => 'Please install NPM first',
|
||||
'Installation error:%s' => 'Installation error:%s',
|
||||
'Failed to switch package manager. Please modify the configuration file manually:%s' => 'Failed to switch package manager. Please modify the configuration file manually:%s',
|
||||
'Please upgrade %s version' => 'Please upgrade %s version',
|
||||
'nothing' => 'nothing',
|
||||
];
|
@ -12,8 +12,7 @@ return [
|
||||
'disabled' => '已禁用',
|
||||
'Allow operation' => '允许操作',
|
||||
'Acquisition failed' => '获取失败',
|
||||
'It is recommended to add cnpm. Click Install' => '建议添加cnpm,可点击安装',
|
||||
'Click Install cnpm' => '点击安装cnpm',
|
||||
'Click Install %s' => '点击安装%s',
|
||||
'Writable' => '可写',
|
||||
'No write permission' => '无写权限',
|
||||
'already installed' => '已安装',
|
||||
@ -40,4 +39,6 @@ return [
|
||||
'Please install NPM first' => '请先安装npm',
|
||||
'Installation error:%s' => '安装出错:%s',
|
||||
'Failed to switch package manager. Please modify the configuration file manually:%s' => '包管理器切换失败,请手动修改配置文件:%s',
|
||||
'Please upgrade %s version' => '请升级%s版本',
|
||||
'nothing' => '无',
|
||||
];
|
@ -34,6 +34,10 @@ class Version
|
||||
return true;
|
||||
}
|
||||
|
||||
// 丢弃'-'后面的内容
|
||||
if (strpos($v1, '-') !== false) $v1 = explode('-', $v1)[0];
|
||||
if (strpos($v2, '-') !== false) $v2 = explode('-', $v2)[0];
|
||||
|
||||
$v1 = explode('.', $v1);
|
||||
$v2 = explode('.', $v2);
|
||||
if (!is_array($v1) || !is_array($v2)) {
|
||||
|
Loading…
Reference in New Issue
Block a user