@tb-eng/sendkit 0.0.0
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/index.d.ts +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/package.json +29 -0
- package/src/index.ts +71 -0
- package/tsconfig.build.json +14 -0
- package/tsdown.config.ts +16 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { sendTelegramMessage } from "@tb-eng/sendkit-core";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
const program = new Command();
|
|
9
|
+
const configPath = join(homedir(), ".config", "sednkit", "config.json");
|
|
10
|
+
function writeTelegramBotToken(token) {
|
|
11
|
+
mkdirSync(dirname(configPath), { recursive: true });
|
|
12
|
+
writeFileSync(configPath, `${JSON.stringify({ telegramBotToken: token }, null, 2)}\n`, { mode: 384 });
|
|
13
|
+
console.log(`Telegram bot token saved successfully at ${configPath}`);
|
|
14
|
+
}
|
|
15
|
+
function getTelegramBotToken() {
|
|
16
|
+
if (!existsSync(configPath)) throw new Error("Telegram bot token is required. Run `sendkit init.`");
|
|
17
|
+
const config = JSON.parse(readFileSync(configPath, "utf8"));
|
|
18
|
+
const token = config.telegramBotToken;
|
|
19
|
+
if (!config || !token) throw new Error("Telegram bot token is required. Run `sendkit init.`");
|
|
20
|
+
return token;
|
|
21
|
+
}
|
|
22
|
+
program.name("sendkit").description("SendKit CLI backed by sendkit-core.");
|
|
23
|
+
program.command("init").description("Configure SendKit CLI local settings").requiredOption("--telegram-bot-token <botToken>", "Telegram bot token").action(async (options) => {
|
|
24
|
+
writeTelegramBotToken(options.telegramBotToken);
|
|
25
|
+
});
|
|
26
|
+
program.name("telegram").description("SendKit a messages to Telegram groups and channels.").command("telegram").argument("<chatId>", "Telegram chatId").argument("<message>", "Message text to send").action(async (chatId, message) => {
|
|
27
|
+
const token = getTelegramBotToken();
|
|
28
|
+
if (!chatId || !message) {
|
|
29
|
+
console.error("ChatId and message are required");
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const result = await sendTelegramMessage({
|
|
34
|
+
botToken: token,
|
|
35
|
+
chatId,
|
|
36
|
+
message
|
|
37
|
+
});
|
|
38
|
+
console.log(JSON.stringify(result));
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error("Failed to send telegram message: ", error);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
await program.parseAsync(process.argv).catch((e) => {
|
|
45
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
46
|
+
process.exit(1);
|
|
47
|
+
});
|
|
48
|
+
//#endregion
|
|
49
|
+
export {};
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Command } from \"commander\";\nimport { sendTelegramMessage } from \"@tb-eng/sendkit-core\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nconst program = new Command();\nconst configPath = join(homedir(), \".config\", \"sednkit\", \"config.json\");\n\nfunction writeTelegramBotToken(token: string) {\n mkdirSync(dirname(configPath), { recursive: true });\n writeFileSync(configPath, `${JSON.stringify({ telegramBotToken: token }, null, 2)}\\n`, {\n mode: 0o600,\n });\n console.log(`Telegram bot token saved successfully at ${configPath}`);\n}\nfunction getTelegramBotToken() {\n if (!existsSync(configPath)) {\n throw new Error(\"Telegram bot token is required. Run `sendkit init.`\");\n }\n\n const config = JSON.parse(readFileSync(configPath, \"utf8\"));\n const token = config.telegramBotToken;\n\n if (!config || !token) {\n throw new Error(\"Telegram bot token is required. Run `sendkit init.`\");\n }\n\n return token;\n}\n\nprogram.name(\"sendkit\").description(\"SendKit CLI backed by sendkit-core.\");\nprogram\n .command(\"init\")\n .description(\"Configure SendKit CLI local settings\")\n .requiredOption(\"--telegram-bot-token <botToken>\", \"Telegram bot token\")\n .action(async (options: { telegramBotToken: string }) => {\n writeTelegramBotToken(options.telegramBotToken);\n });\n\nprogram\n .name(\"telegram\")\n .description(\"SendKit a messages to Telegram groups and channels.\")\n .command(\"telegram\")\n .argument(\"<chatId>\", \"Telegram chatId\")\n .argument(\"<message>\", \"Message text to send\")\n .action(async (chatId: string, message: string) => {\n const token = getTelegramBotToken();\n\n if (!chatId || !message) {\n console.error(\"ChatId and message are required\");\n process.exit(1);\n }\n\n try {\n const result = await sendTelegramMessage({\n botToken: token,\n chatId,\n message,\n });\n console.log(JSON.stringify(result));\n } catch (error) {\n console.error(\"Failed to send telegram message: \", error);\n process.exit(1);\n }\n });\nawait program.parseAsync(process.argv).catch((e) => {\n console.error(e instanceof Error ? e.message : String(e));\n process.exit(1);\n});\n"],"mappings":";;;;;;;AAOA,MAAM,UAAU,IAAI,QAAQ;AAC5B,MAAM,aAAa,KAAK,QAAQ,GAAG,WAAW,WAAW,aAAa;AAEtE,SAAS,sBAAsB,OAAe;CAC5C,UAAU,QAAQ,UAAU,GAAG,EAAE,WAAW,KAAK,CAAC;CAClD,cAAc,YAAY,GAAG,KAAK,UAAU,EAAE,kBAAkB,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,EACrF,MAAM,IACR,CAAC;CACD,QAAQ,IAAI,4CAA4C,YAAY;AACtE;AACA,SAAS,sBAAsB;CAC7B,IAAI,CAAC,WAAW,UAAU,GACxB,MAAM,IAAI,MAAM,qDAAqD;CAGvE,MAAM,SAAS,KA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
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsdown",
|
|
22
|
+
"pack:dry": "bun run build && bun pm pack --dry-run",
|
|
23
|
+
"prepublishOnly": "bun run build"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"commander": "^15.0.0",
|
|
27
|
+
"@tb-eng/sendkit-core": "0.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { sendTelegramMessage } from "@tb-eng/sendkit-core";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
|
|
8
|
+
const program = new Command();
|
|
9
|
+
const configPath = join(homedir(), ".config", "sednkit", "config.json");
|
|
10
|
+
|
|
11
|
+
function writeTelegramBotToken(token: string) {
|
|
12
|
+
mkdirSync(dirname(configPath), { recursive: true });
|
|
13
|
+
writeFileSync(configPath, `${JSON.stringify({ telegramBotToken: token }, null, 2)}\n`, {
|
|
14
|
+
mode: 0o600,
|
|
15
|
+
});
|
|
16
|
+
console.log(`Telegram bot token saved successfully at ${configPath}`);
|
|
17
|
+
}
|
|
18
|
+
function getTelegramBotToken() {
|
|
19
|
+
if (!existsSync(configPath)) {
|
|
20
|
+
throw new Error("Telegram bot token is required. Run `sendkit init.`");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const config = JSON.parse(readFileSync(configPath, "utf8"));
|
|
24
|
+
const token = config.telegramBotToken;
|
|
25
|
+
|
|
26
|
+
if (!config || !token) {
|
|
27
|
+
throw new Error("Telegram bot token is required. Run `sendkit init.`");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return token;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
program.name("sendkit").description("SendKit CLI backed by sendkit-core.");
|
|
34
|
+
program
|
|
35
|
+
.command("init")
|
|
36
|
+
.description("Configure SendKit CLI local settings")
|
|
37
|
+
.requiredOption("--telegram-bot-token <botToken>", "Telegram bot token")
|
|
38
|
+
.action(async (options: { telegramBotToken: string }) => {
|
|
39
|
+
writeTelegramBotToken(options.telegramBotToken);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
program
|
|
43
|
+
.name("telegram")
|
|
44
|
+
.description("SendKit a messages to Telegram groups and channels.")
|
|
45
|
+
.command("telegram")
|
|
46
|
+
.argument("<chatId>", "Telegram chatId")
|
|
47
|
+
.argument("<message>", "Message text to send")
|
|
48
|
+
.action(async (chatId: string, message: string) => {
|
|
49
|
+
const token = getTelegramBotToken();
|
|
50
|
+
|
|
51
|
+
if (!chatId || !message) {
|
|
52
|
+
console.error("ChatId and message are required");
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const result = await sendTelegramMessage({
|
|
58
|
+
botToken: token,
|
|
59
|
+
chatId,
|
|
60
|
+
message,
|
|
61
|
+
});
|
|
62
|
+
console.log(JSON.stringify(result));
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error("Failed to send telegram message: ", error);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
await program.parseAsync(process.argv).catch((e) => {
|
|
69
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
70
|
+
process.exit(1);
|
|
71
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"noEmit": false,
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"declarationMap": true,
|
|
7
|
+
"sourceMap": true,
|
|
8
|
+
"outDir": "dist",
|
|
9
|
+
"rootDir": "src",
|
|
10
|
+
"types": []
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*.ts"],
|
|
13
|
+
"exclude": ["dist", "node_modules"]
|
|
14
|
+
}
|
package/tsdown.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from "tsdown";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: ["src/index.ts"],
|
|
5
|
+
format: ["esm"],
|
|
6
|
+
dts: true,
|
|
7
|
+
sourcemap: true,
|
|
8
|
+
clean: true,
|
|
9
|
+
platform: "node",
|
|
10
|
+
target: "node20",
|
|
11
|
+
outDir: "dist",
|
|
12
|
+
outExtensions: () => ({ js: ".js", dts: ".d.ts" }),
|
|
13
|
+
deps: {
|
|
14
|
+
neverBundle: ["@tb-eng/sendkit-core", "commander", "zod"],
|
|
15
|
+
},
|
|
16
|
+
});
|