@licity/qclaw-local-connector 1.1.0 → 1.2.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.
Files changed (2) hide show
  1. package/index.js +31 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -12,6 +12,7 @@ const qrcode = require('qrcode-terminal');
12
12
  // 优先从运行目录加载 .env(全局安装时从 CWD),否则从安装包目录加载
13
13
  const envFromCwd = path.join(process.cwd(), '.env');
14
14
  const envFromPkg = path.join(__dirname, '.env');
15
+ const envExamplePath = path.join(__dirname, '.env.example');
15
16
  require('dotenv').config({ path: fs.existsSync(envFromCwd) ? envFromCwd : envFromPkg });
16
17
 
17
18
  const pkg = require('./package.json');
@@ -39,7 +40,36 @@ const capabilityScopes = String(process.env.CAPABILITY_SCOPES || 'private_chat,n
39
40
  const execFileAsync = promisify(execFile);
40
41
 
41
42
  if (!connectorKey) {
42
- console.error('缺少 OPENCLAW_CONNECTOR_SECRET,无法启动本地 Connector。');
43
+ // 当工作目录没有 .env 时,自动生成模板并引导用户
44
+ if (!fs.existsSync(envFromCwd)) {
45
+ const templateDest = path.join(process.cwd(), '.env');
46
+ const templateContent = fs.existsSync(envExamplePath)
47
+ ? fs.readFileSync(envExamplePath, 'utf8')
48
+ : [
49
+ 'LICITY_API_BASE_URL=https://li.city',
50
+ 'OPENCLAW_CONNECTOR_SECRET=',
51
+ 'QCLAW_PATH=C:\\QClaw\\QClaw.exe',
52
+ `QCLAW_STATE_DIR=${path.join(os.homedir(), '.qclaw')}`,
53
+ `OPENCLAW_CONFIG_PATH=${path.join(os.homedir(), '.qclaw', 'openclaw.json')}`,
54
+ ].join('\n') + '\n';
55
+ fs.writeFileSync(templateDest, templateContent, 'utf8');
56
+ console.error('');
57
+ console.error('══════════════════════════════════════════════════════');
58
+ console.error(' 首次运行:已在当前目录生成 .env 配置文件模板');
59
+ console.error(` 文件位置:${templateDest}`);
60
+ console.error('');
61
+ console.error(' 请用文本编辑器打开 .env,填写以下必填项:');
62
+ console.error(' OPENCLAW_CONNECTOR_SECRET — 从里世界 APP「我的龙虾」页');
63
+ console.error(' 复制「连接密钥」后粘贴到这里');
64
+ console.error(' QCLAW_PATH — QClaw 主程序实际路径');
65
+ console.error(' QCLAW_STATE_DIR — QClaw 数据目录(含用户名)');
66
+ console.error('');
67
+ console.error(' 填写完毕后在同一目录重新运行:licity-connector');
68
+ console.error('══════════════════════════════════════════════════════');
69
+ console.error('');
70
+ } else {
71
+ console.error('缺少 OPENCLAW_CONNECTOR_SECRET,请在当前目录的 .env 文件中填写连接密钥。');
72
+ }
43
73
  process.exit(1);
44
74
  }
45
75
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@licity/qclaw-local-connector",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "里世界龙虾本地连接器 — 把 QClaw 或其他第三方本地 Runtime 接入里世界 APP",
5
5
  "main": "index.js",
6
6
  "bin": {