@clawcard/cli 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/bin/setup.mjs +21 -35
  2. package/package.json +1 -1
package/bin/setup.mjs CHANGED
@@ -6,7 +6,6 @@ import { homedir } from "os";
6
6
 
7
7
  const OPENCLAW_DIR = join(homedir(), ".openclaw");
8
8
  const SKILLS_DIR = join(OPENCLAW_DIR, "skills", "clawcard");
9
- const CONFIG_PATH = join(OPENCLAW_DIR, "openclaw.json");
10
9
  const SKILL_PATH = join(SKILLS_DIR, "SKILL.md");
11
10
 
12
11
  const DEFAULT_BASE_URL = "https://clawcard.sh";
@@ -133,18 +132,6 @@ function error(msg) {
133
132
  console.error(` \x1b[31m✗\x1b[0m ${msg}`);
134
133
  }
135
134
 
136
- function readJson(path) {
137
- try {
138
- return JSON.parse(readFileSync(path, "utf-8"));
139
- } catch {
140
- return null;
141
- }
142
- }
143
-
144
- function writeJson(path, data) {
145
- writeFileSync(path, JSON.stringify(data, null, 2) + "\n");
146
- }
147
-
148
135
  // ── Main ─────────────────────────────────────────────────────────
149
136
 
150
137
  const args = process.argv.slice(2);
@@ -182,33 +169,32 @@ mkdirSync(SKILLS_DIR, { recursive: true });
182
169
  writeFileSync(SKILL_PATH, SKILL_MD);
183
170
  success(`Skill written to ${SKILL_PATH}`);
184
171
 
185
- // 2. Update openclaw.json with env vars
186
- const config = readJson(CONFIG_PATH);
187
- if (!config) {
188
- error(`Could not read ${CONFIG_PATH}`);
189
- process.exit(1);
172
+ // 2. Write env vars to ~/.openclaw/.env
173
+ const ENV_PATH = join(OPENCLAW_DIR, ".env");
174
+ let envContent = "";
175
+ try {
176
+ envContent = readFileSync(ENV_PATH, "utf-8");
177
+ } catch {
178
+ // .env doesn't exist yet, that's fine
190
179
  }
191
180
 
192
- // Ensure skills.entries.clawcard.env exists
193
- if (!config.skills) config.skills = {};
194
- if (!config.skills.entries) config.skills.entries = {};
181
+ // Update or append each var
182
+ const envVars = {
183
+ CLAWCARD_API_KEY: apiKey,
184
+ CLAWCARD_BASE_URL: baseUrl,
185
+ };
195
186
 
196
- const existing = config.skills.entries.clawcard;
197
- if (existing?.env?.CLAWCARD_API_KEY && existing.env.CLAWCARD_API_KEY !== "YOUR_API_KEY_HERE") {
198
- warn("Existing ClawCard config found — updating API key");
187
+ for (const [key, value] of Object.entries(envVars)) {
188
+ const regex = new RegExp(`^${key}=.*$`, "m");
189
+ if (regex.test(envContent)) {
190
+ envContent = envContent.replace(regex, `${key}=${value}`);
191
+ } else {
192
+ envContent = envContent.trimEnd() + `\n${key}=${value}\n`;
193
+ }
199
194
  }
200
195
 
201
- config.skills.entries.clawcard = {
202
- ...existing,
203
- env: {
204
- ...(existing?.env || {}),
205
- CLAWCARD_API_KEY: apiKey,
206
- CLAWCARD_BASE_URL: baseUrl,
207
- },
208
- };
209
-
210
- writeJson(CONFIG_PATH, config);
211
- success(`Config updated in ${CONFIG_PATH}`);
196
+ writeFileSync(ENV_PATH, envContent);
197
+ success(`Credentials written to ${ENV_PATH}`);
212
198
 
213
199
  // 3. Done
214
200
  console.log();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawcard/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Set up ClawCard for your OpenClaw agent in one command",
5
5
  "bin": {
6
6
  "clawcard": "./bin/setup.mjs"