@cwa-dev/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 +42 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { sendTelegramMessage } from "@cwa-dev/sendkit-core";
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
8
|
+
//#region src/index.ts
|
|
9
|
+
const program = new Command();
|
|
10
|
+
const configPath = join(homedir(), ".config", "sendkit", "config.json");
|
|
11
|
+
const cliConfigSchema = z.object({ telegramBotToken: z.string().min(1).optional() });
|
|
12
|
+
function writeTelegramBotToken(token) {
|
|
13
|
+
mkdirSync(dirname(configPath), { recursive: true });
|
|
14
|
+
writeFileSync(configPath, `${JSON.stringify({ telegramBotToken: token }, null, 2)}\n`, { mode: 384 });
|
|
15
|
+
}
|
|
16
|
+
function getTelegramBotToken() {
|
|
17
|
+
if (!existsSync(configPath)) throw new Error("Telegram bot token is required. Run `sendkit init`.");
|
|
18
|
+
const token = cliConfigSchema.parse(JSON.parse(readFileSync(configPath, "utf8"))).telegramBotToken;
|
|
19
|
+
if (!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
|
+
console.log(`Saved SendKit CLI config to ${configPath}`);
|
|
26
|
+
});
|
|
27
|
+
program.command("telegram").description("Send a Telegram message").argument("<chatId>", "Telegram chat ID").argument("<message>", "Message text to send").action(async (chatId, message) => {
|
|
28
|
+
const result = await sendTelegramMessage({
|
|
29
|
+
botToken: getTelegramBotToken(),
|
|
30
|
+
chatId,
|
|
31
|
+
message
|
|
32
|
+
});
|
|
33
|
+
console.log(JSON.stringify(result));
|
|
34
|
+
});
|
|
35
|
+
await program.parseAsync(process.argv).catch((error) => {
|
|
36
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
37
|
+
process.exitCode = 1;
|
|
38
|
+
});
|
|
39
|
+
//#endregion
|
|
40
|
+
export {};
|
|
41
|
+
|
|
42
|
+
//# 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 { z } from \"zod\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { sendTelegramMessage } from \"@cwa-dev/sendkit-core\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\n\nconst program = new Command();\nconst configPath = join(homedir(), \".config\", \"sendkit\", \"config.json\");\nconst cliConfigSchema = z.object({\n telegramBotToken: z.string().min(1).optional(),\n});\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}\n\nfunction getTelegramBotToken() {\n if (!existsSync(configPath)) {\n throw new Error(\"Telegram bot token is required. Run `sendkit init`.\");\n }\n\n const config = cliConfigSchema.parse(JSON.parse(readFileSync(configPath, \"utf8\")));\n const token = config.telegramBotToken;\n\n if (!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\");\n\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 console.log(`Saved SendKit CLI config to ${configPath}`);\n });\n\nprogram\n .command(\"telegram\")\n .description(\"Send a Telegram message\")\n .argument(\"<chatId>\", \"Telegram chat ID\")\n .argument(\"<message>\", \"Message text to send\")\n .action(async (chatId: string, message: string) => {\n const result = await sendTelegramMessage({\n botToken: getTelegramBotToken(),\n chatId,\n message,\n });\n\n console.log(JSON.stringify(result));\n });\n\nawait program.parseAsync(process.argv).catch((error: unknown) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exitCode = 1;\n});\n"],"mappings":";;;;;;;;AAQA,MAAM,UAAU,IAAI,QAAQ;AAC5B,MAAM,aAAa,KAAK,QAAQ,GAAG,WAAW,WAAW,aAAa;AACtE,MAAM,kBAAkB,EAAE,OAAO,EAC/B,kBAAkB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAC/C,CAAC;AAED,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;AACH;AAEA,SAAS,sBAAsB;CAC7B,IAAI,CAAC,WAAW,UAAU,GACxB,MAAM,IAAI,MAAM,qDAAqD;CAIvE,MAAM,QADS,gBAAgB,MAAM,KAAK,MAAM,aAAa,YAAY,MAAM,CAAC,CAC7D,CAAC,CAAC;CAErB,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,qDAAqD;CAGvE,OAAO;AACT;AAEA,QAAQ,KAAK,SAAS,CAAC,CAAC,YAAY,oCAAoC;AAExE,QACG,QAAQ,MAAM,CAAC,CACf,YAAY,sCAAsC,CAAC,CACnD,eAAe,mCAAmC,oBAAoB,CAAC,CACvE,OAAO,OAAO,YAA0C;CACvD,sBAAsB,QAAQ,gBAAgB;CAC9C,QAAQ,IAAI,+BAA+B,YAAY;AACzD,CAAC;AAEH,QACG,QAAQ,UAAU,CAAC,CACnB,YAAY,yBAAyB,CAAC,CACtC,SAAS,YAAY,kBAAkB,CAAC,CACxC,SAAS,aAAa,sBAAsB,CAAC,CAC7C,OAAO,OAAO,QAAgB,YAAoB;CACjD,MAAM,SAAS,MAAM,oBAAoB;EACvC,UAAU,oBAAoB;EAC9B;EACA;CACF,CAAC;CAED,QAAQ,IAAI,KAAK,UAAU,MAAM,CAAC;AACpC,CAAC;AAEH,MAAM,QAAQ,WAAW,QAAQ,IAAI,CAAC,CAAC,OAAO,UAAmB;CAC/D,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;CACpE,QAAQ,WAAW;AACrB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cwa-dev/sendkit",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"bin": {
|
|
5
|
+
"sendkit": "./dist/index.js"
|
|
6
|
+
},
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"commander": "^15.0.0",
|
|
25
|
+
"@cwa-dev/sendkit-core": "0.0.0",
|
|
26
|
+
"zod": "^4.4.3"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsdown",
|
|
30
|
+
"pack:dry": "bun run build && bun pm pack --dry-run",
|
|
31
|
+
"prepublishOnly": "bun run build"
|
|
32
|
+
}
|
|
33
|
+
}
|