greenrun-cli 0.2.4 → 0.2.5
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/commands/init.js +51 -5
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -3,6 +3,7 @@ import { execSync } from 'child_process';
|
|
|
3
3
|
import { existsSync, readFileSync, writeFileSync, mkdirSync, appendFileSync } from 'fs';
|
|
4
4
|
import { join, dirname } from 'path';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
|
+
import { homedir } from 'os';
|
|
6
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
7
8
|
const __dirname = dirname(__filename);
|
|
8
9
|
const TEMPLATES_DIR = join(__dirname, '..', '..', 'templates');
|
|
@@ -64,22 +65,65 @@ async function validateToken(token) {
|
|
|
64
65
|
return { valid: false };
|
|
65
66
|
}
|
|
66
67
|
}
|
|
68
|
+
function getClaudeConfigPath() {
|
|
69
|
+
return join(homedir(), '.claude.json');
|
|
70
|
+
}
|
|
71
|
+
function readClaudeConfig() {
|
|
72
|
+
const configPath = getClaudeConfigPath();
|
|
73
|
+
if (!existsSync(configPath))
|
|
74
|
+
return {};
|
|
75
|
+
try {
|
|
76
|
+
return JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function writeClaudeConfig(config) {
|
|
83
|
+
writeFileSync(getClaudeConfigPath(), JSON.stringify(config, null, 2) + '\n');
|
|
84
|
+
}
|
|
85
|
+
function setLocalMcpServer(name, server) {
|
|
86
|
+
const config = readClaudeConfig();
|
|
87
|
+
const projectPath = process.cwd();
|
|
88
|
+
config.projects = config.projects || {};
|
|
89
|
+
config.projects[projectPath] = config.projects[projectPath] || {};
|
|
90
|
+
config.projects[projectPath].mcpServers = config.projects[projectPath].mcpServers || {};
|
|
91
|
+
config.projects[projectPath].mcpServers[name] = server;
|
|
92
|
+
writeClaudeConfig(config);
|
|
93
|
+
}
|
|
67
94
|
function configureMcpLocal(token) {
|
|
68
95
|
try {
|
|
69
|
-
|
|
96
|
+
setLocalMcpServer('greenrun', {
|
|
97
|
+
type: 'stdio',
|
|
98
|
+
command: 'npx',
|
|
99
|
+
args: ['-y', 'greenrun-cli@latest'],
|
|
100
|
+
env: { GREENRUN_API_TOKEN: token },
|
|
101
|
+
});
|
|
102
|
+
console.log(' Configured greenrun MCP server');
|
|
70
103
|
}
|
|
71
104
|
catch {
|
|
72
|
-
console.error('\nFailed to
|
|
105
|
+
console.error('\nFailed to write greenrun MCP config to ~/.claude.json');
|
|
73
106
|
console.error('You can add the MCP server manually by running:\n');
|
|
74
107
|
console.error(` claude mcp add greenrun --transport stdio -e GREENRUN_API_TOKEN=${token} -- npx -y greenrun-cli@latest\n`);
|
|
75
108
|
}
|
|
76
109
|
}
|
|
77
110
|
function configurePlaywrightMcp() {
|
|
78
111
|
try {
|
|
79
|
-
|
|
112
|
+
setLocalMcpServer('playwright', {
|
|
113
|
+
type: 'stdio',
|
|
114
|
+
command: 'npx',
|
|
115
|
+
args: [
|
|
116
|
+
'@playwright/mcp@latest',
|
|
117
|
+
'--browser', 'chrome',
|
|
118
|
+
'--user-data-dir', join(homedir(), '.greenrun', 'browser-profile'),
|
|
119
|
+
],
|
|
120
|
+
env: {},
|
|
121
|
+
});
|
|
122
|
+
console.log(' Configured playwright MCP server');
|
|
80
123
|
}
|
|
81
124
|
catch {
|
|
82
|
-
console.error('\nFailed to
|
|
125
|
+
console.error('\nFailed to write Playwright MCP config to ~/.claude.json');
|
|
126
|
+
console.error('You can add it manually:\n');
|
|
83
127
|
console.error(' claude mcp add playwright -- npx @playwright/mcp@latest --browser chrome --user-data-dir ~/.greenrun/browser-profile\n');
|
|
84
128
|
}
|
|
85
129
|
}
|
|
@@ -117,7 +161,9 @@ function configureMcpProject(token) {
|
|
|
117
161
|
console.log(' Added GREENRUN_API_TOKEN to .env');
|
|
118
162
|
}
|
|
119
163
|
else {
|
|
120
|
-
|
|
164
|
+
const updated = envContent.replace(/GREENRUN_API_TOKEN=.*/g, envLine);
|
|
165
|
+
writeFileSync(envPath, updated);
|
|
166
|
+
console.log(' Updated GREENRUN_API_TOKEN in .env');
|
|
121
167
|
}
|
|
122
168
|
}
|
|
123
169
|
else {
|