create-openclaw-bot 5.8.24 → 5.10.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/dist/cli.js CHANGED
@@ -1,162 +1,172 @@
1
- #!/usr/bin/env node
2
- import fs from 'fs';
3
- import path from 'path';
4
- import os from 'os';
5
- import { fileURLToPath } from 'url';
6
- import { spawn } from 'child_process';
7
-
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = path.dirname(__filename);
10
-
11
- const runCmd = (cmd, cmdArgs, opts = {}) => {
12
- return new Promise((resolve, reject) => {
13
- const child = spawn(cmd, cmdArgs, {
14
- shell: true,
15
- stdio: 'inherit',
16
- ...opts
17
- });
18
- child.on('close', (code) => {
19
- if (code === 0) resolve();
20
- else reject(new Error(`${cmd} exited with code ${code}`));
21
- });
22
- child.on('error', reject);
23
- });
24
- };
25
-
26
- function isLocalRepo() {
27
- const pathsToTry = [
28
- path.resolve(__dirname, '..'),
29
- path.resolve(__dirname, '../..')
30
- ];
31
- for (const rootDir of pathsToTry) {
32
- const pkgPath = path.join(rootDir, 'package.json');
33
- if (fs.existsSync(pkgPath)) {
34
- try {
35
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
36
- if (pkg.name === 'create-openclaw-bot' && fs.existsSync(path.join(rootDir, 'src', 'cli', 'cli.src.js'))) {
37
- return true;
38
- }
39
- } catch {}
40
- }
41
- }
42
- return false;
43
- }
44
-
45
- const LOGO = `
46
- ╭────────────────────────────────────────╮
47
- │ 🦞 OpenClaw Setup 🦞 │
48
- │ by tuanminhhole │
49
- ╰────────────────────────────────────────╯
50
- `;
51
- console.log(LOGO);
52
-
53
- const args = process.argv.slice(2);
54
-
55
- const noOpen = args.includes('--no-open');
56
- const hostArg = args.find((arg) => arg.startsWith('--host='));
57
- const portArg = args.find((arg) => arg.startsWith('--port='));
58
- const projectDirArg = args.find((arg) => arg.startsWith('--project-dir='));
59
-
60
- const fallbackDir = path.join(os.homedir(), 'openclaw-setup');
61
- const defaultProjectDir = process.platform === 'win32'
62
- ? ((!fs.existsSync('C:\\openclaw-setup') && fs.existsSync(fallbackDir)) ? fallbackDir : 'C:\\openclaw-setup')
63
- : fallbackDir;
64
-
65
- let projectDir = projectDirArg ? projectDirArg.slice('--project-dir='.length) : defaultProjectDir;
66
-
67
- if (!fs.existsSync(projectDir)) {
68
- try {
69
- fs.mkdirSync(projectDir, { recursive: true });
70
- console.log(`Folder setup được tạo tại: ${projectDir}`);
71
- } catch (err) {
72
- if (err.code === 'EPERM' || err.code === 'EACCES') {
73
- console.warn(`⚠️ Không có quyền tạo thư mục tại: ${projectDir}`);
74
- console.log(`👉 Đang chuyển sang thư mục mặc định trong User Profile: ${fallbackDir}`);
75
- try {
76
- fs.mkdirSync(fallbackDir, { recursive: true });
77
- projectDir = fallbackDir;
78
- console.log(`Folder setup được tạo tại: ${projectDir}`);
79
- } catch (fallbackErr) {
80
- console.error(`Không thể tự động tạo thư mục project tại ${fallbackDir}:`, fallbackErr.message);
81
- }
82
- } else {
83
- console.error(`Không thể tự động tạo thư mục project tại ${projectDir}:`, err.message);
84
- }
85
- }
86
- }
87
-
88
- if (process.env.OPENCLAW_SETUP_WIZARD === 'true' || isLocalRepo()) {
89
- const { startLocalInstaller } = await import('./server/local-server.js');
90
-
91
- await startLocalInstaller({
92
- openBrowser: !noOpen,
93
- host: hostArg ? hostArg.slice('--host='.length) : '127.0.0.1',
94
- preferredPort: portArg ? Number(portArg.slice('--port='.length)) : 51789,
95
- projectDir: projectDir,
96
- });
97
- } else {
98
- const targetDirName = '.openclaw-setup';
99
- const targetPath = path.join(os.homedir(), targetDirName);
100
- const cliPath = path.join(targetPath, 'node_modules', 'create-openclaw-bot', 'dist', 'cli.js');
101
- const shouldUpdate = args.includes('--update');
102
-
103
- try {
104
- if (!fs.existsSync(targetPath)) {
105
- fs.mkdirSync(targetPath, { recursive: true });
106
- }
107
- const pkgPath = path.join(targetPath, 'package.json');
108
- if (!fs.existsSync(pkgPath)) {
109
- fs.writeFileSync(pkgPath, JSON.stringify({ name: 'openclaw-setup-container', version: '1.0.0', private: true, dependencies: {} }, null, 2), 'utf8');
110
- }
111
-
112
- let needsInstall = !fs.existsSync(cliPath) || shouldUpdate;
113
- let installSpec = 'create-openclaw-bot@latest';
114
-
115
- try {
116
- const runningPkgPath = path.join(__dirname, '..', 'package.json');
117
- if (fs.existsSync(runningPkgPath)) {
118
- const runningPkg = JSON.parse(fs.readFileSync(runningPkgPath, 'utf8'));
119
- if (runningPkg.version) {
120
- installSpec = `create-openclaw-bot@${runningPkg.version}`;
121
-
122
- const installedPkgPath = path.join(targetPath, 'node_modules', 'create-openclaw-bot', 'package.json');
123
- if (fs.existsSync(installedPkgPath)) {
124
- const installedPkg = JSON.parse(fs.readFileSync(installedPkgPath, 'utf8'));
125
- if (runningPkg.version !== installedPkg.version) {
126
- console.log(`Version mismatch: Launcher is v${runningPkg.version}, but cached installation is v${installedPkg.version}.`);
127
- needsInstall = true;
128
- }
129
- } else {
130
- needsInstall = true;
131
- }
132
- }
133
- }
134
- } catch (err) {}
135
-
136
- if (needsInstall) {
137
- console.log(`Checking/Installing Setup Wizard package (${installSpec}) in: ${targetPath}...`);
138
- await runCmd('npm', ['install', installSpec, '--no-audit', '--no-fund'], { cwd: targetPath });
139
- }
140
-
141
- console.log('\nStarting Setup Wizard...');
142
- const cleanArgs = args.filter((arg) => arg !== '--update');
143
-
144
- const child = spawn(process.argv[0], [cliPath, ...cleanArgs, `--project-dir=${projectDir}`], {
145
- cwd: targetPath,
146
- shell: false,
147
- stdio: 'inherit',
148
- env: {
149
- ...process.env,
150
- OPENCLAW_SETUP_WIZARD: 'true'
151
- }
152
- });
153
- child.on('close', (code) => {
154
- process.exit(code);
155
- });
156
- } catch (error) {
157
- console.error('\n❌ Lỗi khi khởi động Setup Wizard:', error.message);
158
- process.exit(1);
159
- }
160
- }
161
-
162
-
1
+ #!/usr/bin/env node
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import os from 'os';
5
+ import { fileURLToPath } from 'url';
6
+ import { spawn } from 'child_process';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ const runCmd = (cmd, cmdArgs, opts = {}) => {
12
+ return new Promise((resolve, reject) => {
13
+ const child = spawn(cmd, cmdArgs, {
14
+ shell: true,
15
+ stdio: 'inherit',
16
+ ...opts
17
+ });
18
+ child.on('close', (code) => {
19
+ if (code === 0) resolve();
20
+ else reject(new Error(`${cmd} exited with code ${code}`));
21
+ });
22
+ child.on('error', reject);
23
+ });
24
+ };
25
+
26
+ function isLocalRepo() {
27
+ const pathsToTry = [
28
+ path.resolve(__dirname, '..'),
29
+ path.resolve(__dirname, '../..')
30
+ ];
31
+ for (const rootDir of pathsToTry) {
32
+ const pkgPath = path.join(rootDir, 'package.json');
33
+ if (fs.existsSync(pkgPath)) {
34
+ try {
35
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
36
+ if (pkg.name === 'create-openclaw-bot' && fs.existsSync(path.join(rootDir, 'src', 'cli', 'cli.src.js'))) {
37
+ return true;
38
+ }
39
+ } catch {}
40
+ }
41
+ }
42
+ return false;
43
+ }
44
+
45
+ // True when the full server code is bundled next to this CLI (dist build, npm/global
46
+ // install, or `npx github:...`). In that case run it directly instead of bootstrapping
47
+ // the published package — works even though `files` ships only `dist/` (no `src/`).
48
+ function hasBundledServer() {
49
+ return [
50
+ path.join(__dirname, 'server', 'local-server.js'),
51
+ path.join(__dirname, '..', 'server', 'local-server.js'),
52
+ ].some((p) => fs.existsSync(p));
53
+ }
54
+
55
+ const LOGO = `
56
+ ╭────────────────────────────────────────╮
57
+ │ 🦞 OpenClaw Setup 🦞 │
58
+ │ by tuanminhhole │
59
+ ╰────────────────────────────────────────╯
60
+ `;
61
+ console.log(LOGO);
62
+
63
+ const args = process.argv.slice(2);
64
+
65
+ const noOpen = args.includes('--no-open');
66
+ const hostArg = args.find((arg) => arg.startsWith('--host='));
67
+ const portArg = args.find((arg) => arg.startsWith('--port='));
68
+ const projectDirArg = args.find((arg) => arg.startsWith('--project-dir='));
69
+
70
+ const fallbackDir = path.join(os.homedir(), 'openclaw-setup');
71
+ const defaultProjectDir = process.platform === 'win32'
72
+ ? ((!fs.existsSync('C:\\openclaw-setup') && fs.existsSync(fallbackDir)) ? fallbackDir : 'C:\\openclaw-setup')
73
+ : fallbackDir;
74
+
75
+ let projectDir = projectDirArg ? projectDirArg.slice('--project-dir='.length) : defaultProjectDir;
76
+
77
+ if (!fs.existsSync(projectDir)) {
78
+ try {
79
+ fs.mkdirSync(projectDir, { recursive: true });
80
+ console.log(`Folder setup được tạo tại: ${projectDir}`);
81
+ } catch (err) {
82
+ if (err.code === 'EPERM' || err.code === 'EACCES') {
83
+ console.warn(`⚠️ Không quyền tạo thư mục tại: ${projectDir}`);
84
+ console.log(`👉 Đang chuyển sang thư mục mặc định trong User Profile: ${fallbackDir}`);
85
+ try {
86
+ fs.mkdirSync(fallbackDir, { recursive: true });
87
+ projectDir = fallbackDir;
88
+ console.log(`Folder setup được tạo tại: ${projectDir}`);
89
+ } catch (fallbackErr) {
90
+ console.error(`Không thể tự động tạo thư mục project tại ${fallbackDir}:`, fallbackErr.message);
91
+ }
92
+ } else {
93
+ console.error(`Không thể tự động tạo thư mục project tại ${projectDir}:`, err.message);
94
+ }
95
+ }
96
+ }
97
+
98
+ if (process.env.OPENCLAW_SETUP_WIZARD === 'true' || isLocalRepo() || hasBundledServer()) {
99
+ const { startLocalInstaller } = await import('./server/local-server.js');
100
+
101
+ await startLocalInstaller({
102
+ openBrowser: !noOpen,
103
+ host: hostArg ? hostArg.slice('--host='.length) : '127.0.0.1',
104
+ preferredPort: portArg ? Number(portArg.slice('--port='.length)) : 51789,
105
+ projectDir: projectDir,
106
+ });
107
+ } else {
108
+ const targetDirName = '.openclaw-setup';
109
+ const targetPath = path.join(os.homedir(), targetDirName);
110
+ const cliPath = path.join(targetPath, 'node_modules', 'create-openclaw-bot', 'dist', 'cli.js');
111
+ const shouldUpdate = args.includes('--update');
112
+
113
+ try {
114
+ if (!fs.existsSync(targetPath)) {
115
+ fs.mkdirSync(targetPath, { recursive: true });
116
+ }
117
+ const pkgPath = path.join(targetPath, 'package.json');
118
+ if (!fs.existsSync(pkgPath)) {
119
+ fs.writeFileSync(pkgPath, JSON.stringify({ name: 'openclaw-setup-container', version: '1.0.0', private: true, dependencies: {} }, null, 2), 'utf8');
120
+ }
121
+
122
+ let needsInstall = !fs.existsSync(cliPath) || shouldUpdate;
123
+ let installSpec = 'create-openclaw-bot@latest';
124
+
125
+ try {
126
+ const runningPkgPath = path.join(__dirname, '..', 'package.json');
127
+ if (fs.existsSync(runningPkgPath)) {
128
+ const runningPkg = JSON.parse(fs.readFileSync(runningPkgPath, 'utf8'));
129
+ if (runningPkg.version) {
130
+ installSpec = `create-openclaw-bot@${runningPkg.version}`;
131
+
132
+ const installedPkgPath = path.join(targetPath, 'node_modules', 'create-openclaw-bot', 'package.json');
133
+ if (fs.existsSync(installedPkgPath)) {
134
+ const installedPkg = JSON.parse(fs.readFileSync(installedPkgPath, 'utf8'));
135
+ if (runningPkg.version !== installedPkg.version) {
136
+ console.log(`Version mismatch: Launcher is v${runningPkg.version}, but cached installation is v${installedPkg.version}.`);
137
+ needsInstall = true;
138
+ }
139
+ } else {
140
+ needsInstall = true;
141
+ }
142
+ }
143
+ }
144
+ } catch (err) {}
145
+
146
+ if (needsInstall) {
147
+ console.log(`Checking/Installing Setup Wizard package (${installSpec}) in: ${targetPath}...`);
148
+ await runCmd('npm', ['install', installSpec, '--no-audit', '--no-fund'], { cwd: targetPath });
149
+ }
150
+
151
+ console.log('\nStarting Setup Wizard...');
152
+ const cleanArgs = args.filter((arg) => arg !== '--update');
153
+
154
+ const child = spawn(process.argv[0], [cliPath, ...cleanArgs, `--project-dir=${projectDir}`], {
155
+ cwd: targetPath,
156
+ shell: false,
157
+ stdio: 'inherit',
158
+ env: {
159
+ ...process.env,
160
+ OPENCLAW_SETUP_WIZARD: 'true'
161
+ }
162
+ });
163
+ child.on('close', (code) => {
164
+ process.exit(code);
165
+ });
166
+ } catch (error) {
167
+ console.error('\n❌ Lỗi khi khởi động Setup Wizard:', error.message);
168
+ process.exit(1);
169
+ }
170
+ }
171
+
172
+