@ls-apis/cli 0.0.4 → 0.0.7
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 +92 -2
- package/data/apis.json +891 -731
- package/dist/categories.js +1 -1
- package/dist/formatter.js +0 -1
- package/dist/index.js +6 -15
- package/dist/providers.js +2 -6
- package/dist/qa.js +1 -1
- package/package.json +3 -1
- package/dist/config.js +0 -36
- package/dist/search.js +0 -50
- package/dist/types.js +0 -1
package/dist/categories.js
CHANGED
package/dist/formatter.js
CHANGED
|
@@ -13,7 +13,6 @@ function formatText(results, total, limit, options) {
|
|
|
13
13
|
lines.push(color.cyan(` ${api.name}`));
|
|
14
14
|
lines.push(` ${color.dim('Description:')} ${truncate(api.description ?? 'No description', maxLen)}`);
|
|
15
15
|
lines.push(` ${color.dim('Link:')} ${api.link}`);
|
|
16
|
-
// Test missing braces - should trigger ESLint error
|
|
17
16
|
if (api.auth !== undefined && api.auth !== null) {
|
|
18
17
|
lines.push(` ${color.dim('Auth:')} ${color.yellow(api.auth)}`);
|
|
19
18
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
2
|
import { join, dirname } from 'node:path';
|
|
4
3
|
import { fileURLToPath } from 'node:url';
|
|
5
4
|
import yargs from 'yargs';
|
|
6
5
|
import { hideBin } from 'yargs/helpers';
|
|
7
6
|
import { initColors } from './colors.js';
|
|
8
|
-
import { loadConfig, getConfig } from '
|
|
9
|
-
import {
|
|
7
|
+
import { loadConfig, getConfig } from '@ls-apis/shared/config';
|
|
8
|
+
import { loadDataFile, getVersion } from '@ls-apis/shared/data';
|
|
9
|
+
import { search } from '@ls-apis/shared/search';
|
|
10
10
|
import { formatResults } from './formatter.js';
|
|
11
11
|
import { handleCategories } from './categories.js';
|
|
12
12
|
import { handleProviders } from './providers.js';
|
|
13
13
|
import { runQa } from './qa.js';
|
|
14
|
-
let version;
|
|
15
|
-
async function getVersion() {
|
|
16
|
-
if (!version) {
|
|
17
|
-
const packageJsonPath = join(dirname(fileURLToPath(import.meta.url)), '../package.json');
|
|
18
|
-
const pkg = JSON.parse(await readFile(packageJsonPath, 'utf-8'));
|
|
19
|
-
version = pkg.version;
|
|
20
|
-
}
|
|
21
|
-
return version;
|
|
22
|
-
}
|
|
23
14
|
export async function run(argv) {
|
|
24
15
|
const config = await loadConfig();
|
|
25
|
-
const ver = await getVersion();
|
|
16
|
+
const ver = await getVersion(import.meta.url);
|
|
26
17
|
const dataFile = join(dirname(fileURLToPath(import.meta.url)), '../data/apis.json');
|
|
27
|
-
const data = await
|
|
28
|
-
const { apis, providers } =
|
|
18
|
+
const data = await loadDataFile(import.meta.url, dataFile);
|
|
19
|
+
const { apis, providers } = data;
|
|
29
20
|
let exitEarly = false;
|
|
30
21
|
const args = await yargs(argv)
|
|
31
22
|
.scriptName('ls-apis')
|
package/dist/providers.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
+
import { getProviders } from '@ls-apis/shared/search';
|
|
1
2
|
import { formatProviders } from './formatter.js';
|
|
2
3
|
import { initColors } from './colors.js';
|
|
3
4
|
export function handleProviders(providers, apis, argv, config) {
|
|
4
5
|
const noColor = argv.color === false;
|
|
5
6
|
initColors(noColor ?? !config.colors);
|
|
6
|
-
const counts =
|
|
7
|
-
for (const api of apis) {
|
|
8
|
-
for (const source of api.sources) {
|
|
9
|
-
counts.set(source, (counts.get(source) ?? 0) + 1);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
7
|
+
const counts = getProviders(apis);
|
|
12
8
|
const providersWithCounts = providers.map((p) => ({
|
|
13
9
|
...p,
|
|
14
10
|
count: counts.get(p.name) ?? 0,
|
package/dist/qa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execSync } from 'node:child_process';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { projectRoot } from '
|
|
3
|
+
import { projectRoot } from '@ls-apis/shared/paths';
|
|
4
4
|
export async function runQa(descriptionMaxLength, outputFile) {
|
|
5
5
|
const root = projectRoot(import.meta.url);
|
|
6
6
|
const script = join(root, 'packages/aggregator/src/qa/index.ts');
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ls-apis/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Public APIs Discovery for Humans & Agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"ls-apis": "./dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
+
"typecheck": "tsc --noEmit",
|
|
10
11
|
"build": "tsc && tsc-esm-fix --target dist",
|
|
11
12
|
"start": "node dist/index.js",
|
|
12
13
|
"ls-apis": "node dist/index.js",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"access": "public"
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
52
|
+
"@ls-apis/shared": "*",
|
|
51
53
|
"chalk": "^5.6.2",
|
|
52
54
|
"yargs": "^17.7.2"
|
|
53
55
|
},
|
package/dist/config.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { readFile, writeFile, access } from 'node:fs/promises';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
export const CONFIG_PATH = join(homedir(), '.ls-apis');
|
|
5
|
-
const DEFAULTS = {
|
|
6
|
-
limit: 20,
|
|
7
|
-
descriptionMaxLength: 250,
|
|
8
|
-
colors: true,
|
|
9
|
-
};
|
|
10
|
-
export async function loadConfig() {
|
|
11
|
-
try {
|
|
12
|
-
const raw = await readFile(CONFIG_PATH, 'utf-8');
|
|
13
|
-
const parsed = JSON.parse(raw);
|
|
14
|
-
return {
|
|
15
|
-
limit: parsed.limit ?? DEFAULTS.limit,
|
|
16
|
-
descriptionMaxLength: parsed.descriptionMaxLength ?? DEFAULTS.descriptionMaxLength,
|
|
17
|
-
colors: parsed.colors ?? DEFAULTS.colors,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
await ensureConfigExists();
|
|
22
|
-
return DEFAULTS;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async function ensureConfigExists() {
|
|
26
|
-
try {
|
|
27
|
-
await access(CONFIG_PATH);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
await writeFile(CONFIG_PATH, JSON.stringify(DEFAULTS, null, 2) + '\n');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export async function getConfig() {
|
|
34
|
-
const config = await loadConfig();
|
|
35
|
-
return { config, filePath: CONFIG_PATH };
|
|
36
|
-
}
|
package/dist/search.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export function search(apis, options) {
|
|
2
|
-
let results = apis;
|
|
3
|
-
if (options.query) {
|
|
4
|
-
const q = options.query.toLowerCase();
|
|
5
|
-
results = results.filter((api) => api.name.toLowerCase().includes(q) || api.description?.toLowerCase().includes(q));
|
|
6
|
-
}
|
|
7
|
-
if (options.category) {
|
|
8
|
-
const cat = options.category.toLowerCase();
|
|
9
|
-
results = results.filter((api) => api.categories.some((c) => c.toLowerCase().includes(cat)));
|
|
10
|
-
}
|
|
11
|
-
if (options.auth) {
|
|
12
|
-
const auth = options.auth.toLowerCase();
|
|
13
|
-
results = results.filter((api) => {
|
|
14
|
-
if (auth === 'no') {
|
|
15
|
-
return !api.auth;
|
|
16
|
-
}
|
|
17
|
-
return api.auth?.toLowerCase().includes(auth);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
if (options.sort) {
|
|
21
|
-
results = [...results].sort((a, b) => {
|
|
22
|
-
switch (options.sort) {
|
|
23
|
-
case 'name':
|
|
24
|
-
return a.name.localeCompare(b.name);
|
|
25
|
-
case 'category': {
|
|
26
|
-
const catA = a.categories[0] ?? '';
|
|
27
|
-
const catB = b.categories[0] ?? '';
|
|
28
|
-
return catA.localeCompare(catB);
|
|
29
|
-
}
|
|
30
|
-
case 'auth': {
|
|
31
|
-
const authA = a.auth ?? '';
|
|
32
|
-
const authB = b.auth ?? '';
|
|
33
|
-
return authA.localeCompare(authB);
|
|
34
|
-
}
|
|
35
|
-
default:
|
|
36
|
-
return 0;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return results;
|
|
41
|
-
}
|
|
42
|
-
export function getCategories(apis) {
|
|
43
|
-
const map = new Map();
|
|
44
|
-
for (const api of apis) {
|
|
45
|
-
for (const cat of api.categories) {
|
|
46
|
-
map.set(cat, (map.get(cat) ?? 0) + 1);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return map;
|
|
50
|
-
}
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|