@lobehub/market-cli 0.0.5 → 0.0.6

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.
Files changed (2) hide show
  1. package/dist/cli.js +127 -2
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -198,7 +198,7 @@ function registerRegisterCommand(program2) {
198
198
  },
199
199
  platform: process.arch,
200
200
  source,
201
- version: "0.0.5"
201
+ version: "0.0.6"
202
202
  });
203
203
  await saveCredentials({
204
204
  baseUrl: baseURL,
@@ -221,9 +221,134 @@ function registerRegisterCommand(program2) {
221
221
  });
222
222
  }
223
223
 
224
+ // src/commands/skills.ts
225
+ import { MarketSDK as MarketSDK3 } from "@lobehub/market-sdk";
226
+ import { writeFileSync } from "fs";
227
+ import { resolve } from "path";
228
+
229
+ // src/utils/table.ts
230
+ function truncate(text, maxWidth) {
231
+ if (text.length <= maxWidth) return text;
232
+ return text.slice(0, maxWidth - 1) + "\u2026";
233
+ }
234
+ function renderTable(columns, rows) {
235
+ const widths = columns.map((col) => {
236
+ let width = col.label.length;
237
+ for (const row of rows) {
238
+ const val = String(row[col.key] ?? "");
239
+ width = Math.max(width, val.length);
240
+ }
241
+ return col.maxWidth ? Math.min(width, col.maxWidth) : width;
242
+ });
243
+ const lines = [];
244
+ const header = columns.map((col, i) => {
245
+ const label = col.maxWidth ? truncate(col.label, col.maxWidth) : col.label;
246
+ return label.padEnd(widths[i]);
247
+ }).join(" ");
248
+ lines.push(header);
249
+ for (const row of rows) {
250
+ const cells = columns.map((col, i) => {
251
+ const raw = String(row[col.key] ?? "");
252
+ const val = col.maxWidth ? truncate(raw, col.maxWidth) : raw;
253
+ return val.padEnd(widths[i]);
254
+ });
255
+ lines.push(cells.join(" "));
256
+ }
257
+ return lines.join("\n");
258
+ }
259
+
260
+ // src/commands/skills.ts
261
+ function createSDK() {
262
+ const config = resolveConfig();
263
+ if (!config.clientId || !config.clientSecret) {
264
+ console.error(
265
+ "No credentials found. Run `lobehub-market register` first or set MARKET_CLIENT_ID and MARKET_CLIENT_SECRET."
266
+ );
267
+ process.exit(1);
268
+ }
269
+ return new MarketSDK3({
270
+ baseURL: config.baseUrl,
271
+ clientId: config.clientId,
272
+ clientSecret: config.clientSecret
273
+ });
274
+ }
275
+ function formatCount(n) {
276
+ if (n >= 1e3) return `${(n / 1e3).toFixed(1)}k`;
277
+ return String(n);
278
+ }
279
+ function registerSkillsCommand(program2) {
280
+ const skills = program2.command("skills").description("Browse and install skills from the marketplace");
281
+ skills.command("search").description("Search skills in the marketplace").option("--q <query>", "Search query").option("--category <category>", "Filter by category").option("--sort <field>", "Sort field (createdAt|stars|installCount|name|relevance|updatedAt)").option("--order <order>", "Sort order (asc|desc)").option("--page <number>", "Page number", "1").option("--page-size <number>", "Items per page", "20").option("--locale <locale>", "Locale for content (e.g. en-US, zh-CN)").option("--output <format>", "Output format (text|json)", "text").action(async (options) => {
282
+ try {
283
+ const sdk = createSDK();
284
+ const result = await sdk.marketSkills.getSkillList({
285
+ category: options.category,
286
+ locale: options.locale,
287
+ order: options.order,
288
+ page: Number(options.page),
289
+ pageSize: Number(options.pageSize),
290
+ q: options.q,
291
+ sort: options.sort
292
+ });
293
+ if (options.output === "json") {
294
+ formatOutput("json", result);
295
+ return;
296
+ }
297
+ if (result.items.length === 0) {
298
+ console.log("No skills found.");
299
+ return;
300
+ }
301
+ const rows = result.items.map((item) => ({
302
+ description: item.description,
303
+ identifier: item.identifier,
304
+ installs: formatCount(item.installCount),
305
+ name: item.name,
306
+ stars: !!item.github?.stars ? formatCount(item.github.stars) : "-"
307
+ }));
308
+ const table = renderTable(
309
+ [
310
+ { key: "identifier", label: "IDENTIFIER", maxWidth: 30 },
311
+ { key: "name", label: "NAME", maxWidth: 20 },
312
+ { key: "description", label: "DESCRIPTION", maxWidth: 40 },
313
+ { key: "stars", label: "STARS" },
314
+ { key: "installs", label: "INSTALLS" }
315
+ ],
316
+ rows
317
+ );
318
+ console.log(table);
319
+ const start = (result.currentPage - 1) * result.pageSize + 1;
320
+ const end = start + result.items.length - 1;
321
+ console.log(`
322
+ Showing ${start}-${end} of ${result.totalCount} results`);
323
+ } catch (error) {
324
+ console.error(`Search failed: ${error.message}`);
325
+ process.exit(1);
326
+ }
327
+ });
328
+ skills.command("install <identifier>").description("Download a skill package").option("--version <version>", "Specific version to download").option("--output <path>", "Output file path (defaults to current directory)").action(async (identifier, options) => {
329
+ try {
330
+ const sdk = createSDK();
331
+ console.log(
332
+ `Downloading skill: ${identifier}${options.version ? `@${options.version}` : ""}...`
333
+ );
334
+ const { buffer, filename } = await sdk.marketSkills.downloadSkill(
335
+ identifier,
336
+ options.version
337
+ );
338
+ const outputPath = options.output || resolve(process.cwd(), filename);
339
+ writeFileSync(outputPath, Buffer.from(buffer));
340
+ console.log(`Saved to ${outputPath} (${buffer.byteLength} bytes)`);
341
+ } catch (error) {
342
+ console.error(`Install failed: ${error.message}`);
343
+ process.exit(1);
344
+ }
345
+ });
346
+ }
347
+
224
348
  // src/cli.ts
225
349
  var program = new Command();
226
- program.name("lobehub-market").description("LobeHub Market CLI - Device registration and auth management").version("0.0.5");
350
+ program.name("lobehub-market").description("LobeHub Market CLI - Device registration and auth management").version("0.0.6");
227
351
  registerRegisterCommand(program);
228
352
  registerAuthCommand(program);
353
+ registerSkillsCommand(program);
229
354
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/market-cli",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "LobeHub Market CLI - Device registration and auth management",
5
5
  "keywords": [
6
6
  "lobehub",