@statocysts/cli 0.3.1 → 0.5.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-PRESENT Ming Lin <https://github.com/enpitsuLin>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -13,7 +13,7 @@ pnpm add -g @statocysts/cli
13
13
  ## Usage
14
14
 
15
15
  ```bash
16
- statocysts -u <url> [-m <message> | -f <file>]
16
+ stato -u <url> [-m <message> | -f <file>]
17
17
  ```
18
18
 
19
19
  ### Options
package/bin/stato.mjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import '../dist/cli.mjs'
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.mjs CHANGED
@@ -1,102 +1,7 @@
1
- #!/usr/bin/env node
2
- import * as fs from "node:fs";
3
- import process from "node:process";
4
- import * as readline from "node:readline";
5
- import { send } from "statocysts";
6
- import yargs from "yargs";
7
- import { hideBin } from "yargs/helpers";
1
+ import { run } from "./index.mjs";
8
2
 
9
3
  //#region src/cli.ts
10
- /**
11
- * Read message content from stdin
12
- */
13
- async function readFromStdin() {
14
- if (process.stdin.isTTY) return "";
15
- return new Promise((resolve, reject) => {
16
- const rl = readline.createInterface({
17
- input: process.stdin,
18
- terminal: false
19
- });
20
- const lines = [];
21
- rl.on("line", (line) => {
22
- lines.push(line);
23
- });
24
- rl.on("close", () => {
25
- resolve(lines.join("\n"));
26
- });
27
- rl.on("error", reject);
28
- });
29
- }
30
- /**
31
- * Get message content from various sources
32
- * Priority: --message > --file > stdin
33
- */
34
- async function getMessage(args) {
35
- if (args.message) return args.message;
36
- if (args.file) try {
37
- return fs.readFileSync(args.file, "utf-8").trim();
38
- } catch (error) {
39
- throw new Error(`Failed to read file "${args.file}": ${error.message}`);
40
- }
41
- const stdinContent = await readFromStdin();
42
- if (stdinContent) return stdinContent.trim();
43
- return "";
44
- }
45
- /**
46
- * Send notifications to all specified URLs
47
- */
48
- async function sendNotifications(urls, message) {
49
- const results = await Promise.allSettled(urls.map((url) => send(url, message)));
50
- const failures = [];
51
- results.forEach((result, index) => {
52
- if (result.status === "rejected") failures.push({
53
- url: urls[index],
54
- error: result.reason?.message || String(result.reason)
55
- });
56
- });
57
- if (failures.length > 0) {
58
- console.error("\nFailed to send to some URLs:");
59
- failures.forEach(({ url, error }) => {
60
- console.error(` - ${url}: ${error}`);
61
- });
62
- if (failures.length === urls.length) process.exit(1);
63
- }
64
- }
65
- async function main() {
66
- const argv = await yargs(hideBin(process.argv)).scriptName("stato").usage("$0 -u <url> [-m <message> | -f <file>]").option("url", {
67
- alias: "u",
68
- type: "string",
69
- array: true,
70
- demandOption: true,
71
- description: "Notification service URL(s)"
72
- }).option("message", {
73
- alias: "m",
74
- type: "string",
75
- description: "Message content to send"
76
- }).option("file", {
77
- alias: "f",
78
- type: "string",
79
- description: "Read message content from file"
80
- }).example([
81
- ["$0 -u \"slack://webhook/xxx/yyy/zzz\" -m \"Hello World\"", "Send message to Slack webhook"],
82
- ["$0 -u \"slack://webhook/a/b/c\" -u \"json://example.com/api\" -m \"Hello\"", "Send to multiple URLs"],
83
- ["$0 -u \"slack://webhook/xxx/yyy/zzz\" -f message.txt", "Send message from file"],
84
- ["echo \"Hello\" | $0 -u \"slack://webhook/xxx/yyy/zzz\"", "Send message from stdin"]
85
- ]).help().version().strict().parse();
86
- try {
87
- const message = await getMessage(argv);
88
- if (!message) {
89
- console.error("Error: No message provided. Use -m, -f, or pipe content via stdin.");
90
- process.exit(1);
91
- }
92
- await sendNotifications(argv.url, message);
93
- console.log("Notification sent successfully!");
94
- } catch (error) {
95
- console.error(`Error: ${error.message}`);
96
- process.exit(1);
97
- }
98
- }
99
- main();
4
+ run();
100
5
 
101
6
  //#endregion
102
7
  export { };
@@ -0,0 +1,4 @@
1
+ //#region src/index.d.ts
2
+ declare function run(): Promise<void>;
3
+ //#endregion
4
+ export { run };
package/dist/index.mjs ADDED
@@ -0,0 +1,102 @@
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 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
+ export { run };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@statocysts/cli",
3
3
  "type": "module",
4
- "version": "0.3.1",
4
+ "version": "0.5.0",
5
5
  "description": "CLI for statocysts notification library",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/octoplorer/statocysts",
@@ -17,8 +17,17 @@
17
17
  "cli",
18
18
  "statocysts"
19
19
  ],
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.mts",
23
+ "default": "./dist/index.mjs"
24
+ }
25
+ },
26
+ "main": "./dist/index.mjs",
27
+ "module": "./dist/index.mjs",
28
+ "types": "./dist/index.d.mts",
20
29
  "bin": {
21
- "stato": "./dist/cli.mjs"
30
+ "stato": "./bin/stato.mjs"
22
31
  },
23
32
  "files": [
24
33
  "dist"
@@ -31,12 +40,12 @@
31
40
  },
32
41
  "dependencies": {
33
42
  "yargs": "^18.0.0",
34
- "statocysts": "0.3.1"
43
+ "statocysts": "0.5.0"
35
44
  },
36
45
  "devDependencies": {
37
- "@types/node": "^22.0.0",
46
+ "@types/node": "^25.0.2",
38
47
  "@types/yargs": "^17.0.35",
39
- "tsdown": "^0.18.0",
48
+ "tsdown": "^0.18.1",
40
49
  "typescript": "^5.9.3"
41
50
  },
42
51
  "scripts": {