memes-business 0.0.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.
@@ -0,0 +1,92 @@
1
+ import { mkdir, readFile, writeFile, access } from "node:fs/promises";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ const CONFIG_DIR = join(homedir(), ".config", "memes-cli");
5
+ const CONFIG_FILE = join(CONFIG_DIR, "config.json");
6
+ const DEFAULT_API_URL = "https://memes.business";
7
+ /**
8
+ * Ensure config directory exists
9
+ */
10
+ async function ensureConfigDir() {
11
+ await mkdir(CONFIG_DIR, { recursive: true });
12
+ }
13
+ /**
14
+ * Check if config file exists
15
+ */
16
+ async function configExists() {
17
+ try {
18
+ await access(CONFIG_FILE);
19
+ return true;
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ /**
26
+ * Load configuration from disk
27
+ */
28
+ export async function loadConfig() {
29
+ if (!(await configExists())) {
30
+ return { apiUrl: DEFAULT_API_URL };
31
+ }
32
+ try {
33
+ const content = await readFile(CONFIG_FILE, "utf-8");
34
+ const config = JSON.parse(content);
35
+ return {
36
+ apiUrl: DEFAULT_API_URL,
37
+ ...config,
38
+ };
39
+ }
40
+ catch {
41
+ return { apiUrl: DEFAULT_API_URL };
42
+ }
43
+ }
44
+ /**
45
+ * Save configuration to disk
46
+ * Sets restrictive permissions (0600) since config contains API keys
47
+ */
48
+ export async function saveConfig(config) {
49
+ await ensureConfigDir();
50
+ await writeFile(CONFIG_FILE, JSON.stringify(config, null, 2), {
51
+ encoding: "utf-8",
52
+ mode: 0o600,
53
+ });
54
+ }
55
+ /**
56
+ * Get the API key from config
57
+ */
58
+ export async function getApiKey() {
59
+ const config = await loadConfig();
60
+ return config.apiKey;
61
+ }
62
+ /**
63
+ * Set the API key in config
64
+ */
65
+ export async function setApiKey(apiKey) {
66
+ const config = await loadConfig();
67
+ config.apiKey = apiKey;
68
+ await saveConfig(config);
69
+ }
70
+ /**
71
+ * Clear the API key from config
72
+ */
73
+ export async function clearApiKey() {
74
+ const config = await loadConfig();
75
+ delete config.apiKey;
76
+ await saveConfig(config);
77
+ }
78
+ /**
79
+ * Get the API URL from config
80
+ */
81
+ export async function getApiUrl() {
82
+ const config = await loadConfig();
83
+ return config.apiUrl || DEFAULT_API_URL;
84
+ }
85
+ /**
86
+ * Check if user is authenticated
87
+ */
88
+ export async function isAuthenticated() {
89
+ const apiKey = await getApiKey();
90
+ return !!apiKey;
91
+ }
92
+ export { CONFIG_DIR, CONFIG_FILE };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "memes-business",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "description": "CLI for memes.business",
6
+ "author": "wookiehangover",
7
+ "license": "MIT",
8
+ "homepage": "https://memes.business",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/sutterhill/memes.business.git",
12
+ "directory": "cli"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/sutterhill/memes.business/issues"
16
+ },
17
+ "keywords": [
18
+ "memes",
19
+ "meme-generator",
20
+ "cli",
21
+ "ai"
22
+ ],
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "bin": {
27
+ "memes": "./dist/index.js"
28
+ },
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "dev": "tsc --watch",
32
+ "start": "node dist/index.js",
33
+ "prepublishOnly": "npm run build"
34
+ },
35
+ "dependencies": {
36
+ "@inquirer/prompts": "^8.2.0",
37
+ "chalk": "^5.4.1",
38
+ "commander": "^13.1.0",
39
+ "inquirer": "^12.6.0",
40
+ "open": "^11.0.0",
41
+ "ora": "^8.2.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^22.19.1",
45
+ "typescript": "^5.9.3"
46
+ },
47
+ "engines": {
48
+ "node": ">=18"
49
+ }
50
+ }