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