@hintoai/cli 0.3.4 → 0.3.5
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/config.d.ts +1 -1
- package/dist/config.js +14 -6
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export interface HintoConfig {
|
|
|
2
2
|
apiKey: string;
|
|
3
3
|
baseUrl: string;
|
|
4
4
|
}
|
|
5
|
-
export declare
|
|
5
|
+
export declare function configPath(): string;
|
|
6
6
|
export declare function saveConfig(config: HintoConfig): void;
|
|
7
7
|
export declare function loadConfig(): HintoConfig;
|
package/dist/config.js
CHANGED
|
@@ -3,27 +3,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.configPath = configPath;
|
|
7
7
|
exports.saveConfig = saveConfig;
|
|
8
8
|
exports.loadConfig = loadConfig;
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const os_1 = __importDefault(require("os"));
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
|
-
|
|
12
|
+
// Evaluated lazily (not at module import) so the location always reflects the
|
|
13
|
+
// current environment. Tests redirect it with HINTO_CONFIG_DIR to avoid touching
|
|
14
|
+
// the real ~/.hinto/config.json.
|
|
15
|
+
function configPath() {
|
|
16
|
+
const dir = process.env.HINTO_CONFIG_DIR ?? path_1.default.join(os_1.default.homedir(), '.hinto');
|
|
17
|
+
return path_1.default.join(dir, 'config.json');
|
|
18
|
+
}
|
|
13
19
|
function saveConfig(config) {
|
|
14
|
-
const
|
|
20
|
+
const file = configPath();
|
|
21
|
+
const dir = path_1.default.dirname(file);
|
|
15
22
|
if (!fs_1.default.existsSync(dir))
|
|
16
23
|
fs_1.default.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
17
|
-
fs_1.default.writeFileSync(
|
|
24
|
+
fs_1.default.writeFileSync(file, JSON.stringify(config, null, 2), {
|
|
18
25
|
encoding: 'utf-8',
|
|
19
26
|
mode: 0o600,
|
|
20
27
|
});
|
|
21
28
|
}
|
|
22
29
|
function loadConfig() {
|
|
23
|
-
|
|
30
|
+
const file = configPath();
|
|
31
|
+
if (!fs_1.default.existsSync(file)) {
|
|
24
32
|
throw new Error('Run `hinto init --key <your-api-key>` to get started.');
|
|
25
33
|
}
|
|
26
|
-
const raw = JSON.parse(fs_1.default.readFileSync(
|
|
34
|
+
const raw = JSON.parse(fs_1.default.readFileSync(file, 'utf-8'));
|
|
27
35
|
return {
|
|
28
36
|
...raw,
|
|
29
37
|
apiKey: process.env.HINTO_API_KEY ?? raw.apiKey,
|