@wildbappy/bappy-cli 0.1.0 → 0.1.2
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/README.md +11 -9
- package/bin/bappy.js +42 -14
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# comptracker CLI (legacy package name: @wildbappy/bappy-cli)
|
|
2
2
|
|
|
3
|
-
Command-line access to
|
|
3
|
+
Command-line access to Comptracker's competitive intelligence dashboard subagent API.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install -g @wildbappy/
|
|
8
|
+
npm install -g @wildbappy/comptracker-cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
This package (`@wildbappy/bappy-cli`) remains supported for backwards compatibility, but the recommended install is `@wildbappy/comptracker-cli` so the install command matches the CLI name.
|
|
12
|
+
|
|
11
13
|
## First Run
|
|
12
14
|
|
|
13
15
|
```bash
|
|
14
|
-
|
|
16
|
+
comptracker "how many recent blog posts has peer AI made?"
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
On first run, the CLI prompts for your token:
|
|
@@ -22,9 +24,9 @@ On first run, the CLI prompts for your token:
|
|
|
22
24
|
## Commands
|
|
23
25
|
|
|
24
26
|
```bash
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
comptracker auth
|
|
28
|
+
comptracker logout
|
|
29
|
+
comptracker update
|
|
30
|
+
comptracker --json "question"
|
|
31
|
+
comptracker --url http://149-28-213-47.nip.io "question"
|
|
30
32
|
```
|
package/bin/bappy.js
CHANGED
|
@@ -9,8 +9,13 @@ const { stdin, stdout, stderr, exit } = require('process');
|
|
|
9
9
|
|
|
10
10
|
const DEFAULT_BASE_URL = 'http://149-28-213-47.nip.io';
|
|
11
11
|
const TOKEN_PATTERN = /^cta_[A-Za-z0-9_-]{20,}$/;
|
|
12
|
+
const TOOL_NAME = 'comptracker';
|
|
13
|
+
const TOOL_ALIASES = ['bappy'];
|
|
12
14
|
|
|
13
15
|
function notifyIfUpdateAvailable() {
|
|
16
|
+
// When invoked via the @wildbappy/comptracker-cli wrapper, let the wrapper
|
|
17
|
+
// handle update notifications so users aren't told to upgrade the dependency.
|
|
18
|
+
if (process.env.COMPTRACKER_CLI_WRAPPER === '1') return;
|
|
14
19
|
try {
|
|
15
20
|
const updateNotifier = require('update-notifier');
|
|
16
21
|
const pkg = require('../package.json');
|
|
@@ -27,15 +32,19 @@ function notifyIfUpdateAvailable() {
|
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
function getConfigDir() {
|
|
30
|
-
const envDir = String(process.env.BAPPY_CONFIG_DIR || '').trim();
|
|
35
|
+
const envDir = String(process.env.COMPTRACKER_CONFIG_DIR || process.env.BAPPY_CONFIG_DIR || '').trim();
|
|
31
36
|
if (envDir) return envDir;
|
|
32
|
-
return path.join(os.homedir(), '.
|
|
37
|
+
return path.join(os.homedir(), '.comptracker-cli');
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
function getConfigPath() {
|
|
36
41
|
return path.join(getConfigDir(), 'config.json');
|
|
37
42
|
}
|
|
38
43
|
|
|
44
|
+
function getLegacyConfigPath() {
|
|
45
|
+
return path.join(os.homedir(), '.bappy-cli', 'config.json');
|
|
46
|
+
}
|
|
47
|
+
|
|
39
48
|
async function readConfig() {
|
|
40
49
|
const file = getConfigPath();
|
|
41
50
|
try {
|
|
@@ -43,6 +52,16 @@ async function readConfig() {
|
|
|
43
52
|
const parsed = JSON.parse(raw);
|
|
44
53
|
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
45
54
|
} catch {
|
|
55
|
+
// Backwards compat: read legacy config if present.
|
|
56
|
+
try {
|
|
57
|
+
const raw = await fs.readFile(getLegacyConfigPath(), 'utf8');
|
|
58
|
+
const parsed = JSON.parse(raw);
|
|
59
|
+
if (parsed && typeof parsed === 'object') {
|
|
60
|
+
// Best-effort migration so future writes land in the new location.
|
|
61
|
+
try { await writeConfig(parsed); } catch {}
|
|
62
|
+
return parsed;
|
|
63
|
+
}
|
|
64
|
+
} catch {}
|
|
46
65
|
return {};
|
|
47
66
|
}
|
|
48
67
|
}
|
|
@@ -72,23 +91,26 @@ function sanitizeBaseUrl(value) {
|
|
|
72
91
|
}
|
|
73
92
|
|
|
74
93
|
function printWelcome(baseUrl) {
|
|
75
|
-
stdout.write("Welcome to
|
|
94
|
+
stdout.write("Welcome to Comptracker's competitive intelligence dashboard! Thanks for trying it out.\n\n");
|
|
76
95
|
stdout.write(`You can find your token in your settings at ${baseUrl}/ after you log in.\n\n`);
|
|
77
96
|
}
|
|
78
97
|
|
|
79
98
|
function printHelp() {
|
|
80
|
-
stdout.write(
|
|
99
|
+
stdout.write(`${TOOL_NAME} - Competitive intelligence CLI\n`);
|
|
100
|
+
stdout.write(`Alias: ${TOOL_ALIASES.join(', ')}\n\n`);
|
|
81
101
|
stdout.write(`Usage:\n`);
|
|
82
|
-
stdout.write(`
|
|
83
|
-
stdout.write(`
|
|
84
|
-
stdout.write(`
|
|
85
|
-
stdout.write(`
|
|
86
|
-
stdout.write(`
|
|
87
|
-
stdout.write(`
|
|
88
|
-
stdout.write(`
|
|
102
|
+
stdout.write(` ${TOOL_NAME} "<question>"\n`);
|
|
103
|
+
stdout.write(` ${TOOL_NAME} auth\n`);
|
|
104
|
+
stdout.write(` ${TOOL_NAME} logout\n`);
|
|
105
|
+
stdout.write(` ${TOOL_NAME} update\n`);
|
|
106
|
+
stdout.write(` ${TOOL_NAME} --url <baseUrl> "<question>"\n`);
|
|
107
|
+
stdout.write(` ${TOOL_NAME} --token <cta_...> "<question>"\n`);
|
|
108
|
+
stdout.write(` ${TOOL_NAME} --json "<question>"\n\n`);
|
|
89
109
|
stdout.write(`Env vars:\n`);
|
|
90
|
-
stdout.write(`
|
|
91
|
-
stdout.write(`
|
|
110
|
+
stdout.write(` COMPTRACKER_API_URL Override API base URL (preferred)\n`);
|
|
111
|
+
stdout.write(` COMPTRACKER_CONFIG_DIR Override config directory (preferred)\n`);
|
|
112
|
+
stdout.write(` BAPPY_API_URL Backwards-compatible alias\n`);
|
|
113
|
+
stdout.write(` BAPPY_CONFIG_DIR Backwards-compatible alias\n`);
|
|
92
114
|
}
|
|
93
115
|
|
|
94
116
|
function parseArgs(argv) {
|
|
@@ -272,7 +294,13 @@ async function run() {
|
|
|
272
294
|
}
|
|
273
295
|
|
|
274
296
|
const config = await readConfig();
|
|
275
|
-
const baseUrl = sanitizeBaseUrl(
|
|
297
|
+
const baseUrl = sanitizeBaseUrl(
|
|
298
|
+
flags.url ||
|
|
299
|
+
process.env.COMPTRACKER_API_URL ||
|
|
300
|
+
process.env.BAPPY_API_URL ||
|
|
301
|
+
config.baseUrl ||
|
|
302
|
+
DEFAULT_BASE_URL
|
|
303
|
+
);
|
|
276
304
|
|
|
277
305
|
if (command === 'logout') {
|
|
278
306
|
const next = { ...config, baseUrl };
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildbappy/bappy-cli",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "CLI for
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "CLI for Comptracker's competitive intelligence dashboard",
|
|
5
5
|
"bin": {
|
|
6
|
-
"bappy": "bin/bappy.js"
|
|
6
|
+
"bappy": "bin/bappy.js",
|
|
7
|
+
"comptracker": "bin/bappy.js"
|
|
7
8
|
},
|
|
8
9
|
"files": [
|
|
9
10
|
"bin",
|