@okclaw-build/cli 1.0.0-beta.1
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/bin/okclaw.js +2 -0
- package/dist/commands/check.d.ts +1 -0
- package/dist/commands/check.js +11 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/edit.d.ts +10 -0
- package/dist/commands/edit.js +44 -0
- package/dist/commands/edit.js.map +1 -0
- package/dist/commands/feed.d.ts +10 -0
- package/dist/commands/feed.js +158 -0
- package/dist/commands/feed.js.map +1 -0
- package/dist/commands/install.d.ts +1 -0
- package/dist/commands/install.js +72 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/service.d.ts +4 -0
- package/dist/commands/service.js +23 -0
- package/dist/commands/service.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -0
- package/dist/installers/base.d.ts +5 -0
- package/dist/installers/base.js +2 -0
- package/dist/installers/base.js.map +1 -0
- package/dist/installers/channel.d.ts +17 -0
- package/dist/installers/channel.js +129 -0
- package/dist/installers/channel.js.map +1 -0
- package/dist/installers/openclaw.d.ts +18 -0
- package/dist/installers/openclaw.js +104 -0
- package/dist/installers/openclaw.js.map +1 -0
- package/dist/installers/openviking.d.ts +28 -0
- package/dist/installers/openviking.js +236 -0
- package/dist/installers/openviking.js.map +1 -0
- package/dist/utils/constants.d.ts +26 -0
- package/dist/utils/constants.js +45 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/deps.d.ts +18 -0
- package/dist/utils/deps.js +177 -0
- package/dist/utils/deps.js.map +1 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/utils/logger.js +5 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/mirror.d.ts +1 -0
- package/dist/utils/mirror.js +15 -0
- package/dist/utils/mirror.js.map +1 -0
- package/dist/utils/shell.d.ts +24 -0
- package/dist/utils/shell.js +86 -0
- package/dist/utils/shell.js.map +1 -0
- package/package.json +28 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { shell, shellCapture, commandExists } from './shell.js';
|
|
2
|
+
import { info, warn } from './logger.js';
|
|
3
|
+
import { NODE_MIN_MAJOR, NODE_MIN_MINOR, NODE_INSTALL_VERSION, NODE_MIRROR, PYTHON_MIN_MAJOR, PYTHON_MIN_MINOR, } from './constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* Ensure Node.js >= NODE_MIN_MAJOR.NODE_MIN_MINOR is installed via nvm.
|
|
6
|
+
* Installs nvm first if not present, then installs Node.js through nvm.
|
|
7
|
+
*/
|
|
8
|
+
export async function ensureNodeVersion() {
|
|
9
|
+
const required = `${NODE_MIN_MAJOR}.${NODE_MIN_MINOR}`;
|
|
10
|
+
const result = await shellCapture('node -v');
|
|
11
|
+
if (result.code === 0) {
|
|
12
|
+
const version = result.stdout.replace(/^v/, '');
|
|
13
|
+
if (versionGe(version, required)) {
|
|
14
|
+
info(`Node.js ${version} >= ${required} ✓`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
warn(`Node.js ${version} < ${required}, upgrading via nvm...`);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
info('Node.js not found, installing via nvm...');
|
|
21
|
+
}
|
|
22
|
+
await ensureNvm();
|
|
23
|
+
await installNodejs();
|
|
24
|
+
}
|
|
25
|
+
const NVM_DIR = '/root/.nvm';
|
|
26
|
+
async function ensureNvm() {
|
|
27
|
+
// shell/shellCapture already source nvm.sh automatically
|
|
28
|
+
const check = await shellCapture('nvm --version');
|
|
29
|
+
if (check.code === 0) {
|
|
30
|
+
info(`nvm ${check.stdout.trim()} found ✓`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
info('nvm not found, installing...');
|
|
34
|
+
// Install nvm from gitee mirror (GitHub is unreliable in China)
|
|
35
|
+
await shell(`curl -fsSL https://gitee.com/mirrors/nvm/raw/master/install.sh | PROFILE=/dev/null NVM_DIR=${NVM_DIR} bash`).catch(async () => {
|
|
36
|
+
// Fallback: npmmirror hosted nvm install script
|
|
37
|
+
info('Retrying nvm install from npmmirror...');
|
|
38
|
+
await shell(`curl -fsSL https://npmmirror.com/mirrors/nvm/v0.40.3/install.sh | PROFILE=/dev/null NVM_DIR=${NVM_DIR} bash`);
|
|
39
|
+
});
|
|
40
|
+
// Verify
|
|
41
|
+
const verify = await shellCapture('nvm --version');
|
|
42
|
+
if (verify.code !== 0)
|
|
43
|
+
throw new Error('nvm installation failed');
|
|
44
|
+
info(`nvm ${verify.stdout.trim()} installed ✓`);
|
|
45
|
+
}
|
|
46
|
+
async function installNodejs() {
|
|
47
|
+
info(`Installing Node.js ${NODE_INSTALL_VERSION} via nvm...`);
|
|
48
|
+
// Use npmmirror for faster download in China
|
|
49
|
+
await shell(`NVM_NODEJS_ORG_MIRROR=${NODE_MIRROR} nvm install ${NODE_INSTALL_VERSION}`);
|
|
50
|
+
await shell(`nvm alias default ${NODE_INSTALL_VERSION}`);
|
|
51
|
+
await shell(`nvm use ${NODE_INSTALL_VERSION}`);
|
|
52
|
+
// Verify
|
|
53
|
+
const verify = await shellCapture('node -v');
|
|
54
|
+
if (verify.code !== 0)
|
|
55
|
+
throw new Error('Node.js installation failed: node command not found');
|
|
56
|
+
info(`Node.js ${verify.stdout.trim()} installed via nvm ✓`);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Ensure Python >= PYTHON_MIN_MAJOR.PYTHON_MIN_MINOR is installed.
|
|
60
|
+
* Auto-installs via system package manager if missing or too old.
|
|
61
|
+
*/
|
|
62
|
+
export async function ensurePython() {
|
|
63
|
+
const required = `${PYTHON_MIN_MAJOR}.${PYTHON_MIN_MINOR}`;
|
|
64
|
+
const result = await shellCapture('python3 --version');
|
|
65
|
+
if (result.code === 0) {
|
|
66
|
+
const match = result.stdout.match(/(\d+)\.(\d+)\.?(\d+)?/);
|
|
67
|
+
if (match) {
|
|
68
|
+
const version = `${match[1]}.${match[2]}`;
|
|
69
|
+
if (versionGe(version, required)) {
|
|
70
|
+
info(`Python ${result.stdout.trim()} >= ${required} ✓`);
|
|
71
|
+
await ensurePip();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
warn(`Python ${version} < ${required}, upgrading...`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
info('Python3 not found, installing...');
|
|
79
|
+
}
|
|
80
|
+
await installPython();
|
|
81
|
+
await ensurePip();
|
|
82
|
+
}
|
|
83
|
+
async function installPython() {
|
|
84
|
+
const required = `${PYTHON_MIN_MAJOR}.${PYTHON_MIN_MINOR}`;
|
|
85
|
+
info(`Installing Python >= ${required}...`);
|
|
86
|
+
if (await commandExists('apt-get')) {
|
|
87
|
+
// Try deadsnakes PPA for newer Python on older Ubuntu
|
|
88
|
+
await shell('apt-get update -qq').catch(() => { });
|
|
89
|
+
await shell('apt-get install -y -qq python3 python3-pip python3-venv python3-dev').catch(async () => {
|
|
90
|
+
info('Trying deadsnakes PPA...');
|
|
91
|
+
await shell('apt-get install -y -qq software-properties-common').catch(() => { });
|
|
92
|
+
await shell('add-apt-repository -y ppa:deadsnakes/ppa').catch(() => { });
|
|
93
|
+
await shell('apt-get update -qq');
|
|
94
|
+
await shell('apt-get install -y -qq python3 python3-pip python3-venv python3-dev');
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else if (await commandExists('dnf')) {
|
|
98
|
+
await shell('dnf install -y python3 python3-pip python3-devel');
|
|
99
|
+
}
|
|
100
|
+
else if (await commandExists('yum')) {
|
|
101
|
+
await shell('yum install -y python3 python3-pip python3-devel');
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
throw new Error(`Cannot install Python: no supported package manager. Install Python >= ${required} manually.`);
|
|
105
|
+
}
|
|
106
|
+
// Verify
|
|
107
|
+
const verify = await shellCapture('python3 --version');
|
|
108
|
+
if (verify.code !== 0)
|
|
109
|
+
throw new Error('Python installation failed');
|
|
110
|
+
const match = verify.stdout.match(/(\d+)\.(\d+)/);
|
|
111
|
+
if (match && !versionGe(`${match[1]}.${match[2]}`, required)) {
|
|
112
|
+
throw new Error(`Installed Python ${match[1]}.${match[2]} still below ${required}. Install manually.`);
|
|
113
|
+
}
|
|
114
|
+
info(`Python ${verify.stdout.trim()} installed ✓`);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Ensure pip is available.
|
|
118
|
+
*/
|
|
119
|
+
async function ensurePip() {
|
|
120
|
+
const result = await shellCapture('python3 -m pip --version');
|
|
121
|
+
if (result.code === 0)
|
|
122
|
+
return;
|
|
123
|
+
info('pip not found, installing...');
|
|
124
|
+
await shell('curl -fsSL https://bootstrap.pypa.io/get-pip.py | python3').catch(async () => {
|
|
125
|
+
await installSystemPackages(['python3-pip']);
|
|
126
|
+
});
|
|
127
|
+
const verify = await shellCapture('python3 -m pip --version');
|
|
128
|
+
if (verify.code !== 0)
|
|
129
|
+
throw new Error('Failed to install pip');
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Ensure a command exists on PATH.
|
|
133
|
+
*/
|
|
134
|
+
export async function ensureCommand(cmd) {
|
|
135
|
+
if (!(await commandExists(cmd))) {
|
|
136
|
+
throw new Error(`Required command not found: ${cmd}. Install it first.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Check available disk space (MB) on /root.
|
|
141
|
+
*/
|
|
142
|
+
export async function checkDiskSpace(requiredMb) {
|
|
143
|
+
const result = await shellCapture("df /root --output=avail -BM 2>/dev/null | tail -1 | tr -d ' M'");
|
|
144
|
+
const available = parseInt(result.stdout, 10);
|
|
145
|
+
if (!isNaN(available) && available < requiredMb) {
|
|
146
|
+
throw new Error(`Insufficient disk space: ${available}MB available, ${requiredMb}MB required`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// ---- helpers ----
|
|
150
|
+
async function installSystemPackages(packages) {
|
|
151
|
+
if (await commandExists('apt-get')) {
|
|
152
|
+
await shell(`apt-get update -qq && apt-get install -y -qq ${packages.join(' ')}`);
|
|
153
|
+
}
|
|
154
|
+
else if (await commandExists('dnf')) {
|
|
155
|
+
await shell(`dnf install -y ${packages.join(' ')}`);
|
|
156
|
+
}
|
|
157
|
+
else if (await commandExists('yum')) {
|
|
158
|
+
await shell(`yum install -y ${packages.join(' ')}`);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
throw new Error(`Cannot install packages: no supported package manager`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function versionGe(a, b) {
|
|
165
|
+
const pa = a.split('.').map(Number);
|
|
166
|
+
const pb = b.split('.').map(Number);
|
|
167
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
168
|
+
const va = pa[i] ?? 0;
|
|
169
|
+
const vb = pb[i] ?? 0;
|
|
170
|
+
if (va > vb)
|
|
171
|
+
return true;
|
|
172
|
+
if (va < vb)
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=deps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deps.js","sourceRoot":"","sources":["../../src/utils/deps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAS,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,cAAc,EAAE,cAAc,EAAE,oBAAoB,EACpD,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,GAChD,MAAM,gBAAgB,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,MAAM,QAAQ,GAAG,GAAG,cAAc,IAAI,cAAc,EAAE,CAAC;IACvD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,CAAC;IAC7C,IAAI,MAAM,CAAC,IAAI,KAAK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,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACxD,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACtB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACtB,IAAI,EAAE,GAAG,EAAE;YAAE,OAAO,IAAI,CAAC;QACzB,IAAI,EAAE,GAAG,EAAE;YAAE,OAAO,KAAK,CAAC;IAC5B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export function info(msg) { console.log(`[okclaw] ${msg}`); }
|
|
2
|
+
export function warn(msg) { console.log(`[okclaw] WARN: ${msg}`); }
|
|
3
|
+
export function error(msg) { console.error(`[okclaw] ERROR: ${msg}`); }
|
|
4
|
+
export function success(msg) { console.log(`[okclaw] ✓ ${msg}`); }
|
|
5
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,IAAI,CAAC,GAAW,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;AACrE,MAAM,UAAU,IAAI,CAAC,GAAW,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;AAC3E,MAAM,UAAU,KAAK,CAAC,GAAW,IAAI,OAAO,CAAC,KAAK,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;AAC/E,MAAM,UAAU,OAAO,CAAC,GAAW,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function configureMirrors(): Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { shell } from './shell.js';
|
|
2
|
+
import { info } from './logger.js';
|
|
3
|
+
import { NPM_REGISTRY, PIP_INDEX_URL, PIP_TRUSTED_HOST } from './constants.js';
|
|
4
|
+
export async function configureMirrors() {
|
|
5
|
+
info('Configuring China mirrors...');
|
|
6
|
+
await shell(`npm config set registry ${NPM_REGISTRY}`).catch(() => { });
|
|
7
|
+
// Use /root/.pip — not ~/
|
|
8
|
+
await shell(`mkdir -p /root/.pip && cat > /root/.pip/pip.conf << 'EOF'
|
|
9
|
+
[global]
|
|
10
|
+
index-url = ${PIP_INDEX_URL}
|
|
11
|
+
trusted-host = ${PIP_TRUSTED_HOST}
|
|
12
|
+
EOF`).catch(() => { });
|
|
13
|
+
info('Mirrors configured.');
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=mirror.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mirror.js","sourceRoot":"","sources":["../../src/utils/mirror.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE/E,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IAErC,MAAM,KAAK,CAAC,2BAA2B,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAEvE,0BAA0B;IAC1B,MAAM,KAAK,CAAC;;cAEA,aAAa;iBACV,gBAAgB;IAC7B,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAEpB,IAAI,CAAC,qBAAqB,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface ShellResult {
|
|
2
|
+
code: number;
|
|
3
|
+
stdout: string;
|
|
4
|
+
stderr: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Ensure running as root. If not, re-exec with sudo and exit.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ensureRoot(): void;
|
|
10
|
+
/**
|
|
11
|
+
* Run a shell command with inherited stdio (visible output).
|
|
12
|
+
* Automatically sources nvm so node/npm/openclaw are available.
|
|
13
|
+
* Throws on non-zero exit.
|
|
14
|
+
*/
|
|
15
|
+
export declare function shell(cmd: string): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Run a shell command with retries.
|
|
18
|
+
*/
|
|
19
|
+
export declare function shellRetry(cmd: string, retries?: number, delayMs?: number): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Run a shell command and capture stdout/stderr.
|
|
22
|
+
*/
|
|
23
|
+
export declare function shellCapture(cmd: string): Promise<ShellResult>;
|
|
24
|
+
export declare function commandExists(cmd: string): Promise<boolean>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { spawn, execFileSync } from 'node:child_process';
|
|
2
|
+
import { error as logError, info } from './logger.js';
|
|
3
|
+
/**
|
|
4
|
+
* Ensure running as root. If not, re-exec with sudo and exit.
|
|
5
|
+
*/
|
|
6
|
+
export function ensureRoot() {
|
|
7
|
+
if (process.getuid?.() === 0) {
|
|
8
|
+
process.env.HOME = '/root';
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
info('Not running as root, re-executing with sudo...');
|
|
12
|
+
try {
|
|
13
|
+
execFileSync('sudo', ['-E', 'HOME=/root', process.execPath, ...process.argv.slice(1)], {
|
|
14
|
+
stdio: 'inherit',
|
|
15
|
+
});
|
|
16
|
+
process.exit(0);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
const code = err.status ?? 1;
|
|
20
|
+
process.exit(code);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Prefix to source nvm before every shell command so node/npm are on PATH
|
|
24
|
+
const NVM_INIT = 'export HOME=/root; export NVM_DIR=/root/.nvm; [ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"; ';
|
|
25
|
+
/**
|
|
26
|
+
* Run a shell command with inherited stdio (visible output).
|
|
27
|
+
* Automatically sources nvm so node/npm/openclaw are available.
|
|
28
|
+
* Throws on non-zero exit.
|
|
29
|
+
*/
|
|
30
|
+
export function shell(cmd) {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const child = spawn('bash', ['-c', NVM_INIT + cmd], {
|
|
33
|
+
stdio: 'inherit',
|
|
34
|
+
env: { ...process.env, HOME: '/root' },
|
|
35
|
+
});
|
|
36
|
+
child.on('error', reject);
|
|
37
|
+
child.on('close', (code) => {
|
|
38
|
+
if (code === 0)
|
|
39
|
+
resolve();
|
|
40
|
+
else
|
|
41
|
+
reject(new Error(`Command failed (exit ${code}): ${cmd}`));
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Run a shell command with retries.
|
|
47
|
+
*/
|
|
48
|
+
export async function shellRetry(cmd, retries = 3, delayMs = 2000) {
|
|
49
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
50
|
+
try {
|
|
51
|
+
await shell(cmd);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
if (attempt === retries)
|
|
56
|
+
throw err;
|
|
57
|
+
logError(`Attempt ${attempt}/${retries} failed, retrying in ${delayMs}ms...`);
|
|
58
|
+
await sleep(delayMs);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Run a shell command and capture stdout/stderr.
|
|
64
|
+
*/
|
|
65
|
+
export function shellCapture(cmd) {
|
|
66
|
+
return new Promise((resolve) => {
|
|
67
|
+
const child = spawn('bash', ['-c', NVM_INIT + cmd], {
|
|
68
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
69
|
+
env: { ...process.env, HOME: '/root' },
|
|
70
|
+
});
|
|
71
|
+
let stdout = '';
|
|
72
|
+
let stderr = '';
|
|
73
|
+
child.stdout?.on('data', (chunk) => { stdout += String(chunk); });
|
|
74
|
+
child.stderr?.on('data', (chunk) => { stderr += String(chunk); });
|
|
75
|
+
child.on('error', (err) => resolve({ code: -1, stdout: '', stderr: String(err) }));
|
|
76
|
+
child.on('close', (code) => resolve({ code: code ?? -1, stdout: stdout.trim(), stderr: stderr.trim() }));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
export async function commandExists(cmd) {
|
|
80
|
+
const result = await shellCapture(`command -v ${cmd}`);
|
|
81
|
+
return result.code === 0;
|
|
82
|
+
}
|
|
83
|
+
function sleep(ms) {
|
|
84
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAQtD;;GAEG;AACH,MAAM,UAAU,UAAU;IACxB,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC;QAC3B,OAAO;IACT,CAAC;IAED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,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QACnF,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3G,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,GAAW;IAC7C,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,cAAc,GAAG,EAAE,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@okclaw-build/cli",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "OKClaw deployment CLI - install and manage OpenClaw, OpenViking, and channel plugins",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"okclaw": "bin/okclaw.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsc --watch",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"keywords": ["openclaw", "openviking", "deploy", "cli"],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.4.0",
|
|
19
|
+
"@types/node": "^22.0.0"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=22"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"bin"
|
|
27
|
+
]
|
|
28
|
+
}
|