@wu529778790/open-im 1.1.1 → 1.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/dist/cli.js +3 -4
- package/dist/index.js +3 -4
- package/dist/setup.d.ts +2 -2
- package/dist/setup.js +48 -15
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import { readFileSync, writeFileSync, existsSync, unlinkSync } from "node:fs";
|
|
|
4
4
|
import { join, dirname } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { main, needsSetup, runInteractiveSetup } from "./index.js";
|
|
7
|
-
import { loadConfig
|
|
7
|
+
import { loadConfig } from "./config.js";
|
|
8
8
|
import { runPlatformSelectionPrompt } from "./setup.js";
|
|
9
9
|
import { APP_HOME, SHUTDOWN_PORT } from "./constants.js";
|
|
10
10
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -89,10 +89,9 @@ async function cmdStart() {
|
|
|
89
89
|
if (!(await validateOrSetup())) {
|
|
90
90
|
process.exit(1);
|
|
91
91
|
}
|
|
92
|
-
//
|
|
92
|
+
// 有 TTY 时在父进程让用户选择要启用的平台,再启动子进程
|
|
93
93
|
let config = loadConfig();
|
|
94
|
-
if (
|
|
95
|
-
process.stdin.isTTY) {
|
|
94
|
+
if (process.stdin.isTTY) {
|
|
96
95
|
const updated = await runPlatformSelectionPrompt(config);
|
|
97
96
|
if (!updated) {
|
|
98
97
|
console.log("已取消启动。");
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createServer } from "node:http";
|
|
2
2
|
import { writeFileSync, existsSync, mkdirSync, unlinkSync } from "node:fs";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
-
import { loadConfig, needsSetup
|
|
4
|
+
import { loadConfig, needsSetup } from "./config.js";
|
|
5
5
|
import { runInteractiveSetup, runPlatformSelectionPrompt } from "./setup.js";
|
|
6
6
|
// 导出供 cli.ts 使用
|
|
7
7
|
export { needsSetup, runInteractiveSetup };
|
|
@@ -63,9 +63,8 @@ export async function main() {
|
|
|
63
63
|
process.exit(1);
|
|
64
64
|
}
|
|
65
65
|
let config = loadConfig();
|
|
66
|
-
//
|
|
67
|
-
if (
|
|
68
|
-
process.stdin.isTTY) {
|
|
66
|
+
// 有 TTY 时让用户选择要启用的平台(无论单通道还是多通道)
|
|
67
|
+
if (process.stdin.isTTY) {
|
|
69
68
|
const updated = await runPlatformSelectionPrompt(config);
|
|
70
69
|
if (!updated)
|
|
71
70
|
process.exit(0);
|
package/dist/setup.d.ts
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
import type { Config } from "./config.js";
|
|
7
7
|
export declare function runInteractiveSetup(): Promise<boolean>;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* 启动时让用户选择要启用的平台(无论单通道还是多通道)
|
|
10
|
+
* 显示全部 4 个平台,已配置的预选;若用户选择未配置的,引导运行 init
|
|
11
11
|
* @returns 更新后的 config,或 null 表示取消
|
|
12
12
|
*/
|
|
13
13
|
export declare function runPlatformSelectionPrompt(config: Config): Promise<Config | null>;
|
package/dist/setup.js
CHANGED
|
@@ -503,30 +503,35 @@ const PLATFORM_LABELS = {
|
|
|
503
503
|
wework: "企业微信",
|
|
504
504
|
wechat: "微信(测试中)",
|
|
505
505
|
};
|
|
506
|
+
const ALL_PLATFORMS = ["telegram", "feishu", "wework", "wechat"];
|
|
506
507
|
/**
|
|
507
|
-
*
|
|
508
|
-
*
|
|
508
|
+
* 启动时让用户选择要启用的平台(无论单通道还是多通道)
|
|
509
|
+
* 显示全部 4 个平台,已配置的预选;若用户选择未配置的,引导运行 init
|
|
509
510
|
* @returns 更新后的 config,或 null 表示取消
|
|
510
511
|
*/
|
|
511
512
|
export async function runPlatformSelectionPrompt(config) {
|
|
512
|
-
const withCreds = getPlatformsWithCredentials(config);
|
|
513
|
-
if (withCreds.length <= 1)
|
|
514
|
-
return config;
|
|
513
|
+
const withCreds = new Set(getPlatformsWithCredentials(config));
|
|
515
514
|
const configPath = join(APP_HOME, "config.json");
|
|
516
515
|
const existing = loadExistingConfig();
|
|
517
|
-
const choices =
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
516
|
+
const choices = ALL_PLATFORMS.map((p) => {
|
|
517
|
+
const hasCreds = withCreds.has(p);
|
|
518
|
+
const isEnabled = config.enabledPlatforms.includes(p);
|
|
519
|
+
const suffix = hasCreds
|
|
520
|
+
? (isEnabled ? " ✓已配置且启用" : " ✓已配置")
|
|
521
|
+
: "(未配置)";
|
|
522
|
+
return {
|
|
523
|
+
title: `${PLATFORM_LABELS[p]}${suffix}`,
|
|
524
|
+
value: p,
|
|
525
|
+
selected: isEnabled && hasCreds,
|
|
526
|
+
};
|
|
527
|
+
});
|
|
522
528
|
console.log("\n━━━ 选择要启用的平台 ━━━\n");
|
|
523
529
|
const resp = await prompts({
|
|
524
530
|
type: "multiselect",
|
|
525
531
|
name: "platforms",
|
|
526
532
|
message: "选择要启用的平台(空格切换,回车确认)",
|
|
527
533
|
choices,
|
|
528
|
-
|
|
529
|
-
hint: "至少选择 1 个平台",
|
|
534
|
+
hint: "未配置的平台需先运行 open-im init",
|
|
530
535
|
}, {
|
|
531
536
|
onCancel: () => {
|
|
532
537
|
console.log("\n已取消启动。");
|
|
@@ -536,15 +541,43 @@ export async function runPlatformSelectionPrompt(config) {
|
|
|
536
541
|
if (!resp.platforms || !Array.isArray(resp.platforms))
|
|
537
542
|
return null;
|
|
538
543
|
const selected = new Set(resp.platforms);
|
|
539
|
-
|
|
544
|
+
const selectedUnconfigured = ALL_PLATFORMS.filter((p) => selected.has(p) && !withCreds.has(p));
|
|
545
|
+
if (selectedUnconfigured.length > 0) {
|
|
546
|
+
console.log("");
|
|
547
|
+
console.log("您选择了 " +
|
|
548
|
+
selectedUnconfigured.map((p) => PLATFORM_LABELS[p]).join("、") +
|
|
549
|
+
",但这些平台尚未配置。");
|
|
550
|
+
console.log("请运行 open-im init 进行配置,配置完成后再次启动。");
|
|
551
|
+
console.log("");
|
|
552
|
+
const runNow = await prompts({
|
|
553
|
+
type: "confirm",
|
|
554
|
+
name: "run",
|
|
555
|
+
message: "是否现在运行配置向导?",
|
|
556
|
+
initial: true,
|
|
557
|
+
}, { onCancel: () => process.exit(0) });
|
|
558
|
+
if (runNow.run) {
|
|
559
|
+
const saved = await runInteractiveSetup();
|
|
560
|
+
if (saved) {
|
|
561
|
+
console.log("\n配置完成,请再次运行 open-im start 或 open-im dev 启动。");
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
process.exit(0);
|
|
565
|
+
}
|
|
566
|
+
// 至少需要 1 个已配置的平台被选中
|
|
567
|
+
const selectedWithCreds = ALL_PLATFORMS.filter((p) => selected.has(p) && withCreds.has(p));
|
|
568
|
+
if (selectedWithCreds.length === 0) {
|
|
569
|
+
console.log("\n请至少选择 1 个已配置的平台,或运行 open-im init 添加配置。");
|
|
570
|
+
return null;
|
|
571
|
+
}
|
|
572
|
+
// 更新 config.json 中的 platforms.xxx.enabled
|
|
540
573
|
const updated = { ...existing };
|
|
541
574
|
if (!updated.platforms)
|
|
542
575
|
updated.platforms = {};
|
|
543
|
-
for (const p of
|
|
576
|
+
for (const p of ALL_PLATFORMS) {
|
|
544
577
|
const plat = updated.platforms[p] ?? {};
|
|
545
578
|
updated.platforms[p] = {
|
|
546
579
|
...plat,
|
|
547
|
-
enabled: selected.has(p),
|
|
580
|
+
enabled: selected.has(p) && withCreds.has(p),
|
|
548
581
|
};
|
|
549
582
|
}
|
|
550
583
|
const dir = dirname(configPath);
|