qiwei-official-cli.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env node
  2. const {
  3. runtimeManifest,
  4. prepareOfficialCli,
  5. runOfficialCli,
  6. getOfficialCliStatus,
  7. getInitCommand,
  8. sanitizeCliText
  9. } = require('../mcp/src/core/wecom-cli-runtime');
  10. async function main() {
  11. const args = process.argv.slice(2);
  12. const command = args[0];
  13. if (command === 'install') {
  14. const installed = await prepareOfficialCli({ force: args.includes('--force') });
  15. console.log(
  16. JSON.stringify(
  17. {
  18. status: 'ok',
  19. package: runtimeManifest.package,
  20. version: runtimeManifest.version,
  21. cached: installed.cached
  22. },
  23. null,
  24. 2
  25. )
  26. );
  27. return;
  28. }
  29. if (command === 'status') {
  30. const status = await getOfficialCliStatus();
  31. console.log(JSON.stringify({ ...status, initCommand: status.ready ? undefined : getInitCommand() }, null, 2));
  32. return;
  33. }
  34. const result = await runOfficialCli(args, {
  35. inherited: true,
  36. timeoutMs: command === 'init' ? 10 * 60 * 1000 : 120000
  37. });
  38. if (result.exitCode !== 0) process.exit(result.exitCode);
  39. }
  40. main().catch(error => {
  41. console.error(`qiwei-official-cli failed: ${sanitizeCliText(error.message)}`);
  42. process.exit(1);
  43. });