@jacebenson/jsn 3.3.2 → 3.4.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/package.json +1 -1
- package/src/cli.js +5 -1
- package/src/commands/docs/docs.js +82 -1
- package/src/commands/docs/search.js +7 -1
- package/src/commands/docs/sync.js +3 -0
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -225,7 +225,11 @@ export function buildCLI() {
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
if (shouldCheckSkill) {
|
|
228
|
-
|
|
228
|
+
try {
|
|
229
|
+
checkSkill();
|
|
230
|
+
} catch {
|
|
231
|
+
// Non-fatal — don't crash the CLI if skill check fails
|
|
232
|
+
}
|
|
229
233
|
|
|
230
234
|
try {
|
|
231
235
|
fs.mkdirSync(globalConfigDir(), { recursive: true });
|
|
@@ -114,7 +114,84 @@ export function docsCmd(wrap) {
|
|
|
114
114
|
docType: argv['doc-type'],
|
|
115
115
|
mode: argv.mode,
|
|
116
116
|
});
|
|
117
|
-
|
|
117
|
+
|
|
118
|
+
// Build a readable text blob for styled TTY output.
|
|
119
|
+
const lines = [];
|
|
120
|
+
for (const r of result.results) {
|
|
121
|
+
const title = r.title || r.path || '(untitled)';
|
|
122
|
+
const snippet = (r.snippet || r.body || '')
|
|
123
|
+
.replace(/\\n/g, ' ')
|
|
124
|
+
.replace(/\s+/g, ' ')
|
|
125
|
+
.trim()
|
|
126
|
+
.substring(0, 200);
|
|
127
|
+
lines.push(`[${r.id}] ${title}`);
|
|
128
|
+
if (snippet) lines.push(` ${snippet}`);
|
|
129
|
+
lines.push('');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const hasMore = result.total > result.count;
|
|
133
|
+
if (hasMore) {
|
|
134
|
+
const nextOffset = (result.count + (argv.offset || 0));
|
|
135
|
+
lines.push(`… ${result.total - result.count} more results (use --offset ${nextOffset} for next page)`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
app.ok({
|
|
139
|
+
_formatted: lines.join('\n'),
|
|
140
|
+
query: result.query,
|
|
141
|
+
mode: result.mode,
|
|
142
|
+
total: result.total,
|
|
143
|
+
count: result.count,
|
|
144
|
+
results: result.results,
|
|
145
|
+
}, { summary: `${result.count} of ${result.total} result(s) for "${result.query}" (${result.mode})` });
|
|
146
|
+
}),
|
|
147
|
+
})
|
|
148
|
+
.command({
|
|
149
|
+
command: 'show <id-or-path>',
|
|
150
|
+
describe: 'Show a documentation page by id or path',
|
|
151
|
+
builder: (y) => y
|
|
152
|
+
.positional('id-or-path', { type: 'string', describe: 'Document id (number) or file path' })
|
|
153
|
+
.option('lines', { type: 'number', default: 80, describe: 'Lines of body to show in terminal (use --json for full content)' }),
|
|
154
|
+
handler: wrap(async (argv, app) => {
|
|
155
|
+
const idOrPath = argv['id-or-path'];
|
|
156
|
+
const db = openDocsDb();
|
|
157
|
+
let row;
|
|
158
|
+
if (/^\d+$/.test(idOrPath)) {
|
|
159
|
+
row = db.prepare('SELECT * FROM docs WHERE id = ?').get(parseInt(idOrPath, 10));
|
|
160
|
+
} else {
|
|
161
|
+
row = db.prepare('SELECT * FROM docs WHERE path LIKE ?').get(`%${idOrPath}%`);
|
|
162
|
+
if (!row) {
|
|
163
|
+
row = db.prepare(
|
|
164
|
+
`SELECT d.* FROM docs_fts JOIN docs d ON d.id = docs_fts.rowid WHERE docs_fts MATCH ? LIMIT 1`
|
|
165
|
+
).get(idOrPath);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
closeDocsDb(db);
|
|
169
|
+
|
|
170
|
+
if (!row) {
|
|
171
|
+
throw Object.assign(new Error(`No doc found for "${idOrPath}"`), { code: 'not_found' });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
let fm = {};
|
|
175
|
+
try { fm = JSON.parse(row.frontmatter || '{}'); } catch { /* ignore */ }
|
|
176
|
+
|
|
177
|
+
const title = row.title || fm.title || row.path || '(untitled)';
|
|
178
|
+
const header = `${title}\n${'─'.repeat(Math.min(title.length, 80))}`;
|
|
179
|
+
const body = row.body || '';
|
|
180
|
+
const bodyLines = body.split('\n');
|
|
181
|
+
const truncated = bodyLines.length > argv.lines;
|
|
182
|
+
const preview = bodyLines.slice(0, argv.lines).join('\n');
|
|
183
|
+
const hint = truncated ? `\n\n… ${bodyLines.length - argv.lines} more lines (use --lines ${bodyLines.length} or --json for full content)` : '';
|
|
184
|
+
|
|
185
|
+
app.ok({
|
|
186
|
+
id: row.id,
|
|
187
|
+
path: row.path,
|
|
188
|
+
title: row.title,
|
|
189
|
+
bundle: row.bundle,
|
|
190
|
+
release: row.release,
|
|
191
|
+
canonical_url: fm.canonical_url || null,
|
|
192
|
+
body,
|
|
193
|
+
_formatted: `${header}\n\n${preview}${hint}`,
|
|
194
|
+
}, { summary: `Doc ${row.id}: ${title}` });
|
|
118
195
|
}),
|
|
119
196
|
})
|
|
120
197
|
.command({
|
|
@@ -157,9 +234,13 @@ export function docsCmd(wrap) {
|
|
|
157
234
|
process.stdout.write(' sync Download docs and build a searchable index (handles updates too)\n');
|
|
158
235
|
process.stdout.write(' status Show whether docs are downloaded, indexed, embedded, or served\n');
|
|
159
236
|
process.stdout.write(' search Full-text + semantic search across the local docs index\n');
|
|
237
|
+
process.stdout.write(' show Display a full documentation page by id or path\n');
|
|
160
238
|
process.stdout.write(' serve Start a local web UI for browsing and searching docs\n');
|
|
161
239
|
process.stdout.write('\n');
|
|
162
240
|
process.stdout.write('Tip: use "jsn docs serve --expose" to bind to 0.0.0.0 and share on your network.\n');
|
|
241
|
+
process.stdout.write('\n');
|
|
242
|
+
const dbPath = getDocsDbPath();
|
|
243
|
+
process.stdout.write(`Docs DB: ${dbPath} (run "jsn docs status" for details, or query directly with sqlite3)\n`);
|
|
163
244
|
process.stdout.write('\nRun "jsn docs <command> --help" for details.\n');
|
|
164
245
|
},
|
|
165
246
|
};
|
|
@@ -25,7 +25,7 @@ export function searchDocs(opts = {}) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const db = new DatabaseSync(dbPath, { readOnly: true });
|
|
28
|
-
const limit = Math.min(parseInt(opts.limit, 10) || 20,
|
|
28
|
+
const limit = Math.min(parseInt(opts.limit, 10) || 20, 1000);
|
|
29
29
|
const offset = parseInt(opts.offset, 10) || 0;
|
|
30
30
|
const bundle = opts.bundle ? String(opts.bundle) : null;
|
|
31
31
|
const docType = opts.docType ? String(opts.docType) : null;
|
|
@@ -44,6 +44,11 @@ export function searchDocs(opts = {}) {
|
|
|
44
44
|
}
|
|
45
45
|
const where = filters.length ? ' AND ' + filters.join(' AND ') : '';
|
|
46
46
|
|
|
47
|
+
// Total matching docs (for pagination)
|
|
48
|
+
const total = db
|
|
49
|
+
.prepare(`SELECT COUNT(*) AS n FROM docs_fts WHERE docs_fts MATCH @q${where}`)
|
|
50
|
+
.get({ q, ...(bundle && { bundle }), ...(docType && { docType }) }).n;
|
|
51
|
+
|
|
47
52
|
let rows;
|
|
48
53
|
if (!useHybrid) {
|
|
49
54
|
rows = db
|
|
@@ -133,6 +138,7 @@ export function searchDocs(opts = {}) {
|
|
|
133
138
|
return {
|
|
134
139
|
query: q,
|
|
135
140
|
mode: useHybrid ? 'hybrid' : 'keyword',
|
|
141
|
+
total,
|
|
136
142
|
count: rows.length,
|
|
137
143
|
results: rows,
|
|
138
144
|
};
|
|
@@ -12,6 +12,9 @@ const BRANCH = 'australia';
|
|
|
12
12
|
|
|
13
13
|
function git(args, cwd, stdio = 'inherit') {
|
|
14
14
|
const r = spawnSync('git', args, { cwd, stdio });
|
|
15
|
+
if (r.error && r.error.code === 'ENOENT') {
|
|
16
|
+
throw new Error('git is not installed. Install git to sync docs, or download the docs repo manually.');
|
|
17
|
+
}
|
|
15
18
|
if (r.status !== 0) {
|
|
16
19
|
throw new Error(`git ${args[0]} failed (exit ${r.status}).`);
|
|
17
20
|
}
|