@amaster.ai/runtime-cli 1.1.37 → 1.1.38

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 CHANGED
@@ -36,6 +36,7 @@ __export(config_exports, {
36
36
  clearAuthSession: () => clearAuthSession,
37
37
  ensureRegistry: () => ensureRegistry,
38
38
  getAccessToken: () => getAccessToken,
39
+ getAmasterConfigDir: () => getAmasterConfigDir,
39
40
  getAppConfig: () => getAppConfig,
40
41
  getAuthSession: () => getAuthSession,
41
42
  getBaseURL: () => getBaseURL,
@@ -57,21 +58,32 @@ __export(config_exports, {
57
58
  setCurrentRegistry: () => setCurrentRegistry,
58
59
  shouldRefreshToken: () => shouldRefreshToken
59
60
  });
61
+ function getAmasterConfigDir() {
62
+ return process.env.AMASTER_CONFIG_DIR?.trim() || path.join(os.homedir(), ".amaster");
63
+ }
64
+ function configFile() {
65
+ return path.join(getAmasterConfigDir(), "config.json");
66
+ }
67
+ function authFile(appCode) {
68
+ return path.join(getAmasterConfigDir(), `auth-${appCode}.json`);
69
+ }
60
70
  function getConfig() {
61
- if (!fs.existsSync(CONFIG_FILE)) {
71
+ const file = configFile();
72
+ if (!fs.existsSync(file)) {
62
73
  return { apps: {} };
63
74
  }
64
75
  try {
65
- return JSON.parse(fs.readFileSync(CONFIG_FILE, "utf-8"));
76
+ return JSON.parse(fs.readFileSync(file, "utf-8"));
66
77
  } catch {
67
78
  return { apps: {} };
68
79
  }
69
80
  }
70
81
  function saveConfig(config) {
71
- if (!fs.existsSync(AMASTER_CONFIG_DIR)) {
72
- fs.mkdirSync(AMASTER_CONFIG_DIR, { recursive: true });
82
+ const configDir = getAmasterConfigDir();
83
+ if (!fs.existsSync(configDir)) {
84
+ fs.mkdirSync(configDir, { recursive: true });
73
85
  }
74
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
86
+ fs.writeFileSync(configFile(), JSON.stringify(config, null, 2));
75
87
  }
76
88
  function getAppConfig(appCode) {
77
89
  const config = getConfig();
@@ -89,9 +101,9 @@ function removeApp(appCode) {
89
101
  const config = getConfig();
90
102
  if (config.apps[appCode]) {
91
103
  delete config.apps[appCode];
92
- const authFile = path.join(AMASTER_CONFIG_DIR, `auth-${appCode}.json`);
93
- if (fs.existsSync(authFile)) {
94
- fs.rmSync(authFile, { force: true });
104
+ const file = authFile(appCode);
105
+ if (fs.existsSync(file)) {
106
+ fs.rmSync(file, { force: true });
95
107
  }
96
108
  if (config.currentApp === appCode) {
97
109
  const remainingApps = Object.keys(config.apps);
@@ -255,28 +267,28 @@ function getBaseURL(appCode) {
255
267
  return appConfig?.baseURL || null;
256
268
  }
257
269
  function getAuthSession(appCode) {
258
- const authFile = path.join(AMASTER_CONFIG_DIR, `auth-${appCode}.json`);
259
- if (!fs.existsSync(authFile)) {
270
+ const file = authFile(appCode);
271
+ if (!fs.existsSync(file)) {
260
272
  return null;
261
273
  }
262
274
  try {
263
- const content = fs.readFileSync(authFile, "utf-8");
275
+ const content = fs.readFileSync(file, "utf-8");
264
276
  return JSON.parse(content);
265
277
  } catch {
266
278
  return null;
267
279
  }
268
280
  }
269
281
  function saveAuthSession(appCode, session) {
270
- if (!fs.existsSync(AMASTER_CONFIG_DIR)) {
271
- fs.mkdirSync(AMASTER_CONFIG_DIR, { recursive: true });
282
+ const configDir = getAmasterConfigDir();
283
+ if (!fs.existsSync(configDir)) {
284
+ fs.mkdirSync(configDir, { recursive: true });
272
285
  }
273
- const authFile = path.join(AMASTER_CONFIG_DIR, `auth-${appCode}.json`);
274
- fs.writeFileSync(authFile, JSON.stringify(session, null, 2), { mode: 384 });
286
+ fs.writeFileSync(authFile(appCode), JSON.stringify(session, null, 2), { mode: 384 });
275
287
  }
276
288
  function clearAuthSession(appCode) {
277
- const authFile = path.join(AMASTER_CONFIG_DIR, `auth-${appCode}.json`);
278
- if (fs.existsSync(authFile)) {
279
- fs.rmSync(authFile, { force: true });
289
+ const file = authFile(appCode);
290
+ if (fs.existsSync(file)) {
291
+ fs.rmSync(file, { force: true });
280
292
  }
281
293
  }
282
294
  function isAuthenticated(appCode) {
@@ -315,11 +327,9 @@ function isLocalLikeHost(hostname) {
315
327
  }
316
328
  return false;
317
329
  }
318
- var AMASTER_CONFIG_DIR, CONFIG_FILE, DEFAULT_REGISTRY_NAME, BUILTIN_REGISTRY_DEFINITIONS;
330
+ var DEFAULT_REGISTRY_NAME, BUILTIN_REGISTRY_DEFINITIONS;
319
331
  var init_config = __esm({
320
332
  "src/config.ts"() {
321
- AMASTER_CONFIG_DIR = path.join(os.homedir(), ".amaster");
322
- CONFIG_FILE = path.join(AMASTER_CONFIG_DIR, "config.json");
323
333
  DEFAULT_REGISTRY_NAME = "helige";
324
334
  BUILTIN_REGISTRY_DEFINITIONS = {
325
335
  helige: "https://helige.cn",