create-openclaw-bot 5.0.2 → 5.0.4
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/cli.js +74 -3
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
import { input, select, checkbox, confirm } from '@inquirer/prompts';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import path from 'path';
|
|
6
|
+
import os from 'os';
|
|
6
7
|
import chalk from 'chalk';
|
|
7
8
|
import { spawn, execSync } from 'child_process';
|
|
8
|
-
const TELEGRAM_RELAY_PLUGIN_ID = 'telegram-multibot-relay';
|
|
9
|
-
|
|
9
|
+
const TELEGRAM_RELAY_PLUGIN_ID = 'openclaw-telegram-multibot-relay';
|
|
10
|
+
// Use plain npm package name — clawhub: protocol not supported in all OpenClaw versions
|
|
11
|
+
const TELEGRAM_RELAY_PLUGIN_SPEC = TELEGRAM_RELAY_PLUGIN_ID;
|
|
10
12
|
|
|
11
13
|
// Install command: only use clawhub: spec (published to ClawHub)
|
|
12
14
|
function buildRelayPluginInstallCommand(prefix = 'openclaw') {
|
|
@@ -1130,6 +1132,31 @@ ${hasBrowserDesktop ? ` extra_hosts:
|
|
|
1130
1132
|
buildTelegramPostInstallChecklist({ isVi, bots, groupId }),
|
|
1131
1133
|
'utf8',
|
|
1132
1134
|
);
|
|
1135
|
+
// Generate ecosystem.config.js for PM2 native multi-bot
|
|
1136
|
+
if (deployMode === 'native') {
|
|
1137
|
+
const pm2Apps = agentMetas.map((meta) => [
|
|
1138
|
+
' {',
|
|
1139
|
+
` name: '${meta.agentId}',`,
|
|
1140
|
+
` script: 'openclaw',`,
|
|
1141
|
+
` args: '--agent ${meta.agentId}',`,
|
|
1142
|
+
` cwd: '${projectDir.replace(/\\/g, '/')}',`,
|
|
1143
|
+
` interpreter: 'none',`,
|
|
1144
|
+
` autorestart: true,`,
|
|
1145
|
+
` watch: false,`,
|
|
1146
|
+
` env: { NODE_ENV: 'production' }`,
|
|
1147
|
+
' }',
|
|
1148
|
+
].join('\n')).join(',\n');
|
|
1149
|
+
const ecosystemContent = [
|
|
1150
|
+
'// PM2 ecosystem — run: pm2 start ecosystem.config.js',
|
|
1151
|
+
'module.exports = {',
|
|
1152
|
+
' apps: [',
|
|
1153
|
+
pm2Apps,
|
|
1154
|
+
' ]',
|
|
1155
|
+
'};',
|
|
1156
|
+
'',
|
|
1157
|
+
].join('\n');
|
|
1158
|
+
await fs.writeFile(path.join(projectDir, 'ecosystem.config.js'), ecosystemContent);
|
|
1159
|
+
}
|
|
1133
1160
|
installRelayPluginForProject(projectDir, isVi);
|
|
1134
1161
|
if (Object.keys(authProfilesJson).length > 0) {
|
|
1135
1162
|
await fs.writeJson(path.join(rootClawDir, 'auth-profiles.json'), authProfilesJson, { spaces: 2 });
|
|
@@ -1596,11 +1623,55 @@ fi
|
|
|
1596
1623
|
if (isMultiBot && channelKey === 'telegram') {
|
|
1597
1624
|
console.log(chalk.yellow(`\n${isVi ? '📋 Xem hướng dẫn sau cài:' : '📋 Read post-install guide:'} ${path.join(projectDir, 'TELEGRAM-POST-INSTALL.md')}`));
|
|
1598
1625
|
}
|
|
1599
|
-
|
|
1626
|
+
// ── Auto-install openclaw binary if not present ──────────────────────────
|
|
1627
|
+
const isOpenClawInstalled = () => { try { execSync('openclaw --version', { stdio: 'ignore' }); return true; } catch { return false; } };
|
|
1628
|
+
if (!isOpenClawInstalled()) {
|
|
1629
|
+
console.log(chalk.cyan(isVi
|
|
1630
|
+
? '\n📦 Đang cài openclaw binary (npm install -g openclaw)...'
|
|
1631
|
+
: '\n📦 Installing openclaw binary (npm install -g openclaw)...'));
|
|
1632
|
+
try {
|
|
1633
|
+
execSync('npm install -g openclaw', { stdio: 'inherit' });
|
|
1634
|
+
console.log(chalk.green(isVi ? '✅ openclaw đã cài xong!' : '✅ openclaw installed!'));
|
|
1635
|
+
} catch {
|
|
1636
|
+
console.log(chalk.yellow(isVi
|
|
1637
|
+
? '⚠️ Không tự cài được. Chạy thủ công: sudo npm install -g openclaw'
|
|
1638
|
+
: '⚠️ Could not auto-install. Run manually: sudo npm install -g openclaw'));
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
// ── Auto-sync generated config to ~/.openclaw so `openclaw` picks it up ──
|
|
1643
|
+
|
|
1644
|
+
const homedir = os.homedir();
|
|
1645
|
+
const globalClawDir = path.join(homedir, '.openclaw');
|
|
1646
|
+
const localClawDir = path.join(projectDir, '.openclaw');
|
|
1647
|
+
try {
|
|
1648
|
+
await fs.ensureDir(globalClawDir);
|
|
1649
|
+
await fs.copy(localClawDir, globalClawDir, { overwrite: true });
|
|
1650
|
+
console.log(chalk.green(`\n✅ ${isVi
|
|
1651
|
+
? `Config đã được sync vào ~/.openclaw/ — openclaw sẵn sàng!`
|
|
1652
|
+
: `Config synced to ~/.openclaw/ — openclaw is ready!`}`));
|
|
1653
|
+
} catch (syncErr) {
|
|
1654
|
+
console.log(chalk.yellow(`\n⚠️ ${isVi
|
|
1655
|
+
? `Không thể tự sync config. Chạy thủ công:\n cp -rn ${localClawDir}/. ${globalClawDir}/`
|
|
1656
|
+
: `Could not auto-sync config. Run manually:\n cp -rn ${localClawDir}/. ${globalClawDir}/`}`));
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1600
1659
|
console.log(chalk.cyan(`\n👉 ${isVi ? 'Đã tạo xong file cấu hình native.' : 'Native config files are ready.'}`));
|
|
1601
1660
|
console.log(chalk.gray(isVi
|
|
1602
1661
|
? ` Cấu trúc config: ${isMultiBot && channelKey === 'telegram' ? '.openclaw/ dùng chung + agents/workspace-*' : (isMultiBot ? 'bot1/, bot2/, ...' : '.openclaw/')}`
|
|
1603
1662
|
: ` Config layout: ${isMultiBot && channelKey === 'telegram' ? 'shared .openclaw/ with agents/workspace-*' : (isMultiBot ? 'bot1/, bot2/, ...' : '.openclaw/')}`));
|
|
1663
|
+
|
|
1664
|
+
// Print exact run commands
|
|
1665
|
+
console.log(chalk.bold.white(`\n🚀 ${isVi ? 'Chạy bot ngay:' : 'Start the bot now:'}`));
|
|
1666
|
+
if (isMultiBot && channelKey === 'telegram') {
|
|
1667
|
+
console.log(chalk.white(` pm2 start ${path.join(projectDir, 'ecosystem.config.js')}`));
|
|
1668
|
+
} else {
|
|
1669
|
+
console.log(chalk.white(` openclaw gateway`));
|
|
1670
|
+
}
|
|
1671
|
+
console.log(chalk.gray(isVi
|
|
1672
|
+
? `\n Chạy background (PM2):\n npm install -g pm2\n pm2 start "openclaw gateway" --name "${botName || 'openclaw-bot'}" --cwd ${projectDir}\n pm2 save && pm2 startup`
|
|
1673
|
+
: `\n Run in background (PM2):\n npm install -g pm2\n pm2 start "openclaw gateway" --name "${botName || 'openclaw-bot'}" --cwd ${projectDir}\n pm2 save && pm2 startup`));
|
|
1674
|
+
|
|
1604
1675
|
if (isMultiBot && channelKey === 'telegram') {
|
|
1605
1676
|
console.log(chalk.yellow(`\n${isVi ? '📋 Xem hướng dẫn sau cài:' : '📋 Read post-install guide:'} ${path.join(projectDir, 'TELEGRAM-POST-INSTALL.md')}`));
|
|
1606
1677
|
}
|