@openfort/cli 0.1.8 → 0.1.9
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/bin.js +6 -17
- package/dist/chunk-SVNLXGFY.js +68 -0
- package/dist/cli.js +695 -756
- package/package.json +1 -1
- package/src/bin.ts +5 -17
- package/dist/chunk-QJGHQ7ID.js +0 -25
package/dist/bin.js
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
CREDENTIALS_PATH
|
|
4
|
-
|
|
3
|
+
CREDENTIALS_PATH,
|
|
4
|
+
loadEnvFile
|
|
5
|
+
} from "./chunk-SVNLXGFY.js";
|
|
5
6
|
|
|
6
7
|
// src/bin.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const content = readFileSync(filePath, "utf-8");
|
|
11
|
-
for (const line of content.split("\n")) {
|
|
12
|
-
const trimmed = line.trim();
|
|
13
|
-
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
14
|
-
const eqIndex = trimmed.indexOf("=");
|
|
15
|
-
if (eqIndex === -1) continue;
|
|
16
|
-
const key = trimmed.slice(0, eqIndex).trim();
|
|
17
|
-
const value = trimmed.slice(eqIndex + 1).trim();
|
|
18
|
-
if (!process.env[key]) {
|
|
19
|
-
process.env[key] = value;
|
|
20
|
-
}
|
|
8
|
+
for (const [key, value] of loadEnvFile(CREDENTIALS_PATH)) {
|
|
9
|
+
if (!process.env[key]) {
|
|
10
|
+
process.env[key] = value;
|
|
21
11
|
}
|
|
22
12
|
}
|
|
23
|
-
loadEnvIntoProcess(CREDENTIALS_PATH);
|
|
24
13
|
var { default: cli } = await import("./cli.js");
|
|
25
14
|
cli.serve();
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/config.ts
|
|
4
|
+
import { homedir } from "os";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
import { mkdirSync } from "fs";
|
|
7
|
+
function getConfigDir() {
|
|
8
|
+
if (process.env.XDG_CONFIG_HOME) {
|
|
9
|
+
return join(process.env.XDG_CONFIG_HOME, "openfort");
|
|
10
|
+
}
|
|
11
|
+
if (process.platform === "win32" && process.env.APPDATA) {
|
|
12
|
+
return join(process.env.APPDATA, "openfort");
|
|
13
|
+
}
|
|
14
|
+
return join(homedir(), ".config", "openfort");
|
|
15
|
+
}
|
|
16
|
+
var CONFIG_DIR = getConfigDir();
|
|
17
|
+
var CREDENTIALS_PATH = join(CONFIG_DIR, "credentials");
|
|
18
|
+
function ensureConfigDir() {
|
|
19
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/env.ts
|
|
23
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
24
|
+
import { Errors } from "incur";
|
|
25
|
+
function loadEnvFile(envPath) {
|
|
26
|
+
const entries = /* @__PURE__ */ new Map();
|
|
27
|
+
if (!existsSync(envPath)) return entries;
|
|
28
|
+
const content = readFileSync(envPath, "utf-8");
|
|
29
|
+
for (const line of content.split("\n")) {
|
|
30
|
+
const trimmed = line.trim();
|
|
31
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
32
|
+
const eqIndex = trimmed.indexOf("=");
|
|
33
|
+
if (eqIndex === -1) continue;
|
|
34
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
35
|
+
const value = trimmed.slice(eqIndex + 1).trim();
|
|
36
|
+
entries.set(key, value);
|
|
37
|
+
}
|
|
38
|
+
return entries;
|
|
39
|
+
}
|
|
40
|
+
function writeEnvKey(envPath, key, value) {
|
|
41
|
+
const entries = loadEnvFile(envPath);
|
|
42
|
+
entries.set(key, value);
|
|
43
|
+
const lines = [];
|
|
44
|
+
for (const [k, v] of entries) {
|
|
45
|
+
lines.push(`${k}=${v}`);
|
|
46
|
+
}
|
|
47
|
+
writeFileSync(envPath, `${lines.join("\n")}
|
|
48
|
+
`);
|
|
49
|
+
}
|
|
50
|
+
function requireApiKey() {
|
|
51
|
+
const apiKey = process.env.OPENFORT_API_KEY;
|
|
52
|
+
if (!apiKey) {
|
|
53
|
+
throw new Errors.IncurError({
|
|
54
|
+
code: "MISSING_API_KEY",
|
|
55
|
+
message: "OPENFORT_API_KEY is required.",
|
|
56
|
+
hint: "Run: openfort login"
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return apiKey;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export {
|
|
63
|
+
CREDENTIALS_PATH,
|
|
64
|
+
ensureConfigDir,
|
|
65
|
+
loadEnvFile,
|
|
66
|
+
writeEnvKey,
|
|
67
|
+
requireApiKey
|
|
68
|
+
};
|