sks-maximo-utils 1.1.4 → 1.1.7
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/cli.js +11 -1
- package/nodeutils/config.js +51 -40
- package/nodeutils/maximoTools.js +4 -1
- package/nodeutils/requestHttp.js +2 -2
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -13,10 +13,12 @@ const args = process.argv.slice(2);
|
|
|
13
13
|
|
|
14
14
|
// 解析全局选项(--env)
|
|
15
15
|
let globalEnv = 'local';
|
|
16
|
+
let envSpecified = false;
|
|
16
17
|
const filteredArgs = [];
|
|
17
18
|
for (let i = 0; i < args.length; i++) {
|
|
18
19
|
if (args[i] === '--env' || args[i] === '-e') {
|
|
19
20
|
globalEnv = args[i + 1];
|
|
21
|
+
envSpecified = true;
|
|
20
22
|
i++; // 跳过值
|
|
21
23
|
} else {
|
|
22
24
|
filteredArgs.push(args[i]);
|
|
@@ -24,7 +26,15 @@ for (let i = 0; i < args.length; i++) {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
const cmd = filteredArgs[0];
|
|
27
|
-
|
|
29
|
+
|
|
30
|
+
// 兼容位置参数写法:sks-maximo import-xxx <fileName> <env>
|
|
31
|
+
const importCommands = ['import-object', 'import-appinfo', 'import-presentation', 'import-script', 'import-domain', 'import-maxintobject'];
|
|
32
|
+
if (!envSpecified && importCommands.includes(cmd)) {
|
|
33
|
+
const positionalEnv = filteredArgs[2];
|
|
34
|
+
if (positionalEnv && !positionalEnv.startsWith('-')) {
|
|
35
|
+
globalEnv = positionalEnv;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
28
38
|
|
|
29
39
|
if (!cmd || ['-h', '--help', '-?', '--version', '-v'].includes(cmd)) {
|
|
30
40
|
console.log(`sks-maximo v${packageJson.version}`);
|
package/nodeutils/config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import os from
|
|
3
|
-
import path from
|
|
4
|
-
import { fileURLToPath } from
|
|
5
|
-
import logger from
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import logger from "./logger.js";
|
|
6
6
|
|
|
7
7
|
// 获取当前模块目录
|
|
8
8
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -11,7 +11,7 @@ let globalConfig = null;
|
|
|
11
11
|
|
|
12
12
|
function getConfigPath() {
|
|
13
13
|
const homeDir = os.homedir();
|
|
14
|
-
return path.join(homeDir,
|
|
14
|
+
return path.join(homeDir, ".sks", "nodeutils", "config.json");
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function getConfigDir() {
|
|
@@ -39,7 +39,7 @@ export function loadConfig(env = null) {
|
|
|
39
39
|
|
|
40
40
|
if (!env) {
|
|
41
41
|
const args = process.argv.slice(2);
|
|
42
|
-
env = args[0]
|
|
42
|
+
env = args[0];
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
try {
|
|
@@ -53,16 +53,22 @@ export function loadConfig(env = null) {
|
|
|
53
53
|
copySampleConfig(configPath);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const configData = fs.readFileSync(configPath,
|
|
56
|
+
const configData = fs.readFileSync(configPath, "utf-8");
|
|
57
57
|
const allConfigs = JSON.parse(configData);
|
|
58
|
+
if (!env) {
|
|
59
|
+
env = allConfigs.defaultEnv;
|
|
60
|
+
}
|
|
61
|
+
if(!env){
|
|
62
|
+
throw new Error(`未找到环境 ${env} 的配置`);
|
|
63
|
+
}
|
|
58
64
|
|
|
59
65
|
// 获取全局配置
|
|
60
|
-
const globalLogLevel = allConfigs.logLevel ||
|
|
66
|
+
const globalLogLevel = allConfigs.logLevel || "INFO";
|
|
61
67
|
// console.log("globalLogLevel:"+ globalLogLevel);
|
|
62
68
|
|
|
63
69
|
// 获取环境配置
|
|
64
70
|
const envs = allConfigs.envs || {};
|
|
65
|
-
const envConfig = envs[env]
|
|
71
|
+
const envConfig = envs[env] ;
|
|
66
72
|
|
|
67
73
|
if (!envConfig) {
|
|
68
74
|
throw new Error(`未找到环境 ${env} 的配置`);
|
|
@@ -73,21 +79,21 @@ export function loadConfig(env = null) {
|
|
|
73
79
|
|
|
74
80
|
// 设置默认 authType
|
|
75
81
|
if (!globalConfig.authType) {
|
|
76
|
-
globalConfig.authType =
|
|
82
|
+
globalConfig.authType = "apiKey";
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
// logLevel 优先使用环境配置,否则使用全局配置
|
|
80
86
|
const logLevel = envConfig.logLevel || globalLogLevel;
|
|
81
|
-
|
|
87
|
+
|
|
82
88
|
// langcode 优先使用环境配置,否则使用全局配置,默认 zh
|
|
83
|
-
const langcode = envConfig.langcode || allConfigs.langcode ||
|
|
89
|
+
const langcode = envConfig.langcode || allConfigs.langcode || "zh";
|
|
84
90
|
globalConfig.langcode = langcode;
|
|
85
91
|
|
|
86
92
|
// 规范化 baseUrl
|
|
87
93
|
if (globalConfig.baseUrl) {
|
|
88
|
-
globalConfig.baseUrl = globalConfig.baseUrl.replace(/\\/g,
|
|
89
|
-
if (!globalConfig.baseUrl.endsWith(
|
|
90
|
-
globalConfig.baseUrl +=
|
|
94
|
+
globalConfig.baseUrl = globalConfig.baseUrl.replace(/\\/g, "/");
|
|
95
|
+
if (!globalConfig.baseUrl.endsWith("/")) {
|
|
96
|
+
globalConfig.baseUrl += "/";
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
99
|
|
|
@@ -102,7 +108,7 @@ export function loadConfig(env = null) {
|
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
function copySampleConfig(configPath) {
|
|
105
|
-
const sampleConfigPath = path.join(__dirname,
|
|
111
|
+
const sampleConfigPath = path.join(__dirname, "sample.config.json");
|
|
106
112
|
|
|
107
113
|
const configDir = path.dirname(configPath);
|
|
108
114
|
if (!fs.existsSync(configDir)) {
|
|
@@ -115,30 +121,35 @@ function copySampleConfig(configPath) {
|
|
|
115
121
|
} else {
|
|
116
122
|
// 如果 sample.config.json 不存在,创建默认配置
|
|
117
123
|
const defaultConfig = {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
"
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
logLevel: "INFO",
|
|
125
|
+
langcode: "zh",
|
|
126
|
+
defaultEnv: "local",
|
|
127
|
+
envs: {
|
|
128
|
+
local: {
|
|
129
|
+
baseUrl: "http://127.0.0.1:9080/maximo",
|
|
130
|
+
langcode: "zh",
|
|
131
|
+
apiKey: "your-api-key-here",
|
|
132
|
+
maxauth: "",
|
|
126
133
|
},
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
134
|
+
dev: {
|
|
135
|
+
baseUrl: "https://mdev/maximo",
|
|
136
|
+
langcode: "zh",
|
|
137
|
+
apiKey: "your-api-key-here",
|
|
138
|
+
maxauth: "",
|
|
132
139
|
},
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
+
hd: {
|
|
141
|
+
baseUrl: "http://xxxxx:9080/maximo",
|
|
142
|
+
langcode: "zh",
|
|
143
|
+
apiKey: "your-api-key-here",
|
|
144
|
+
maxauth: "",
|
|
145
|
+
},
|
|
146
|
+
},
|
|
140
147
|
};
|
|
141
|
-
fs.writeFileSync(
|
|
148
|
+
fs.writeFileSync(
|
|
149
|
+
configPath,
|
|
150
|
+
JSON.stringify(defaultConfig, null, 2),
|
|
151
|
+
"utf-8",
|
|
152
|
+
);
|
|
142
153
|
logger.info(`[Config] 已创建默认配置文件: ${configPath}`);
|
|
143
154
|
}
|
|
144
155
|
}
|
|
@@ -159,5 +170,5 @@ export default {
|
|
|
159
170
|
getConfig,
|
|
160
171
|
getWorkDir,
|
|
161
172
|
getConfigDir,
|
|
162
|
-
checkAndCreateConfig
|
|
163
|
-
};
|
|
173
|
+
checkAndCreateConfig,
|
|
174
|
+
};
|
package/nodeutils/maximoTools.js
CHANGED
|
@@ -500,7 +500,10 @@ export async function importMaxScript({fileName, logname}) {
|
|
|
500
500
|
|
|
501
501
|
var headers={};
|
|
502
502
|
if (scriptExists && scriptHref) {
|
|
503
|
-
|
|
503
|
+
// Maximo 的资源 ID 是标准 base64 且把填充位 = 替换为 -(如 ...Uw== → ...Uw--),
|
|
504
|
+
// 不能用 base64url(直接去掉填充会导致服务端找不到资源而返回 404)。
|
|
505
|
+
const scriptId = Buffer.from(autoscript).toString('base64').replace(/=+$/, m => '-'.repeat(m.length));
|
|
506
|
+
deployUrl = `api/os/MXSCRIPT/_${scriptId}`;
|
|
504
507
|
deployMethod = 'POST';
|
|
505
508
|
headers = {
|
|
506
509
|
'Content-Type': 'application/merge-patch+json',
|
package/nodeutils/requestHttp.js
CHANGED
|
@@ -29,10 +29,10 @@ function limitLogOutput(data, maxLength = 200) {
|
|
|
29
29
|
|
|
30
30
|
function joinUrl(base, path) {
|
|
31
31
|
if(path!=null&&path!==''){
|
|
32
|
-
|
|
32
|
+
logger.debug(`[HTTP Log] ------------ base: ${base}, path: ${path}`);
|
|
33
|
+
if(path.startsWith('http://')||path.startsWith('https://')){
|
|
33
34
|
return path;
|
|
34
35
|
}
|
|
35
|
-
|
|
36
36
|
}
|
|
37
37
|
return `${base.replace(/\/$/, '')}/${path.replace(/^\//, '')}`;
|
|
38
38
|
}
|