skhub-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +22 -0
- package/README.md +22 -0
- package/bin/cli.js +26 -0
- package/install.js +109 -0
- package/package.json +25 -0
package/README.en.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
## Skillhub CLI
|
|
2
|
+
English | [中文](README.md)
|
|
3
|
+
|
|
4
|
+
Skillhub CLI is a command line tool to install and use skillhub.
|
|
5
|
+
|
|
6
|
+
- Org: [Skillhub](https://skillhub.xin)
|
|
7
|
+
|
|
8
|
+
### Installation
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g skhub
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Usage
|
|
14
|
+
- get help
|
|
15
|
+
```bash
|
|
16
|
+
skhub --help
|
|
17
|
+
```
|
|
18
|
+
- install skill
|
|
19
|
+
```bash
|
|
20
|
+
skhub install <skill-name or skill-url>
|
|
21
|
+
```
|
|
22
|
+
- you can learn more about skhub and skillhub on [skillhub.xin](https://skillhub.xin/docs?id=start-use).
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
## Skillhub CLI
|
|
2
|
+
中文 | [English](README.en.md)
|
|
3
|
+
|
|
4
|
+
Skillhub CLI 是一款用于安装和使用 Skillhub客户端 的命令行工具(CLI)。
|
|
5
|
+
|
|
6
|
+
- 官网: [Skillhub](https://skillhub.xin)
|
|
7
|
+
|
|
8
|
+
### 安装
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g skhub
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### 使用
|
|
14
|
+
- 获取帮助
|
|
15
|
+
```bash
|
|
16
|
+
skhub --help
|
|
17
|
+
```
|
|
18
|
+
- 安装技能(skill)
|
|
19
|
+
```bash
|
|
20
|
+
skhub install <skill-name or skill-url>
|
|
21
|
+
```
|
|
22
|
+
- 你可以在 [skillhub.xin](https://skillhub.xin/docs?id=start-use) 学习更多关于 skhub和skillhub 的使用方法。
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawn } = require('child_process');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
// 确定二进制文件的位置 (通常在 node_modules 下的特定文件夹)
|
|
8
|
+
// 这里 install.js 把它下载到了 ./bin/native
|
|
9
|
+
const platform = process.platform === 'win32' ? 'windows' : process.platform;
|
|
10
|
+
const arch = os.arch(); // os.arch()才是系统架构
|
|
11
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
12
|
+
const binaryName = `skillhub-${platform}-${arch}${ext}`;
|
|
13
|
+
const binaryPath = path.join(__dirname, 'native', binaryName);
|
|
14
|
+
|
|
15
|
+
if (!fs.existsSync(binaryPath)) {
|
|
16
|
+
console.error(`Error: Binary not found at ${binaryPath}. Re-run npm install skhub.`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 启动二进制文件,并将当前进程的参数透传给它
|
|
21
|
+
const args = process.argv.slice(2);
|
|
22
|
+
const child = spawn(binaryPath, args, { stdio: 'inherit' });
|
|
23
|
+
|
|
24
|
+
child.on('close', code => {
|
|
25
|
+
process.exit(code);
|
|
26
|
+
});
|
package/install.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const zlib = require('zlib'); // .gz 提前预备
|
|
6
|
+
const AdmZip = require('adm-zip'); // .zip 提前预备
|
|
7
|
+
const axios = require('axios');
|
|
8
|
+
|
|
9
|
+
const platform = process.platform === 'win32' ? 'windows' : process.platform;
|
|
10
|
+
const arch = os.arch(); // os.arch()才是系统架构
|
|
11
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
12
|
+
const fileName = `skillhub-${platform}-${arch}${ext}`;
|
|
13
|
+
|
|
14
|
+
// 从https://gitee.com/skillhub/skillhub/raw/master/releases-npm-native.json 中获取最新版本
|
|
15
|
+
const releasesUrl = 'https://gitee.com/skillhub/skillhub/raw/master/releases-npm-native.json';
|
|
16
|
+
|
|
17
|
+
var latestVersion = '';
|
|
18
|
+
// 从 releases.json 中获取最新版本
|
|
19
|
+
https.get(releasesUrl, (response) => {
|
|
20
|
+
let data = '';
|
|
21
|
+
response.on('data', (chunk) => {
|
|
22
|
+
data += chunk;
|
|
23
|
+
});
|
|
24
|
+
response.on('end', () => {
|
|
25
|
+
console.log(data)
|
|
26
|
+
const releases = JSON.parse(data);
|
|
27
|
+
latestVersion = releases.version;
|
|
28
|
+
console.log(`Latest version: ${latestVersion}`);
|
|
29
|
+
support = releases.support; // key: os_arch, value: downloadUrl
|
|
30
|
+
const os_arch = `${platform}_${arch}`;
|
|
31
|
+
console.log(os_arch)
|
|
32
|
+
const downloadUrl = support[os_arch];
|
|
33
|
+
if (!downloadUrl) {
|
|
34
|
+
console.error(`Sorry, not support ${os_arch}`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
DownloadAndInstall(latestVersion, fileName);
|
|
38
|
+
});
|
|
39
|
+
}).on('error', (err) => {
|
|
40
|
+
console.error(`Failed to fetch releases: ${err.message}`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
function DownloadAndInstall(version, fileName) {
|
|
45
|
+
const downloadUrl = `https://gitee.com/skillhub/skillhub/releases/download/${version}/${version}_${fileName}`;
|
|
46
|
+
|
|
47
|
+
const targetDir = path.join(__dirname, 'bin', 'native');
|
|
48
|
+
const targetPath = path.join(targetDir, fileName);
|
|
49
|
+
|
|
50
|
+
// 确保目录存在
|
|
51
|
+
if (!fs.existsSync(targetDir)) {
|
|
52
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
console.log(`Downloading ${fileName}...`);
|
|
56
|
+
console.log(downloadUrl)
|
|
57
|
+
|
|
58
|
+
const file = fs.createWriteStream(targetPath);
|
|
59
|
+
|
|
60
|
+
axios({
|
|
61
|
+
method: 'get',
|
|
62
|
+
url: downloadUrl,
|
|
63
|
+
responseType: 'stream'
|
|
64
|
+
})
|
|
65
|
+
.then(function (response) {
|
|
66
|
+
console.log('download success\nstart install...')
|
|
67
|
+
|
|
68
|
+
let stream = response.data;
|
|
69
|
+
if (downloadUrl.endsWith('.gz')) {
|
|
70
|
+
stream = response.data.pipe(zlib.createGunzip());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
stream.pipe(file);
|
|
74
|
+
|
|
75
|
+
file.on('finish', () => {
|
|
76
|
+
file.close();
|
|
77
|
+
|
|
78
|
+
if (fileName.endsWith('.zip')) {
|
|
79
|
+
console.log('Extracting zip file...');
|
|
80
|
+
try {
|
|
81
|
+
const zip = new AdmZip(targetPath);
|
|
82
|
+
zip.extractAllTo(targetDir, true);
|
|
83
|
+
fs.unlinkSync(targetPath); // 删除 zip 文件
|
|
84
|
+
|
|
85
|
+
// 尝试设置解压后文件的执行权限
|
|
86
|
+
const execName = fileName.slice(0, -4);
|
|
87
|
+
const execPath = path.join(targetDir, execName);
|
|
88
|
+
if (platform !== 'windows' && fs.existsSync(execPath)) {
|
|
89
|
+
fs.chmodSync(execPath, 0o755);
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
console.error(`Failed to unzip: ${err.message}`);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
// 设置执行权限 (Unix)
|
|
97
|
+
if (platform !== 'windows') {
|
|
98
|
+
fs.chmodSync(targetPath, 0o755);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
console.log('Installation complete!');
|
|
102
|
+
});
|
|
103
|
+
})
|
|
104
|
+
.catch(function (error) {
|
|
105
|
+
fs.unlink(targetPath, () => {}); // 删除损坏的文件
|
|
106
|
+
console.error(`Download failed: ${error.message}`);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
});
|
|
109
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "skhub-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "skillhub CLI,Install the latest version of skhub",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://gitee.com/skillhub/skhub-npm.git"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"skhub": "./bin/cli.js"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
|
+
},
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"files": [
|
|
18
|
+
"bin/cli.js",
|
|
19
|
+
"install.js"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"adm-zip": "^0.5.16",
|
|
23
|
+
"axios": "^1.13.6"
|
|
24
|
+
}
|
|
25
|
+
}
|