+1
-1
| { | ||
| "name": "subsc-cli", | ||
| "version": "0.2.5", | ||
| "version": "0.2.6", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+1
-1
@@ -1,2 +0,2 @@ | ||
| # subscriptions-cli | ||
| # subsc-cli | ||
@@ -3,0 +3,0 @@ A CLI tool to manage your subscription services from the terminal. |
-117
| #!/usr/bin/env node | ||
| import { Command } from "commander"; | ||
| import { input, select } from "@inquirer/prompts"; | ||
| import Table from "cli-table3"; | ||
| import consola, { consola as consola$1 } from "consola"; | ||
| import { mkdirSync, readFileSync, writeFileSync } from "fs"; | ||
| import { homedir } from "os"; | ||
| import path from "path"; | ||
| //#region src/basefs.ts | ||
| const dir = path.join(homedir(), ".config", "subscription-cli", "subscription.json"); | ||
| const getSubscriptions = () => { | ||
| try { | ||
| const result = readFileSync(dir, "utf-8"); | ||
| return JSON.parse(result).filter(Boolean); | ||
| } catch (err) { | ||
| return []; | ||
| } | ||
| }; | ||
| const writeSubscription = (SharedArgs) => { | ||
| mkdirSync(path.dirname(dir), { recursive: true }); | ||
| const json = JSON.stringify(SharedArgs, null, 2); | ||
| try { | ||
| writeFileSync(dir, json, "utf-8"); | ||
| consola.success("done add subscription"); | ||
| } catch (error) { | ||
| consola.error("ファイルを作成することができませんでした"); | ||
| } | ||
| }; | ||
| const deleteSubscription = (id) => { | ||
| writeSubscription(getSubscriptions().filter((n) => n.id !== id)); | ||
| }; | ||
| //#endregion | ||
| //#region src/table.ts | ||
| const spreadSubscription = () => { | ||
| const list = getSubscriptions(); | ||
| if (list.length === 0) { | ||
| consola$1.info("No subscriptions found"); | ||
| return; | ||
| } | ||
| const table = new Table({ head: [ | ||
| "name", | ||
| "cycle", | ||
| "tags", | ||
| "price" | ||
| ] }); | ||
| for (const sub of list) table.push([ | ||
| String(sub.name), | ||
| String(sub.cycle), | ||
| String(sub.tags.join(" | ")), | ||
| sub.currency === "USD" ? String(`$${sub.price}`) : String(`\\${sub.price}`) | ||
| ]); | ||
| const jpytotal = list.filter((n) => n.currency === "USD").reduce((sum, n) => sum + n.price, 0); | ||
| const usdtotal = list.filter((n) => n.currency === "JPY").reduce((sum, n) => sum + n.price, 0); | ||
| table.push([ | ||
| "", | ||
| "", | ||
| "JPY TOTAL", | ||
| `\\${jpytotal}` | ||
| ], [ | ||
| "", | ||
| "", | ||
| "USD TOTAL", | ||
| `$${usdtotal}` | ||
| ]); | ||
| consola$1.log(table.toString()); | ||
| }; | ||
| //#endregion | ||
| //#region src/index.ts | ||
| const runCLI = () => { | ||
| const program = new Command(); | ||
| program.name("subsc-cli"); | ||
| program.command("list").action(() => { | ||
| spreadSubscription(); | ||
| }); | ||
| program.command("add").action(async () => { | ||
| const name = await input({ message: "subscription name" }); | ||
| const price = await input({ message: "payment subscribe service" }); | ||
| const currency = await select({ | ||
| message: "currency", | ||
| choices: [{ | ||
| label: "JPY", | ||
| value: "JPY" | ||
| }, { | ||
| label: "USD", | ||
| value: "USD" | ||
| }] | ||
| }); | ||
| const cycle = await select({ | ||
| message: "cycle", | ||
| choices: [{ | ||
| label: "monthly", | ||
| value: "monthly" | ||
| }, { | ||
| label: "yearly", | ||
| value: "yearly" | ||
| }] | ||
| }); | ||
| const tag = await input({ message: "tags" }); | ||
| const get = getSubscriptions(); | ||
| get.push({ | ||
| id: Math.max(0, ...get.map((s) => s.id)) + 1, | ||
| name, | ||
| price: Number(price), | ||
| currency, | ||
| cycle, | ||
| tags: tag | ||
| }); | ||
| writeSubscription(get); | ||
| }); | ||
| program.command("delete").argument("<number>").action((number) => { | ||
| deleteSubscription(Number(number)); | ||
| }); | ||
| program.parse(); | ||
| }; | ||
| runCLI(); | ||
| //#endregion | ||
| export {}; |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
1
-50%3109
-65.57%4
-33.33%27
-81.25%