@amaster.ai/runtime-cli 1.1.36 → 1.1.38-beta.0
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/cli.cjs +31 -21
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +31 -21
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +32 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +32 -22
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -27,6 +27,7 @@ __export(config_exports, {
|
|
|
27
27
|
clearAuthSession: () => clearAuthSession,
|
|
28
28
|
ensureRegistry: () => ensureRegistry,
|
|
29
29
|
getAccessToken: () => getAccessToken,
|
|
30
|
+
getAmasterConfigDir: () => getAmasterConfigDir,
|
|
30
31
|
getAppConfig: () => getAppConfig,
|
|
31
32
|
getAuthSession: () => getAuthSession,
|
|
32
33
|
getBaseURL: () => getBaseURL,
|
|
@@ -48,21 +49,32 @@ __export(config_exports, {
|
|
|
48
49
|
setCurrentRegistry: () => setCurrentRegistry,
|
|
49
50
|
shouldRefreshToken: () => shouldRefreshToken
|
|
50
51
|
});
|
|
52
|
+
function getAmasterConfigDir() {
|
|
53
|
+
return process.env.AMASTER_CONFIG_DIR?.trim() || join(homedir(), ".amaster");
|
|
54
|
+
}
|
|
55
|
+
function configFile() {
|
|
56
|
+
return join(getAmasterConfigDir(), "config.json");
|
|
57
|
+
}
|
|
58
|
+
function authFile(appCode) {
|
|
59
|
+
return join(getAmasterConfigDir(), `auth-${appCode}.json`);
|
|
60
|
+
}
|
|
51
61
|
function getConfig() {
|
|
52
|
-
|
|
62
|
+
const file = configFile();
|
|
63
|
+
if (!existsSync(file)) {
|
|
53
64
|
return { apps: {} };
|
|
54
65
|
}
|
|
55
66
|
try {
|
|
56
|
-
return JSON.parse(readFileSync(
|
|
67
|
+
return JSON.parse(readFileSync(file, "utf-8"));
|
|
57
68
|
} catch {
|
|
58
69
|
return { apps: {} };
|
|
59
70
|
}
|
|
60
71
|
}
|
|
61
72
|
function saveConfig(config) {
|
|
62
|
-
|
|
63
|
-
|
|
73
|
+
const configDir = getAmasterConfigDir();
|
|
74
|
+
if (!existsSync(configDir)) {
|
|
75
|
+
mkdirSync(configDir, { recursive: true });
|
|
64
76
|
}
|
|
65
|
-
writeFileSync(
|
|
77
|
+
writeFileSync(configFile(), JSON.stringify(config, null, 2));
|
|
66
78
|
}
|
|
67
79
|
function getAppConfig(appCode) {
|
|
68
80
|
const config = getConfig();
|
|
@@ -80,9 +92,9 @@ function removeApp(appCode) {
|
|
|
80
92
|
const config = getConfig();
|
|
81
93
|
if (config.apps[appCode]) {
|
|
82
94
|
delete config.apps[appCode];
|
|
83
|
-
const
|
|
84
|
-
if (existsSync(
|
|
85
|
-
rmSync(
|
|
95
|
+
const file = authFile(appCode);
|
|
96
|
+
if (existsSync(file)) {
|
|
97
|
+
rmSync(file, { force: true });
|
|
86
98
|
}
|
|
87
99
|
if (config.currentApp === appCode) {
|
|
88
100
|
const remainingApps = Object.keys(config.apps);
|
|
@@ -246,28 +258,28 @@ function getBaseURL(appCode) {
|
|
|
246
258
|
return appConfig?.baseURL || null;
|
|
247
259
|
}
|
|
248
260
|
function getAuthSession(appCode) {
|
|
249
|
-
const
|
|
250
|
-
if (!existsSync(
|
|
261
|
+
const file = authFile(appCode);
|
|
262
|
+
if (!existsSync(file)) {
|
|
251
263
|
return null;
|
|
252
264
|
}
|
|
253
265
|
try {
|
|
254
|
-
const content = readFileSync(
|
|
266
|
+
const content = readFileSync(file, "utf-8");
|
|
255
267
|
return JSON.parse(content);
|
|
256
268
|
} catch {
|
|
257
269
|
return null;
|
|
258
270
|
}
|
|
259
271
|
}
|
|
260
272
|
function saveAuthSession(appCode, session) {
|
|
261
|
-
|
|
262
|
-
|
|
273
|
+
const configDir = getAmasterConfigDir();
|
|
274
|
+
if (!existsSync(configDir)) {
|
|
275
|
+
mkdirSync(configDir, { recursive: true });
|
|
263
276
|
}
|
|
264
|
-
|
|
265
|
-
writeFileSync(authFile, JSON.stringify(session, null, 2), { mode: 384 });
|
|
277
|
+
writeFileSync(authFile(appCode), JSON.stringify(session, null, 2), { mode: 384 });
|
|
266
278
|
}
|
|
267
279
|
function clearAuthSession(appCode) {
|
|
268
|
-
const
|
|
269
|
-
if (existsSync(
|
|
270
|
-
rmSync(
|
|
280
|
+
const file = authFile(appCode);
|
|
281
|
+
if (existsSync(file)) {
|
|
282
|
+
rmSync(file, { force: true });
|
|
271
283
|
}
|
|
272
284
|
}
|
|
273
285
|
function isAuthenticated(appCode) {
|
|
@@ -306,11 +318,9 @@ function isLocalLikeHost(hostname) {
|
|
|
306
318
|
}
|
|
307
319
|
return false;
|
|
308
320
|
}
|
|
309
|
-
var
|
|
321
|
+
var DEFAULT_REGISTRY_NAME, BUILTIN_REGISTRY_DEFINITIONS;
|
|
310
322
|
var init_config = __esm({
|
|
311
323
|
"src/config.ts"() {
|
|
312
|
-
AMASTER_CONFIG_DIR = join(homedir(), ".amaster");
|
|
313
|
-
CONFIG_FILE = join(AMASTER_CONFIG_DIR, "config.json");
|
|
314
324
|
DEFAULT_REGISTRY_NAME = "helige";
|
|
315
325
|
BUILTIN_REGISTRY_DEFINITIONS = {
|
|
316
326
|
helige: "https://helige.cn",
|