@tencent-map/lbs-skills 0.0.1 → 0.0.3

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/bin/cli.js +44 -17
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  const lib = require('../lib/index.js');
5
+ const { version } = require('../package.json');
5
6
 
6
7
  // ─── 工具函数 ────────────────────────────────────────────────────────
7
8
 
@@ -45,7 +46,7 @@ function parseArgs(argv) {
45
46
  // ─── 帮助信息 ────────────────────────────────────────────────────────
46
47
 
47
48
  const HELP = `
48
- tmap-lbs — 腾讯地图位置服务 CLI
49
+ tmap-lbs v${version} — 腾讯地图位置服务 CLI
49
50
 
50
51
  Usage:
51
52
  tmap-lbs <command> [options]
@@ -228,9 +229,7 @@ async function cmdConfig(positional) {
228
229
  case 'get-key': {
229
230
  const key = lib.getKey();
230
231
  if (key) {
231
- const masked = key.length > 8
232
- ? key.slice(0, 4) + '*'.repeat(key.length - 8) + key.slice(-4)
233
- : '****';
232
+ const masked = key.length > 8 ? key.slice(0, 4) + '*'.repeat(key.length - 8) + key.slice(-4) : '****';
234
233
  console.log(`当前 Key: ${masked}`);
235
234
  } else {
236
235
  console.log('未设置 API Key');
@@ -253,7 +252,10 @@ async function cmdConfig(positional) {
253
252
  }
254
253
 
255
254
  async function cmdSearch(args) {
256
- if (args.help) { console.log(HELP_SEARCH); return; }
255
+ if (args.help) {
256
+ console.log(HELP_SEARCH);
257
+ return;
258
+ }
257
259
  if (!args.keywords) fatal('缺少 --keywords 参数');
258
260
 
259
261
  const result = await lib.searchPOI({
@@ -285,7 +287,10 @@ async function cmdSearch(args) {
285
287
  }
286
288
 
287
289
  async function cmdGeocode(args) {
288
- if (args.help) { console.log(HELP_GEOCODE); return; }
290
+ if (args.help) {
291
+ console.log(HELP_GEOCODE);
292
+ return;
293
+ }
289
294
  if (!args.address) fatal('缺少 --address 参数');
290
295
 
291
296
  const result = await lib.geocode({ address: args.address });
@@ -302,19 +307,26 @@ async function cmdGeocode(args) {
302
307
  }
303
308
 
304
309
  async function cmdNearby(args) {
305
- if (args.help) { console.log(HELP_NEARBY); return; }
310
+ if (args.help) {
311
+ console.log(HELP_NEARBY);
312
+ return;
313
+ }
314
+
315
+ const key = lib.ensureKey();
306
316
 
307
317
  let keyword = args.keyword;
308
318
  if (!keyword) {
309
319
  // 组合 location + keywords 形成搜索关键词
310
320
  if (!args.location && !args.keywords) {
311
- fatal('缺少参数。用法: tmap-lbs nearby --location <位置> --keywords <类别>\n 或: tmap-lbs nearby --keyword <完整关键词>');
321
+ fatal(
322
+ '缺少参数。用法: tmap-lbs nearby --location <位置> --keywords <类别>\n 或: tmap-lbs nearby --keyword <完整关键词>'
323
+ );
312
324
  }
313
325
  keyword = (args.location || '') + (args.keywords || '');
314
326
  }
315
327
 
316
328
  const encoded = encodeURIComponent(keyword);
317
- const url = `https://mapapi.qq.com/web/claw/nearby-search.html?keyword=${encoded}`;
329
+ const url = `https://mapapi.qq.com/web/claw/nearby-search.html?keyword=${encoded}&key=${encodeURIComponent(key)}`;
318
330
 
319
331
  console.log(`\n🔍 已生成周边搜索链接:\n`);
320
332
  console.log(` ${url}\n`);
@@ -323,14 +335,20 @@ async function cmdNearby(args) {
323
335
  }
324
336
 
325
337
  async function cmdRoute(args) {
326
- if (args.help) { console.log(HELP_ROUTE); return; }
338
+ if (args.help) {
339
+ console.log(HELP_ROUTE);
340
+ return;
341
+ }
327
342
  if (!args.origin) fatal('缺少 --origin 参数');
328
343
  if (!args.destination) fatal('缺少 --destination 参数');
329
344
 
330
345
  const mode = args.mode || 'walk';
331
346
  const modeNames = {
332
- walk: '步行', drive: '驾车', cycle: '骑行',
333
- ecycle: '电动车', transit: '公交',
347
+ walk: '步行',
348
+ drive: '驾车',
349
+ cycle: '骑行',
350
+ ecycle: '电动车',
351
+ transit: '公交',
334
352
  };
335
353
 
336
354
  if (!modeNames[mode]) {
@@ -396,11 +414,17 @@ async function cmdRoute(args) {
396
414
  }
397
415
 
398
416
  async function cmdTravel(args) {
399
- if (args.help) { console.log(HELP_TRAVEL); return; }
417
+ if (args.help) {
418
+ console.log(HELP_TRAVEL);
419
+ return;
420
+ }
400
421
  if (!args.city) fatal('缺少 --city 参数');
401
422
  if (!args.interests) fatal('缺少 --interests 参数');
402
423
 
403
- const interests = args.interests.split(',').map((s) => s.trim()).filter(Boolean);
424
+ const interests = args.interests
425
+ .split(',')
426
+ .map((s) => s.trim())
427
+ .filter(Boolean);
404
428
  const recommend = args.recommend || '';
405
429
 
406
430
  console.log(`\n🗺 正在获取景点坐标...\n`);
@@ -424,12 +448,12 @@ async function cmdTravel(args) {
424
448
  if (spots.length === 0) fatal('没有成功获取任何景点的坐标');
425
449
 
426
450
  // 生成旅游规划可视化链接
427
- const key = lib.getKey() || '';
451
+ const key = lib.ensureKey();
428
452
  const spotsJSON = JSON.stringify(spots);
429
453
  const params = new URLSearchParams();
430
454
  params.set('spots', spotsJSON);
431
455
  if (recommend) params.set('recommend', recommend);
432
- if (key) params.set('key', key);
456
+ params.set('key', key);
433
457
 
434
458
  const url = `https://mapapi.qq.com/web/claw/travel.html?${params.toString()}`;
435
459
 
@@ -444,7 +468,10 @@ async function cmdTravel(args) {
444
468
  }
445
469
 
446
470
  async function cmdTrail(args) {
447
- if (args.help) { console.log(HELP_TRAIL); return; }
471
+ if (args.help) {
472
+ console.log(HELP_TRAIL);
473
+ return;
474
+ }
448
475
  if (!args.data) fatal('缺少 --data 参数');
449
476
 
450
477
  const encoded = encodeURIComponent(args.data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencent-map/lbs-skills",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "腾讯地图位置服务命令行工具,支持 POI 搜索、地理编码、周边搜索、路径规划、旅游规划、轨迹可视化等功能",
5
5
  "bin": {
6
6
  "tmap-lbs": "./bin/cli.js"