@supacortex/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.
- package/dist/index.js +89 -47
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,34 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __spreadValues = (a, b) => {
|
|
8
|
-
for (var prop in b || (b = {}))
|
|
9
|
-
if (__hasOwnProp.call(b, prop))
|
|
10
|
-
__defNormalProp(a, prop, b[prop]);
|
|
11
|
-
if (__getOwnPropSymbols)
|
|
12
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
-
if (__propIsEnum.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
}
|
|
16
|
-
return a;
|
|
17
|
-
};
|
|
18
|
-
var __objRest = (source, exclude) => {
|
|
19
|
-
var target = {};
|
|
20
|
-
for (var prop in source)
|
|
21
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
22
|
-
target[prop] = source[prop];
|
|
23
|
-
if (source != null && __getOwnPropSymbols)
|
|
24
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
25
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
26
|
-
target[prop] = source[prop];
|
|
27
|
-
}
|
|
28
|
-
return target;
|
|
29
|
-
};
|
|
30
2
|
|
|
31
3
|
// src/index.ts
|
|
4
|
+
import { createRequire } from "module";
|
|
32
5
|
import { Command } from "commander";
|
|
33
6
|
|
|
34
7
|
// src/lib/config.ts
|
|
@@ -43,14 +16,14 @@ var getConfig = () => {
|
|
|
43
16
|
const content = readFileSync(configPath, "utf-8");
|
|
44
17
|
const data = JSON.parse(content);
|
|
45
18
|
return data;
|
|
46
|
-
} catch
|
|
19
|
+
} catch {
|
|
47
20
|
return {};
|
|
48
21
|
}
|
|
49
22
|
};
|
|
50
23
|
var setConfig = (updates) => {
|
|
51
24
|
mkdirSync(configDir, { recursive: true });
|
|
52
25
|
const existing = getConfig();
|
|
53
|
-
const data =
|
|
26
|
+
const data = { ...existing, ...updates };
|
|
54
27
|
writeFileSync(configPath, JSON.stringify(data, null, 2));
|
|
55
28
|
};
|
|
56
29
|
var writeConfig = (config) => {
|
|
@@ -86,13 +59,13 @@ var apiRequest = async (path2, method, body) => {
|
|
|
86
59
|
},
|
|
87
60
|
body: body ? JSON.stringify(body) : void 0
|
|
88
61
|
});
|
|
89
|
-
} catch
|
|
62
|
+
} catch {
|
|
90
63
|
console.error(`Failed to connect to ${endpoint}`);
|
|
91
64
|
process.exit(1);
|
|
92
65
|
}
|
|
93
66
|
if (!res.ok) {
|
|
94
67
|
const errorBody = await res.json().catch(() => null);
|
|
95
|
-
const message =
|
|
68
|
+
const message = errorBody?.error || `${res.status} ${res.statusText}`;
|
|
96
69
|
console.error(`Error: ${message}`);
|
|
97
70
|
process.exit(1);
|
|
98
71
|
}
|
|
@@ -122,7 +95,7 @@ var registerLoginCommand = (program2) => {
|
|
|
122
95
|
deviceCode = data.deviceCode;
|
|
123
96
|
userCode = data.userCode;
|
|
124
97
|
verifyUrl = data.verifyUrl;
|
|
125
|
-
} catch
|
|
98
|
+
} catch {
|
|
126
99
|
console.error(`Failed to connect to ${appUrl}`);
|
|
127
100
|
process.exit(1);
|
|
128
101
|
}
|
|
@@ -155,7 +128,7 @@ var registerLoginCommand = (program2) => {
|
|
|
155
128
|
console.error("Code expired. Run `scx login` again.");
|
|
156
129
|
process.exit(1);
|
|
157
130
|
}
|
|
158
|
-
} catch
|
|
131
|
+
} catch {
|
|
159
132
|
}
|
|
160
133
|
}
|
|
161
134
|
console.error("Code expired. Run `scx login` again.");
|
|
@@ -166,7 +139,7 @@ var registerLoginCommand = (program2) => {
|
|
|
166
139
|
// src/commands/logout.ts
|
|
167
140
|
var registerLogoutCommand = (program2) => {
|
|
168
141
|
program2.command("logout").description("Log out and remove saved API key").action(() => {
|
|
169
|
-
const
|
|
142
|
+
const { apiKey, ...rest } = getConfig();
|
|
170
143
|
if (!apiKey) {
|
|
171
144
|
console.log("Not logged in.");
|
|
172
145
|
return;
|
|
@@ -193,7 +166,7 @@ var registerEndpointCommand = (program2) => {
|
|
|
193
166
|
return;
|
|
194
167
|
}
|
|
195
168
|
if (url === "reset") {
|
|
196
|
-
const
|
|
169
|
+
const { endpoint, ...rest } = getConfig();
|
|
197
170
|
writeConfig(rest);
|
|
198
171
|
console.log("Endpoint reset to default.");
|
|
199
172
|
return;
|
|
@@ -205,10 +178,10 @@ var registerEndpointCommand = (program2) => {
|
|
|
205
178
|
|
|
206
179
|
// src/commands/whoami.ts
|
|
207
180
|
var registerWhoamiCommand = (program2) => {
|
|
208
|
-
program2.command("whoami").action(() => {
|
|
181
|
+
program2.command("whoami").description("Show current config").action(() => {
|
|
209
182
|
const { endpoint, apiKey } = getConfig();
|
|
210
|
-
console.log(`Endpoint: ${endpoint
|
|
211
|
-
console.log(`API Key: ${apiKey
|
|
183
|
+
console.log(`Endpoint: ${endpoint ?? "not set"}`);
|
|
184
|
+
console.log(`API Key: ${apiKey ?? "not set"}`);
|
|
212
185
|
});
|
|
213
186
|
};
|
|
214
187
|
|
|
@@ -216,11 +189,10 @@ var registerWhoamiCommand = (program2) => {
|
|
|
216
189
|
var registerBookmarksCommand = (program2) => {
|
|
217
190
|
const bookmarks = program2.command("bookmarks");
|
|
218
191
|
bookmarks.command("list").option("-l, --limit <number>", "Max results", "20").option("-o, --offset <number>", "Skip results").option("-s, --search <string>", "Search bookmarks").option("-j, --json", "Output raw JSON").description("List all bookmarks").action(async (option) => {
|
|
219
|
-
var _a, _b;
|
|
220
192
|
const searchParams = new URLSearchParams();
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
193
|
+
if (option.limit) searchParams.append("limit", String(parseInt(option.limit, 10)));
|
|
194
|
+
if (option.offset) searchParams.append("offset", String(parseInt(option.offset, 10)));
|
|
195
|
+
if (option.search) searchParams.append("search", option.search);
|
|
224
196
|
const result = await apiRequest(
|
|
225
197
|
`bookmarks?${searchParams.toString()}`,
|
|
226
198
|
"GET"
|
|
@@ -238,7 +210,7 @@ var registerBookmarksCommand = (program2) => {
|
|
|
238
210
|
console.log(` ${b.author ? `@${b.author} \xB7 ` : ""}${b.type}`);
|
|
239
211
|
console.log();
|
|
240
212
|
}
|
|
241
|
-
console.log(`Showing ${data.length} of ${
|
|
213
|
+
console.log(`Showing ${data.length} of ${result.meta?.total ?? data.length} bookmarks`);
|
|
242
214
|
});
|
|
243
215
|
bookmarks.command("add").description("Add a new bookmark").argument("<url>", "URL to bookmark").option("-j, --json", "Output raw JSON").action(async (url, option) => {
|
|
244
216
|
const result = await apiRequest("bookmarks", "POST", { url });
|
|
@@ -307,13 +279,14 @@ var registerSyncCommand = (program2) => {
|
|
|
307
279
|
}
|
|
308
280
|
console.log(sinceYear ? `Syncing X bookmarks from ${sinceYear} onwards...` : "Syncing X bookmarks...");
|
|
309
281
|
const result = await apiRequest("sync", "POST", sinceYear ? { sinceYear } : void 0);
|
|
310
|
-
if (result.synced
|
|
282
|
+
if (!result.synced) {
|
|
311
283
|
console.log("Already up to date.");
|
|
312
284
|
} else {
|
|
313
285
|
console.log(`Synced ${result.synced} new bookmarks.`);
|
|
314
286
|
}
|
|
315
287
|
if (result.status === "interrupted") {
|
|
316
|
-
|
|
288
|
+
const resetMsg = result.rateLimitResetsAt ? ` Resets at ${new Date(result.rateLimitResetsAt).toLocaleString()}` : "";
|
|
289
|
+
console.log(`Rate limited.${resetMsg}`);
|
|
317
290
|
}
|
|
318
291
|
});
|
|
319
292
|
sync.command("status").description("Check latest sync status").action(async () => {
|
|
@@ -331,9 +304,76 @@ var registerSyncCommand = (program2) => {
|
|
|
331
304
|
});
|
|
332
305
|
};
|
|
333
306
|
|
|
307
|
+
// src/commands/update.ts
|
|
308
|
+
import { execSync } from "child_process";
|
|
309
|
+
var NPM_REGISTRY_URL = "https://registry.npmjs.org/@supacortex/cli/latest";
|
|
310
|
+
var registerUpdateCommand = (program2, version) => {
|
|
311
|
+
program2.command("update").description("Update Supacortex CLI to the latest version").action(async () => {
|
|
312
|
+
const currentVersion = version;
|
|
313
|
+
console.log(`Current version: ${currentVersion}`);
|
|
314
|
+
console.log("Checking for updates...");
|
|
315
|
+
console.log();
|
|
316
|
+
try {
|
|
317
|
+
const res = await fetch(NPM_REGISTRY_URL);
|
|
318
|
+
if (!res.ok) throw new Error("Failed to check npm registry");
|
|
319
|
+
const data = await res.json();
|
|
320
|
+
const latest = data.version;
|
|
321
|
+
if (latest === currentVersion) {
|
|
322
|
+
console.log("Already on the latest version.");
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
console.log(`New version available: ${latest}`);
|
|
326
|
+
console.log();
|
|
327
|
+
console.log("Updating...");
|
|
328
|
+
try {
|
|
329
|
+
execSync("npm update -g @supacortex/cli", { stdio: "ignore" });
|
|
330
|
+
console.log(`Updated to ${latest}`);
|
|
331
|
+
} catch {
|
|
332
|
+
console.log("Automatic update failed.");
|
|
333
|
+
console.log();
|
|
334
|
+
console.log("Update manually:");
|
|
335
|
+
console.log(" npm install -g @supacortex/cli@latest");
|
|
336
|
+
}
|
|
337
|
+
} catch (err) {
|
|
338
|
+
console.error(`Error: ${err.message}`);
|
|
339
|
+
process.exit(1);
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
// src/lib/update-notifier.ts
|
|
345
|
+
var NPM_REGISTRY_URL2 = "https://registry.npmjs.org/@supacortex/cli/latest";
|
|
346
|
+
var CHECK_INTERVAL = 24 * 60 * 60 * 1e3;
|
|
347
|
+
var checkForUpdates = (currentVersion) => {
|
|
348
|
+
const config = getConfig();
|
|
349
|
+
const now = Date.now();
|
|
350
|
+
if (config.latestVersion && config.latestVersion !== currentVersion) {
|
|
351
|
+
process.on("exit", () => {
|
|
352
|
+
console.log();
|
|
353
|
+
console.log(` Update available: ${currentVersion} \u2192 ${config.latestVersion}`);
|
|
354
|
+
console.log(` Run "scx update" to update`);
|
|
355
|
+
console.log();
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
if (config.lastUpdateCheck && now - config.lastUpdateCheck < CHECK_INTERVAL) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
fetch(NPM_REGISTRY_URL2).then((res) => res.ok ? res.json() : null).then((data) => {
|
|
362
|
+
if (data?.version) {
|
|
363
|
+
setConfig({
|
|
364
|
+
lastUpdateCheck: now,
|
|
365
|
+
latestVersion: data.version
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}).catch(() => {
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
|
|
334
372
|
// src/index.ts
|
|
373
|
+
var require2 = createRequire(import.meta.url);
|
|
374
|
+
var pkg = require2("../package.json");
|
|
335
375
|
var program = new Command();
|
|
336
|
-
program.name("scx").description("Supacortex CLI \u2014 your second brain from the terminal").version(
|
|
376
|
+
program.name("scx").description("Supacortex CLI \u2014 your second brain from the terminal").version(pkg.version);
|
|
337
377
|
registerLoginCommand(program);
|
|
338
378
|
registerLogoutCommand(program);
|
|
339
379
|
registerTokenCommand(program);
|
|
@@ -342,4 +382,6 @@ registerWhoamiCommand(program);
|
|
|
342
382
|
registerBookmarksCommand(program);
|
|
343
383
|
registerGroupsCommand(program);
|
|
344
384
|
registerSyncCommand(program);
|
|
385
|
+
registerUpdateCommand(program, pkg.version);
|
|
386
|
+
checkForUpdates(pkg.version);
|
|
345
387
|
program.parse();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supacortex/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Supacortex CLI — your second brain from the terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
13
|
"dev": "tsx src/index.ts",
|
|
14
|
-
"build": "tsup src/index.ts --format esm"
|
|
14
|
+
"build": "tsup src/index.ts --format esm --target node18"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
17
|
"supacortex",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/monorepo-labs/
|
|
24
|
+
"url": "https://github.com/monorepo-labs/supacortex"
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|