akademia 0.1.1 → 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 +18 -6
- package/bin/akademia.js +150 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,20 +12,32 @@ akademia
|
|
|
12
12
|
Po instalacji wpisz:
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
akademia
|
|
15
|
+
akademia
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Program zostanie otwarty w terminalu. Wpisz frazę, której szukasz:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
landing page
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Po wynikach wpisz numer, żeby otworzyć materiał:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
1
|
|
16
28
|
```
|
|
17
29
|
|
|
18
|
-
|
|
30
|
+
W każdej chwili możesz wpisać:
|
|
19
31
|
|
|
20
32
|
```bash
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
pomoc
|
|
34
|
+
status
|
|
35
|
+
wyjdz
|
|
24
36
|
```
|
|
25
37
|
|
|
26
38
|
## Prywatność
|
|
27
39
|
|
|
28
|
-
CLI V1 pobiera tylko publiczne pliki JSON.
|
|
40
|
+
CLI V1 pobiera tylko publiczne pliki JSON. Samo otwarcie programu i wyszukiwanie nie wysyła kodu projektu, plików, maili ani danych klientów do Akademii.
|
|
29
41
|
|
|
30
42
|
## API
|
|
31
43
|
|
package/bin/akademia.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import readline from "node:readline/promises";
|
|
3
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
2
4
|
import { AkademiaClient } from "../src/client.js";
|
|
3
5
|
import { writeReport } from "../src/report.js";
|
|
4
6
|
import { scanProject } from "../src/scan.js";
|
|
5
7
|
import { searchResources } from "../src/search.js";
|
|
6
8
|
import { printDoctor, printResource, printScanResults, printSearchResults } from "../src/format.js";
|
|
7
9
|
|
|
8
|
-
const VERSION = "0.1.
|
|
10
|
+
const VERSION = "0.1.2";
|
|
9
11
|
|
|
10
12
|
async function main(argv) {
|
|
11
13
|
const { command, args, flags } = parseArgs(argv);
|
|
@@ -22,7 +24,7 @@ async function main(argv) {
|
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
if (!command) {
|
|
25
|
-
await
|
|
27
|
+
await startInteractive(client);
|
|
26
28
|
return;
|
|
27
29
|
}
|
|
28
30
|
|
|
@@ -195,6 +197,152 @@ Szczegół techniczny: ${error.message}
|
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
199
|
|
|
200
|
+
async function startInteractive(client) {
|
|
201
|
+
let catalog;
|
|
202
|
+
try {
|
|
203
|
+
catalog = await client.catalog();
|
|
204
|
+
} catch (error) {
|
|
205
|
+
printOfflineStart(error);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
printInteractiveStart(catalog);
|
|
210
|
+
|
|
211
|
+
const rl = readline.createInterface({ input, output });
|
|
212
|
+
let lastResults = [];
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
rl.setPrompt("> ");
|
|
216
|
+
promptAgain(rl);
|
|
217
|
+
|
|
218
|
+
for await (const line of rl) {
|
|
219
|
+
const answer = line.trim();
|
|
220
|
+
const normalized = answer.toLowerCase();
|
|
221
|
+
|
|
222
|
+
if (!answer) {
|
|
223
|
+
promptAgain(rl);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (["wyjdz", "wyjdź", "exit", "quit", "q"].includes(normalized)) {
|
|
228
|
+
console.log("Do zobaczenia.");
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (isHelpCommand(normalized)) {
|
|
233
|
+
printInteractiveHelp();
|
|
234
|
+
promptAgain(rl);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (normalizeCommand(normalized) === "doctor") {
|
|
239
|
+
const freshCatalog = await client.catalog();
|
|
240
|
+
printDoctor(freshCatalog, client.baseUrl);
|
|
241
|
+
console.log("");
|
|
242
|
+
promptAgain(rl);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const resourceId = parseShowInput(answer);
|
|
247
|
+
if (resourceId) {
|
|
248
|
+
const resource = await client.resource(resourceId);
|
|
249
|
+
printResource(resource, { full: false });
|
|
250
|
+
console.log("");
|
|
251
|
+
promptAgain(rl);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (/^\d+$/.test(answer) && lastResults[Number(answer) - 1]) {
|
|
256
|
+
const resource = await client.resource(lastResults[Number(answer) - 1].id);
|
|
257
|
+
printResource(resource, { full: false });
|
|
258
|
+
console.log("");
|
|
259
|
+
promptAgain(rl);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const index = await client.searchIndex();
|
|
264
|
+
lastResults = searchResources(index, stripSearchPrefix(answer), { limit: 5 });
|
|
265
|
+
printInteractiveSearchResults(lastResults);
|
|
266
|
+
promptAgain(rl);
|
|
267
|
+
}
|
|
268
|
+
} finally {
|
|
269
|
+
rl.close();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function promptAgain(rl) {
|
|
274
|
+
if (input.isTTY) rl.prompt();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function printInteractiveStart(catalog) {
|
|
278
|
+
const resources = catalog?.resources || [];
|
|
279
|
+
const prompts = resources.filter((item) => item.type === "prompt").length;
|
|
280
|
+
const checklists = resources.filter((item) => item.type === "checklist").length;
|
|
281
|
+
|
|
282
|
+
console.log(`Akademia.pl CLI ${VERSION}
|
|
283
|
+
|
|
284
|
+
Działa. Masz dostęp do ${resources.length} publicznych materiałów.
|
|
285
|
+
Prompty: ${prompts}. Checklisty: ${checklists}.
|
|
286
|
+
|
|
287
|
+
Wpisz, czego szukasz, np. landing page.
|
|
288
|
+
Możesz też wpisać: pomoc, status, wyjdz.
|
|
289
|
+
`);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function printOfflineStart(error) {
|
|
293
|
+
console.log(`Akademia.pl CLI ${VERSION}
|
|
294
|
+
|
|
295
|
+
CLI jest zainstalowane, ale nie udało się połączyć z Akademia.pl.
|
|
296
|
+
|
|
297
|
+
Wpisz:
|
|
298
|
+
akademia pomoc
|
|
299
|
+
|
|
300
|
+
Szczegół techniczny: ${error.message}
|
|
301
|
+
`);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function printInteractiveHelp() {
|
|
305
|
+
console.log(`
|
|
306
|
+
Wpisz frazę, której szukasz:
|
|
307
|
+
landing page
|
|
308
|
+
umowa
|
|
309
|
+
oferta
|
|
310
|
+
|
|
311
|
+
Po wynikach wpisz numer, żeby otworzyć materiał:
|
|
312
|
+
1
|
|
313
|
+
|
|
314
|
+
Inne komendy:
|
|
315
|
+
status
|
|
316
|
+
wyjdz
|
|
317
|
+
`);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function parseShowInput(value) {
|
|
321
|
+
const match = value.match(/^(pokaz|pokaż|show)\s+(.+)$/i);
|
|
322
|
+
return match ? match[2].trim() : "";
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function stripSearchPrefix(value) {
|
|
326
|
+
return value.replace(/^(szukaj|search)\s+/i, "").trim();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function printInteractiveSearchResults(results) {
|
|
330
|
+
if (!results.length) {
|
|
331
|
+
console.log("Nie znalazłem pasujących materiałów. Spróbuj inną frazę.");
|
|
332
|
+
console.log("");
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
console.log("Znalazłem:");
|
|
337
|
+
for (const [index, item] of results.entries()) {
|
|
338
|
+
console.log(`${index + 1}. ${item.title}`);
|
|
339
|
+
console.log(` ${item.type === "prompt" ? "prompt" : "checklista"}, ${item.application || item.applicationSlug || "Akademia"}`);
|
|
340
|
+
}
|
|
341
|
+
console.log("");
|
|
342
|
+
console.log("Wpisz numer, żeby otworzyć materiał, albo wpisz kolejną frazę.");
|
|
343
|
+
console.log("");
|
|
344
|
+
}
|
|
345
|
+
|
|
198
346
|
function printHelp() {
|
|
199
347
|
console.log(`Akademia.pl CLI ${VERSION}
|
|
200
348
|
|