@statocysts/cli 0.9.0 → 0.9.1
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.mjs +3 -2
- package/dist/cli.mjs.map +1 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1 -100
- package/dist/src-i7BSyPnd.mjs +107 -0
- package/dist/src-i7BSyPnd.mjs.map +1 -0
- package/package.json +3 -3
package/dist/cli.mjs
CHANGED
package/dist/cli.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import { run } from './index.js'\n\nrun()\n"],"mappings":";;;AAEA,KAAK"}
|
package/dist/index.d.mts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";iBAwGsB,GAAA,CAAA,GAAO"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,102 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
import * as readline from "node:readline";
|
|
4
|
-
import { send } from "statocysts";
|
|
5
|
-
import yargs from "yargs";
|
|
6
|
-
import { hideBin } from "yargs/helpers";
|
|
1
|
+
import { t as run } from "./src-i7BSyPnd.mjs";
|
|
7
2
|
|
|
8
|
-
//#region src/index.ts
|
|
9
|
-
/**
|
|
10
|
-
* Read message content from stdin
|
|
11
|
-
*/
|
|
12
|
-
async function readFromStdin() {
|
|
13
|
-
if (process.stdin.isTTY) return "";
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
const rl = readline.createInterface({
|
|
16
|
-
input: process.stdin,
|
|
17
|
-
terminal: false
|
|
18
|
-
});
|
|
19
|
-
const lines = [];
|
|
20
|
-
rl.on("line", (line) => {
|
|
21
|
-
lines.push(line);
|
|
22
|
-
});
|
|
23
|
-
rl.on("close", () => {
|
|
24
|
-
resolve(lines.join("\n"));
|
|
25
|
-
});
|
|
26
|
-
rl.on("error", reject);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Get message content from various sources
|
|
31
|
-
* Priority: --body > --file > stdin
|
|
32
|
-
*/
|
|
33
|
-
async function getBody(args) {
|
|
34
|
-
if (args.body) return args.body;
|
|
35
|
-
if (args.file) try {
|
|
36
|
-
return fs.readFileSync(args.file, "utf-8").trim();
|
|
37
|
-
} catch (error) {
|
|
38
|
-
throw new Error(`Failed to read file "${args.file}": ${error.message}`);
|
|
39
|
-
}
|
|
40
|
-
const stdinContent = await readFromStdin();
|
|
41
|
-
if (stdinContent) return stdinContent.trim();
|
|
42
|
-
return "";
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Send notifications to all specified URLs
|
|
46
|
-
*/
|
|
47
|
-
async function sendNotifications(urls, title, body) {
|
|
48
|
-
const results = await Promise.allSettled(urls.map((url) => send(url, title, body)));
|
|
49
|
-
const failures = [];
|
|
50
|
-
results.forEach((result, index) => {
|
|
51
|
-
if (result.status === "rejected") failures.push({
|
|
52
|
-
url: urls[index],
|
|
53
|
-
error: result.reason?.message || String(result.reason)
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
if (failures.length > 0) {
|
|
57
|
-
console.error("\nFailed to send to some URLs:");
|
|
58
|
-
failures.forEach(({ url, error }) => {
|
|
59
|
-
console.error(` - ${url}: ${error}`);
|
|
60
|
-
});
|
|
61
|
-
if (failures.length === urls.length) process.exit(1);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
async function run() {
|
|
65
|
-
const argv = await yargs(hideBin(process.argv)).scriptName("stato").usage("$0 -u <url> -t <title> [-b <body> | -f <file>]").option("url", {
|
|
66
|
-
alias: "u",
|
|
67
|
-
type: "string",
|
|
68
|
-
array: true,
|
|
69
|
-
demandOption: true,
|
|
70
|
-
description: "Notification service URL(s)"
|
|
71
|
-
}).option("title", {
|
|
72
|
-
alias: "t",
|
|
73
|
-
type: "string",
|
|
74
|
-
demandOption: true,
|
|
75
|
-
description: "Notification title"
|
|
76
|
-
}).option("body", {
|
|
77
|
-
alias: "b",
|
|
78
|
-
type: "string",
|
|
79
|
-
description: "Notification body content"
|
|
80
|
-
}).option("file", {
|
|
81
|
-
alias: "f",
|
|
82
|
-
type: "string",
|
|
83
|
-
description: "Read body content from file"
|
|
84
|
-
}).example([
|
|
85
|
-
["$0 -u \"slack://webhook/xxx/yyy/zzz\" -t \"Alert\" -b \"Hello World\"", "Send notification to Slack webhook"],
|
|
86
|
-
["$0 -u \"slack://webhook/a/b/c\" -u \"json://example.com/api\" -t \"Alert\" -b \"Hello\"", "Send to multiple URLs"],
|
|
87
|
-
["$0 -u \"slack://webhook/xxx/yyy/zzz\" -t \"Alert\" -f message.txt", "Send with body from file"],
|
|
88
|
-
["echo \"Hello\" | $0 -u \"slack://webhook/xxx/yyy/zzz\" -t \"Alert\"", "Send with body from stdin"],
|
|
89
|
-
["$0 -u \"slack://webhook/xxx/yyy/zzz\" -t \"Simple Alert\"", "Send title only"]
|
|
90
|
-
]).help().version().strict().parse();
|
|
91
|
-
try {
|
|
92
|
-
const body = await getBody(argv);
|
|
93
|
-
await sendNotifications(argv.url, argv.title, body || void 0);
|
|
94
|
-
console.log("Notification sent successfully!");
|
|
95
|
-
} catch (error) {
|
|
96
|
-
console.error(`Error: ${error.message}`);
|
|
97
|
-
process.exit(1);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
//#endregion
|
|
102
3
|
export { run };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import * as readline from "node:readline";
|
|
4
|
+
import { send } from "statocysts";
|
|
5
|
+
import yargs from "yargs";
|
|
6
|
+
import { hideBin } from "yargs/helpers";
|
|
7
|
+
|
|
8
|
+
//#region package.json
|
|
9
|
+
var version = "0.9.1";
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/index.ts
|
|
13
|
+
/**
|
|
14
|
+
* Read message content from stdin
|
|
15
|
+
*/
|
|
16
|
+
async function readFromStdin() {
|
|
17
|
+
if (process.stdin.isTTY) return "";
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const rl = readline.createInterface({
|
|
20
|
+
input: process.stdin,
|
|
21
|
+
terminal: false
|
|
22
|
+
});
|
|
23
|
+
const lines = [];
|
|
24
|
+
rl.on("line", (line) => {
|
|
25
|
+
lines.push(line);
|
|
26
|
+
});
|
|
27
|
+
rl.on("close", () => {
|
|
28
|
+
resolve(lines.join("\n"));
|
|
29
|
+
});
|
|
30
|
+
rl.on("error", reject);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get message content from various sources
|
|
35
|
+
* Priority: --body > --file > stdin
|
|
36
|
+
*/
|
|
37
|
+
async function getBody(args) {
|
|
38
|
+
if (args.body) return args.body;
|
|
39
|
+
if (args.file) try {
|
|
40
|
+
return fs.readFileSync(args.file, "utf-8").trim();
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new Error(`Failed to read file "${args.file}": ${error.message}`);
|
|
43
|
+
}
|
|
44
|
+
const stdinContent = await readFromStdin();
|
|
45
|
+
if (stdinContent) return stdinContent.trim();
|
|
46
|
+
return "";
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Send notifications to all specified URLs
|
|
50
|
+
*/
|
|
51
|
+
async function sendNotifications(urls, title, body) {
|
|
52
|
+
const results = await Promise.allSettled(urls.map((url) => send(url, title, body)));
|
|
53
|
+
const failures = [];
|
|
54
|
+
results.forEach((result, index) => {
|
|
55
|
+
if (result.status === "rejected") failures.push({
|
|
56
|
+
url: urls[index],
|
|
57
|
+
error: result.reason?.message || String(result.reason)
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
if (failures.length > 0) {
|
|
61
|
+
console.error("\nFailed to send to some URLs:");
|
|
62
|
+
failures.forEach(({ url, error }) => {
|
|
63
|
+
console.error(` - ${url}: ${error}`);
|
|
64
|
+
});
|
|
65
|
+
if (failures.length === urls.length) process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function run() {
|
|
69
|
+
const argv = await yargs(hideBin(process.argv)).scriptName("stato").usage("$0 -u <url> -t <title> [-b <body> | -f <file>]").option("url", {
|
|
70
|
+
alias: "u",
|
|
71
|
+
type: "string",
|
|
72
|
+
array: true,
|
|
73
|
+
demandOption: true,
|
|
74
|
+
description: "Notification service URL(s)"
|
|
75
|
+
}).option("title", {
|
|
76
|
+
alias: "t",
|
|
77
|
+
type: "string",
|
|
78
|
+
demandOption: true,
|
|
79
|
+
description: "Notification title"
|
|
80
|
+
}).option("body", {
|
|
81
|
+
alias: "b",
|
|
82
|
+
type: "string",
|
|
83
|
+
description: "Notification body content"
|
|
84
|
+
}).option("file", {
|
|
85
|
+
alias: "f",
|
|
86
|
+
type: "string",
|
|
87
|
+
description: "Read body content from file"
|
|
88
|
+
}).example([
|
|
89
|
+
["$0 -u \"slack://webhook/xxx/yyy/zzz\" -t \"Alert\" -b \"Hello World\"", "Send notification to Slack webhook"],
|
|
90
|
+
["$0 -u \"slack://webhook/a/b/c\" -u \"json://example.com/api\" -t \"Alert\" -b \"Hello\"", "Send to multiple URLs"],
|
|
91
|
+
["$0 -u \"slack://webhook/xxx/yyy/zzz\" -t \"Alert\" -f message.txt", "Send with body from file"],
|
|
92
|
+
["echo \"Hello\" | $0 -u \"slack://webhook/xxx/yyy/zzz\" -t \"Alert\"", "Send with body from stdin"],
|
|
93
|
+
["$0 -u \"slack://webhook/xxx/yyy/zzz\" -t \"Simple Alert\"", "Send title only"]
|
|
94
|
+
]).help().version(version).strict().parse();
|
|
95
|
+
try {
|
|
96
|
+
const body = await getBody(argv);
|
|
97
|
+
await sendNotifications(argv.url, argv.title, body || void 0);
|
|
98
|
+
console.log("Notification sent successfully!");
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error(`Error: ${error.message}`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { run as t };
|
|
107
|
+
//# sourceMappingURL=src-i7BSyPnd.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-i7BSyPnd.mjs","names":["lines: string[]","failures: { url: string, error: string }[]"],"sources":["../package.json","../src/index.ts"],"sourcesContent":["","import * as fs from 'node:fs'\nimport process from 'node:process'\nimport * as readline from 'node:readline'\nimport { send } from 'statocysts'\nimport yargs from 'yargs'\nimport { hideBin } from 'yargs/helpers'\nimport { version } from '../package.json' with { type: 'json' }\n\ninterface CliArgs {\n url: string[]\n title: string\n body?: string\n file?: string\n}\n\n/**\n * Read message content from stdin\n */\nasync function readFromStdin(): Promise<string> {\n // Check if stdin is a TTY (interactive terminal)\n if (process.stdin.isTTY) {\n return ''\n }\n\n return new Promise((resolve, reject) => {\n const rl = readline.createInterface({\n input: process.stdin,\n terminal: false,\n })\n\n const lines: string[] = []\n\n rl.on('line', (line) => {\n lines.push(line)\n })\n\n rl.on('close', () => {\n resolve(lines.join('\\n'))\n })\n\n rl.on('error', reject)\n })\n}\n\n/**\n * Get message content from various sources\n * Priority: --body > --file > stdin\n */\nasync function getBody(args: CliArgs): Promise<string> {\n // Priority 1: Direct body argument\n if (args.body) {\n return args.body\n }\n\n // Priority 2: Read from file\n if (args.file) {\n try {\n return fs.readFileSync(args.file, 'utf-8').trim()\n }\n catch (error) {\n throw new Error(`Failed to read file \"${args.file}\": ${(error as Error).message}`)\n }\n }\n\n // Priority 3: Read from stdin\n const stdinContent = await readFromStdin()\n if (stdinContent) {\n return stdinContent.trim()\n }\n\n return ''\n}\n\n/**\n * Send notifications to all specified URLs\n */\nasync function sendNotifications(urls: string[], title: string, body?: string): Promise<void> {\n const results = await Promise.allSettled(\n urls.map(url => send(url, title, body)),\n )\n\n const failures: { url: string, error: string }[] = []\n\n results.forEach((result, index) => {\n if (result.status === 'rejected') {\n failures.push({\n url: urls[index],\n error: result.reason?.message || String(result.reason),\n })\n }\n })\n\n if (failures.length > 0) {\n console.error('\\nFailed to send to some URLs:')\n failures.forEach(({ url, error }) => {\n console.error(` - ${url}: ${error}`)\n })\n\n if (failures.length === urls.length) {\n process.exit(1)\n }\n }\n}\n\nexport async function run(): Promise<void> {\n const argv = await yargs(hideBin(process.argv))\n .scriptName('stato')\n .usage('$0 -u <url> -t <title> [-b <body> | -f <file>]')\n .option('url', {\n alias: 'u',\n type: 'string',\n array: true,\n demandOption: true,\n description: 'Notification service URL(s)',\n })\n .option('title', {\n alias: 't',\n type: 'string',\n demandOption: true,\n description: 'Notification title',\n })\n .option('body', {\n alias: 'b',\n type: 'string',\n description: 'Notification body content',\n })\n .option('file', {\n alias: 'f',\n type: 'string',\n description: 'Read body content from file',\n })\n .example([\n ['$0 -u \"slack://webhook/xxx/yyy/zzz\" -t \"Alert\" -b \"Hello World\"', 'Send notification to Slack webhook'],\n ['$0 -u \"slack://webhook/a/b/c\" -u \"json://example.com/api\" -t \"Alert\" -b \"Hello\"', 'Send to multiple URLs'],\n ['$0 -u \"slack://webhook/xxx/yyy/zzz\" -t \"Alert\" -f message.txt', 'Send with body from file'],\n ['echo \"Hello\" | $0 -u \"slack://webhook/xxx/yyy/zzz\" -t \"Alert\"', 'Send with body from stdin'],\n ['$0 -u \"slack://webhook/xxx/yyy/zzz\" -t \"Simple Alert\"', 'Send title only'],\n ])\n .help()\n .version(version)\n .strict()\n .parse() as CliArgs\n\n try {\n const body = await getBody(argv)\n\n await sendNotifications(argv.url, argv.title, body || undefined)\n console.log('Notification sent successfully!')\n }\n catch (error) {\n console.error(`Error: ${(error as Error).message}`)\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;ACkBA,eAAe,gBAAiC;AAE9C,KAAI,QAAQ,MAAM,MAChB,QAAO;AAGT,Q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ACnB,MAAM,iDAAiD,CACvD,OAAO,OAAO;EACb,OAAO;EACP,MAAM;EACN,OAAO;EACP,cAAc;EACd,aAAa;EACd,CAAC,CACD,OAAO,SAAS;EACf,OAAO;EACP,MAAM;EACN,cAAc;EACd,aAAa;EACd,CAAC,CACD,OAAO,QAAQ;EACd,OAAO;EACP,MAAM;EACN,aAAa;EACd,CAAC,CACD,OAAO,QAAQ;EACd,OAAO;EACP,MAAM;EACN,aAAa;EACd,CAAC,CACD,QAAQ;EACP,CAAC,yEAAmE,qCAAqC;EACzG,CAAC,2FAAmF,wBAAwB;EAC5G,CAAC,qEAAiE,2BAA2B;EAC7F,CAAC,uEAAiE,4BAA4B;EAC9F,CAAC,6DAAyD,kBAAkB;EAC7E,CAAC,CACD,MAAM,CACN,QAAQ,QAAQ,CAChB,QAAQ,CACR,OAAO;AAEV,KAAI;EACF,MAAM,OAAO,MAAM,QAAQ,KAAK;AAEhC,QAAM,kBAAkB,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAU;AAChE,UAAQ,IAAI,kCAAkC;UAEzC,OAAO;AACZ,UAAQ,MAAM,UAAW,MAAgB,UAAU;AACnD,UAAQ,KAAK,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statocysts/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.1",
|
|
5
5
|
"description": "CLI for statocysts notification library",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/octoplorer/statocysts",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"yargs": "^18.0.0",
|
|
43
|
-
"statocysts": "0.9.
|
|
43
|
+
"statocysts": "0.9.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "^25.0.3",
|
|
47
47
|
"@types/yargs": "^17.0.35",
|
|
48
|
-
"tsdown": "^0.18.
|
|
48
|
+
"tsdown": "^0.18.3",
|
|
49
49
|
"typescript": "^5.9.3"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|