openclaw-weiyuan-init 1.0.2 → 1.0.9
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.md +35 -8
- package/bin/cli.js +7 -2
- package/lib/commands.js +65 -12
- package/lib/downloader.js +31 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
|
-
# @weiyuan/openclaw-weiyuan-init
|
|
2
|
-
|
|
3
|
-
OpenClaw Weiyuan Skill 一键初始化工具
|
|
4
|
-
|
|
5
|
-
## 一键部署
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npx -y
|
|
1
|
+
# @weiyuan/openclaw-weiyuan-init
|
|
2
|
+
|
|
3
|
+
OpenClaw Weiyuan Skill 一键初始化工具
|
|
4
|
+
|
|
5
|
+
## 一键部署
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx -y openclaw-weiyuan-init@latest init
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 版本化 zip 自动识别
|
|
12
|
+
|
|
13
|
+
- 默认读取 `<upgradeBaseUrl>/LATEST_SKILL_VERSION.txt`
|
|
14
|
+
- 自动下载 `weiyuan-openclaw-skill-v<version>.zip`
|
|
15
|
+
- 当 zip 文件名随版本变化时无需改命令
|
|
16
|
+
|
|
17
|
+
## 常用参数
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx -y openclaw-weiyuan-init@latest init --upgrade <upgradeBaseUrl> --server <serverUrl>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
邀请码一键入组(推荐):
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx -y openclaw-weiyuan-init@latest init --invite <inviteToken>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`inviteToken` 包含 `server/upgrade/project/code`,会自动完成安装与入组。
|
|
30
|
+
|
|
31
|
+
如需指定固定 zip,可覆盖自动识别:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx -y openclaw-weiyuan-init@latest init --download <zipUrl> --server <serverUrl>
|
|
35
|
+
```
|
package/bin/cli.js
CHANGED
|
@@ -14,7 +14,11 @@ program
|
|
|
14
14
|
.description('初始化 weiyuan skill')
|
|
15
15
|
.option('-w, --workspace <path>', '指定工作目录', 'workspace-weiyuan')
|
|
16
16
|
.option('-s, --server <url>', '指定服务器地址', 'http://121.43.119.190:8787')
|
|
17
|
-
.option('-
|
|
17
|
+
.option('-u, --upgrade <url>', '指定升级源地址(含 LATEST_SKILL_VERSION.txt)', 'http://121.43.119.190/upgrade')
|
|
18
|
+
.option('-d, --download <url>', '指定下载地址(可覆盖自动版本解析)')
|
|
19
|
+
.option('-i, --invite <token>', '邀请码令牌(包含 server/upgrade/project/code)')
|
|
20
|
+
.option('-p, --project <id>', '邀请加入的项目 ID')
|
|
21
|
+
.option('-c, --code <code>', '邀请口令')
|
|
18
22
|
.option('-f, --force', '强制覆盖已有文件')
|
|
19
23
|
.action(async (options) => {
|
|
20
24
|
try {
|
|
@@ -42,6 +46,7 @@ program
|
|
|
42
46
|
.command('status')
|
|
43
47
|
.description('查看 weiyuan 状态')
|
|
44
48
|
.option('-w, --workspace <path>', '指定工作目录', 'workspace-weiyuan')
|
|
49
|
+
.option('-s, --server <url>', '指定服务器地址', 'http://121.43.119.190:8787')
|
|
45
50
|
.action(async (options) => {
|
|
46
51
|
try {
|
|
47
52
|
await runStatus(options);
|
|
@@ -51,4 +56,4 @@ program
|
|
|
51
56
|
}
|
|
52
57
|
});
|
|
53
58
|
|
|
54
|
-
program.parse();
|
|
59
|
+
program.parse();
|
package/lib/commands.js
CHANGED
|
@@ -2,26 +2,59 @@ const chalk = require('chalk');
|
|
|
2
2
|
const ora = require('ora');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const fs = require('fs-extra');
|
|
5
|
-
const {
|
|
5
|
+
const { execFile } = require('child_process');
|
|
6
|
+
const { promisify } = require('util');
|
|
7
|
+
const { downloadFile, resolvePackageSource } = require('./downloader');
|
|
6
8
|
const { extractZip } = require('./extractor');
|
|
7
9
|
const { createIdentityFile } = require('./identity');
|
|
8
10
|
const { checkServer, initSkill } = require('./server');
|
|
9
11
|
const { printBanner, printSummary, listDirectory } = require('./utils');
|
|
12
|
+
const execFileAsync = promisify(execFile);
|
|
10
13
|
|
|
11
14
|
const DEFAULT_CONFIG = {
|
|
12
15
|
workspaceName: 'workspace-weiyuan',
|
|
13
|
-
|
|
16
|
+
upgradeBaseUrl: 'http://121.43.119.190/upgrade',
|
|
17
|
+
downloadUrl: '',
|
|
14
18
|
serverUrl: 'http://121.43.119.190:8787',
|
|
15
|
-
zipFilename: 'weiyuan-openclaw-skill-v0.1.1.zip',
|
|
16
19
|
identityFile: '.weiyuan'
|
|
17
20
|
};
|
|
18
21
|
|
|
22
|
+
function decodeInviteToken(token) {
|
|
23
|
+
if (!token || typeof token !== 'string') return null;
|
|
24
|
+
try {
|
|
25
|
+
const normalized = token.replace(/-/g, '+').replace(/_/g, '/');
|
|
26
|
+
const pad = normalized.length % 4 === 0 ? '' : '='.repeat(4 - (normalized.length % 4));
|
|
27
|
+
const raw = Buffer.from(normalized + pad, 'base64').toString('utf8');
|
|
28
|
+
const parsed = JSON.parse(raw);
|
|
29
|
+
if (!parsed || parsed.v !== 1) return null;
|
|
30
|
+
if (!parsed.api || !parsed.upgrade || !parsed.projectId || !parsed.code) return null;
|
|
31
|
+
return parsed;
|
|
32
|
+
} catch (_) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function runJoin(weiyuanPath, identityPath, projectId, code) {
|
|
38
|
+
await execFileAsync('npm', ['--prefix', weiyuanPath, 'run', 'weiyuan', '--', 'join', '--identity', identityPath, '--project', projectId, '--code', code], {
|
|
39
|
+
cwd: weiyuanPath
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
19
43
|
async function runInit(options) {
|
|
20
44
|
printBanner();
|
|
21
45
|
|
|
46
|
+
const invite = decodeInviteToken(options.invite);
|
|
47
|
+
if (invite) {
|
|
48
|
+
options.server = options.server || invite.api;
|
|
49
|
+
options.upgrade = options.upgrade || invite.upgrade;
|
|
50
|
+
options.project = options.project || invite.projectId;
|
|
51
|
+
options.code = options.code || invite.code;
|
|
52
|
+
}
|
|
53
|
+
|
|
22
54
|
const workspacePath = path.join(process.cwd(), options.workspace);
|
|
23
55
|
const weiyuanPath = path.join(workspacePath, 'weiyuan');
|
|
24
|
-
const
|
|
56
|
+
const upgradeBaseUrl = options.upgrade || DEFAULT_CONFIG.upgradeBaseUrl;
|
|
57
|
+
const requestedDownloadUrl = options.download || DEFAULT_CONFIG.downloadUrl;
|
|
25
58
|
const serverUrl = options.server || DEFAULT_CONFIG.serverUrl;
|
|
26
59
|
const force = options.force || false;
|
|
27
60
|
|
|
@@ -52,14 +85,22 @@ async function runInit(options) {
|
|
|
52
85
|
}
|
|
53
86
|
|
|
54
87
|
// 3. 下载文件
|
|
88
|
+
spinner = ora('解析下载包...').start();
|
|
89
|
+
const source = await resolvePackageSource({
|
|
90
|
+
downloadUrl: requestedDownloadUrl,
|
|
91
|
+
upgradeBaseUrl,
|
|
92
|
+
spinner
|
|
93
|
+
});
|
|
94
|
+
spinner.succeed(`下载源: ${source.downloadUrl}`);
|
|
95
|
+
|
|
55
96
|
spinner = ora('下载 weiyuan skill...').start();
|
|
56
|
-
const zipPath = path.join(weiyuanPath,
|
|
57
|
-
const downloadSuccess = await downloadFile(downloadUrl, zipPath, spinner);
|
|
97
|
+
const zipPath = path.join(weiyuanPath, source.zipFilename);
|
|
98
|
+
const downloadSuccess = await downloadFile(source.downloadUrl, zipPath, spinner);
|
|
58
99
|
if (!downloadSuccess) {
|
|
59
100
|
spinner.fail('下载失败');
|
|
60
101
|
throw new Error('下载失败');
|
|
61
102
|
}
|
|
62
|
-
spinner.succeed(
|
|
103
|
+
spinner.succeed(`下载完成: ${source.zipFilename}`);
|
|
63
104
|
|
|
64
105
|
// 4. 解压
|
|
65
106
|
spinner = ora('解压文件...').start();
|
|
@@ -102,8 +143,19 @@ async function runInit(options) {
|
|
|
102
143
|
spinner.warn('初始化端点不存在,请手动调用');
|
|
103
144
|
}
|
|
104
145
|
|
|
146
|
+
if (options.project && options.code) {
|
|
147
|
+
spinner = ora('自动加入微元项目...').start();
|
|
148
|
+
try {
|
|
149
|
+
await runJoin(weiyuanPath, identityPath, options.project, options.code);
|
|
150
|
+
spinner.succeed(`已加入项目: ${options.project}`);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
spinner.fail(`自动入组失败: ${error.message}`);
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
105
157
|
// 打印总结
|
|
106
|
-
printSummary(workspacePath, serverUrl, downloadUrl);
|
|
158
|
+
printSummary(workspacePath, serverUrl, source.downloadUrl);
|
|
107
159
|
}
|
|
108
160
|
|
|
109
161
|
async function runClean(options) {
|
|
@@ -159,14 +211,15 @@ async function runStatus(options) {
|
|
|
159
211
|
}
|
|
160
212
|
|
|
161
213
|
// 检查服务器
|
|
162
|
-
const
|
|
214
|
+
const serverUrl = options.server || DEFAULT_CONFIG.serverUrl;
|
|
215
|
+
const serverOk = await checkServer(serverUrl);
|
|
163
216
|
if (serverOk) {
|
|
164
|
-
console.log(chalk.green(`✅ 服务器: ${
|
|
217
|
+
console.log(chalk.green(`✅ 服务器: ${serverUrl}`));
|
|
165
218
|
} else {
|
|
166
|
-
console.log(chalk.red(`❌ 服务器不可达: ${
|
|
219
|
+
console.log(chalk.red(`❌ 服务器不可达: ${serverUrl}`));
|
|
167
220
|
}
|
|
168
221
|
|
|
169
222
|
console.log('');
|
|
170
223
|
}
|
|
171
224
|
|
|
172
|
-
module.exports = { runInit, runClean, runStatus, DEFAULT_CONFIG };
|
|
225
|
+
module.exports = { runInit, runClean, runStatus, DEFAULT_CONFIG };
|
package/lib/downloader.js
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
const axios = require('axios');
|
|
2
2
|
const fs = require('fs-extra');
|
|
3
3
|
|
|
4
|
+
function trimSlash(url) {
|
|
5
|
+
return String(url || '').replace(/\/+$/, '');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function toZipFilename(downloadUrl) {
|
|
9
|
+
const clean = String(downloadUrl || '').split('?')[0].split('#')[0];
|
|
10
|
+
const parts = clean.split('/');
|
|
11
|
+
return parts[parts.length - 1] || 'weiyuan-openclaw-skill.zip';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function resolvePackageSource({ downloadUrl, upgradeBaseUrl, spinner = null }) {
|
|
15
|
+
if (downloadUrl) {
|
|
16
|
+
return { downloadUrl, zipFilename: toZipFilename(downloadUrl), version: null, from: 'download_url' };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const base = trimSlash(upgradeBaseUrl);
|
|
20
|
+
const latestUrl = `${base}/LATEST_SKILL_VERSION.txt`;
|
|
21
|
+
const latestResp = await axios.get(latestUrl, { timeout: 10000 });
|
|
22
|
+
const version = String(latestResp.data || '').trim();
|
|
23
|
+
if (!version) {
|
|
24
|
+
throw new Error('empty_latest_version');
|
|
25
|
+
}
|
|
26
|
+
const zipFilename = `weiyuan-openclaw-skill-v${version}.zip`;
|
|
27
|
+
const resolvedDownloadUrl = `${base}/${zipFilename}`;
|
|
28
|
+
if (spinner) {
|
|
29
|
+
spinner.text = `已解析最新版本: v${version}`;
|
|
30
|
+
}
|
|
31
|
+
return { downloadUrl: resolvedDownloadUrl, zipFilename, version, from: 'latest_version' };
|
|
32
|
+
}
|
|
33
|
+
|
|
4
34
|
async function downloadFile(url, outputPath, spinner = null) {
|
|
5
35
|
try {
|
|
6
36
|
const response = await axios({
|
|
@@ -40,4 +70,4 @@ async function downloadFile(url, outputPath, spinner = null) {
|
|
|
40
70
|
}
|
|
41
71
|
}
|
|
42
72
|
|
|
43
|
-
module.exports = { downloadFile };
|
|
73
|
+
module.exports = { downloadFile, resolvePackageSource };
|