@tryarcanist/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/index.js +10 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,9 +4,14 @@
|
|
|
4
4
|
import { createRequire } from "module";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
|
|
7
|
+
// ../../shared/utils/url.ts
|
|
8
|
+
function normalizeBaseUrl(url) {
|
|
9
|
+
return url.replace(/\/+$/, "");
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
// src/api.ts
|
|
8
13
|
async function apiRequest(config, path, init) {
|
|
9
|
-
const res = await fetch(`${config.apiUrl}${path}`, {
|
|
14
|
+
const res = await fetch(`${normalizeBaseUrl(config.apiUrl)}${path}`, {
|
|
10
15
|
...init,
|
|
11
16
|
headers: {
|
|
12
17
|
"Content-Type": "application/json",
|
|
@@ -40,14 +45,15 @@ var CONFIG_DIR = join(homedir(), ".arcanist");
|
|
|
40
45
|
var CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
41
46
|
function loadConfig() {
|
|
42
47
|
try {
|
|
43
|
-
|
|
48
|
+
const config = JSON.parse(readFileSync(CONFIG_FILE, "utf-8"));
|
|
49
|
+
return { ...config, apiUrl: normalizeBaseUrl(config.apiUrl) };
|
|
44
50
|
} catch {
|
|
45
51
|
return null;
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
54
|
function saveConfig(config) {
|
|
49
55
|
mkdirSync(CONFIG_DIR, { recursive: true, mode: 448 });
|
|
50
|
-
writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n", { mode: 384 });
|
|
56
|
+
writeFileSync(CONFIG_FILE, JSON.stringify({ ...config, apiUrl: normalizeBaseUrl(config.apiUrl) }, null, 2) + "\n", { mode: 384 });
|
|
51
57
|
}
|
|
52
58
|
function requireConfig() {
|
|
53
59
|
const config = loadConfig();
|
|
@@ -146,7 +152,7 @@ async function loginCommand(options) {
|
|
|
146
152
|
process.exit(1);
|
|
147
153
|
}
|
|
148
154
|
}
|
|
149
|
-
const apiUrl = options.apiUrl ?? loadConfig()?.apiUrl ?? "https://app.tryarcanist.com";
|
|
155
|
+
const apiUrl = normalizeBaseUrl(options.apiUrl ?? loadConfig()?.apiUrl ?? "https://app.tryarcanist.com");
|
|
150
156
|
saveConfig({ apiUrl, token });
|
|
151
157
|
console.log(`Logged in. API: ${apiUrl}`);
|
|
152
158
|
try {
|