@mailmodo/cli 0.0.56-beta.pr58.104 → 0.0.56-beta.pr58.106
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/lib/config.d.ts +2 -0
- package/dist/lib/config.js +19 -10
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/dist/lib/config.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export declare function saveConfig(config: MailmodoConfig): Promise<void>;
|
|
|
28
28
|
export declare function clearConfig(): Promise<void>;
|
|
29
29
|
/**
|
|
30
30
|
* Returns the absolute path to the Mailmodo config directory (~/.mailmodo).
|
|
31
|
+
* Honors MAILMODO_CONFIG_DIR env var when set (used in tests to redirect away
|
|
32
|
+
* from the user's real config).
|
|
31
33
|
*
|
|
32
34
|
* @returns {string} The config directory path.
|
|
33
35
|
*/
|
package/dist/lib/config.js
CHANGED
|
@@ -2,8 +2,12 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
import { mkdir, readFile, unlink, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
function configDir() {
|
|
6
|
+
return process.env.MAILMODO_CONFIG_DIR ?? join(homedir(), '.mailmodo');
|
|
7
|
+
}
|
|
8
|
+
function configFile() {
|
|
9
|
+
return join(configDir(), 'config');
|
|
10
|
+
}
|
|
7
11
|
/**
|
|
8
12
|
* Loads the Mailmodo CLI configuration from ~/.mailmodo/config.
|
|
9
13
|
* The config file stores the API key and account metadata as JSON.
|
|
@@ -13,10 +17,11 @@ const CONFIG_FILE = join(CONFIG_DIR, 'config');
|
|
|
13
17
|
* or null if the config file does not exist or is corrupted.
|
|
14
18
|
*/
|
|
15
19
|
export async function loadConfig() {
|
|
16
|
-
|
|
20
|
+
const file = configFile();
|
|
21
|
+
if (!existsSync(file))
|
|
17
22
|
return null;
|
|
18
23
|
try {
|
|
19
|
-
const content = await readFile(
|
|
24
|
+
const content = await readFile(file, 'utf8');
|
|
20
25
|
return JSON.parse(content);
|
|
21
26
|
}
|
|
22
27
|
catch {
|
|
@@ -32,20 +37,22 @@ export async function loadConfig() {
|
|
|
32
37
|
* at minimum an apiKey. Optional fields: email, totalFreeRemaining.
|
|
33
38
|
*/
|
|
34
39
|
export async function saveConfig(config) {
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
const dir = configDir();
|
|
41
|
+
if (!existsSync(dir)) {
|
|
42
|
+
await mkdir(dir, { recursive: true });
|
|
37
43
|
}
|
|
38
|
-
await writeFile(
|
|
44
|
+
await writeFile(configFile(), JSON.stringify(config, null, 2));
|
|
39
45
|
}
|
|
40
46
|
/**
|
|
41
47
|
* Deletes the saved CLI config file (~/.mailmodo/config), removing the stored API key.
|
|
42
48
|
* No-op if the file does not exist.
|
|
43
49
|
*/
|
|
44
50
|
export async function clearConfig() {
|
|
45
|
-
|
|
51
|
+
const file = configFile();
|
|
52
|
+
if (!existsSync(file))
|
|
46
53
|
return;
|
|
47
54
|
try {
|
|
48
|
-
await unlink(
|
|
55
|
+
await unlink(file);
|
|
49
56
|
}
|
|
50
57
|
catch {
|
|
51
58
|
// Ignore missing file or permission errors; caller can treat as best-effort sign-out.
|
|
@@ -53,9 +60,11 @@ export async function clearConfig() {
|
|
|
53
60
|
}
|
|
54
61
|
/**
|
|
55
62
|
* Returns the absolute path to the Mailmodo config directory (~/.mailmodo).
|
|
63
|
+
* Honors MAILMODO_CONFIG_DIR env var when set (used in tests to redirect away
|
|
64
|
+
* from the user's real config).
|
|
56
65
|
*
|
|
57
66
|
* @returns {string} The config directory path.
|
|
58
67
|
*/
|
|
59
68
|
export function getConfigDir() {
|
|
60
|
-
return
|
|
69
|
+
return configDir();
|
|
61
70
|
}
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED