sks-maximo-utils 1.1.6 → 1.1.8
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/README.md +38 -9
- package/cli.js +12 -2
- package/nodeutils/config.js +51 -40
- package/nodeutils/maximoTools.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Maximo 表结构和数据更新工具集。
|
|
|
14
14
|
|
|
15
15
|
### 全局安装(CLI 使用)
|
|
16
16
|
```bash
|
|
17
|
-
npm install -g
|
|
17
|
+
npm install -g sks-maximo-utils
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
### 项目中安装(引用使用)
|
|
@@ -26,18 +26,39 @@ npm install sks-maximo-utils
|
|
|
26
26
|
|
|
27
27
|
### CLI 命令
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
不带参数运行,检查配置并打开配置目录:
|
|
30
30
|
```bash
|
|
31
31
|
sks-maximo
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
导入命令通用格式:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
sks-maximo <import-command> <fileName> [env] [--logname <name>]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
环境既可以用位置参数,也可以用 `-e` / `--env` 指定,两者等价:
|
|
41
|
+
|
|
35
42
|
```bash
|
|
36
|
-
sks-maximo
|
|
37
|
-
sks-maximo
|
|
38
|
-
sks-maximo hd # 使用 hd 环境配置
|
|
43
|
+
sks-maximo import-presentation LIBRARY_EN.xml prod_en
|
|
44
|
+
sks-maximo import-presentation LIBRARY_EN.xml -e prod_en
|
|
39
45
|
```
|
|
40
46
|
|
|
47
|
+
导入命令:
|
|
48
|
+
|
|
49
|
+
| 命令 | 说明 |
|
|
50
|
+
|------|------|
|
|
51
|
+
| `sks-maximo import-object <fileName>` | 导入 Maximo 对象配置 |
|
|
52
|
+
| `sks-maximo import-appinfo <fileName>` | 导入应用信息配置 |
|
|
53
|
+
| `sks-maximo import-presentation <fileName>` | 导入应用 XML 配置 |
|
|
54
|
+
| `sks-maximo import-script <fileName>` | 导入自动化脚本 |
|
|
55
|
+
| `sks-maximo import-domain <fileName>` | 导入域配置 |
|
|
56
|
+
| `sks-maximo import-maxintobject <fileName>` | 导入对象结构(Integration Object)配置 |
|
|
57
|
+
|
|
58
|
+
环境名必须是 `~/.sks/nodeutils/config.json` 中 `envs` 下已存在的键(例如 `local`、`dev`、`dev_en`、`prod`、`prod_en`、`hd`)。请求会自动追加 `_langcode` 参数,取该环境配置的 `langcode`;环境未配置时取全局 `langcode`(默认 `zh`)。因此做英文数据导入时,要传入配置了 `"langcode": "en"` 的环境,例如 `prod_en`。
|
|
59
|
+
|
|
60
|
+
所有导入命令都支持 `-l` / `--logname <name>` 自定义日志前缀。
|
|
61
|
+
|
|
41
62
|
### 在脚本中引用
|
|
42
63
|
|
|
43
64
|
```javascript
|
|
@@ -128,17 +149,25 @@ fileUtils.readFileContent('test.txt');
|
|
|
128
149
|
"authType": "apiKey",
|
|
129
150
|
"langcode": "zh"
|
|
130
151
|
},
|
|
131
|
-
"
|
|
132
|
-
"baseUrl": "https://
|
|
152
|
+
"prod": {
|
|
153
|
+
"baseUrl": "https://main.manage.prod.example.com/maximo",
|
|
154
|
+
"apiKey": "your-api-key",
|
|
155
|
+
"maxauth": "",
|
|
156
|
+
"authType": "apiKey"
|
|
157
|
+
},
|
|
158
|
+
"prod_en": {
|
|
159
|
+
"baseUrl": "https://main.manage.prod.example.com/maximo",
|
|
133
160
|
"apiKey": "your-api-key",
|
|
134
161
|
"maxauth": "",
|
|
135
162
|
"authType": "apiKey",
|
|
136
|
-
"langcode": "
|
|
163
|
+
"langcode": "en"
|
|
137
164
|
}
|
|
138
165
|
}
|
|
139
166
|
}
|
|
140
167
|
```
|
|
141
168
|
|
|
169
|
+
`envs` 下的键就是环境名,可自行命名(如 `loc`、`dev`、`dev_en`、`prod`、`prod_en`、`hd`)。同一个 Maximo 服务可以配置多个环境名,仅 `langcode` 不同,用于分别导入中文/英文数据。
|
|
170
|
+
|
|
142
171
|
### 配置说明
|
|
143
172
|
|
|
144
173
|
| 字段 | 说明 |
|
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}`);
|
|
@@ -57,7 +67,7 @@ if (!cmd || ['-h', '--help', '-?', '--version', '-v'].includes(cmd)) {
|
|
|
57
67
|
console.log('选项:');
|
|
58
68
|
console.log(' -h, --help # 显示帮助信息');
|
|
59
69
|
console.log(' -v, --version # 显示版本信息');
|
|
60
|
-
console.log(' --env, -e <env> #
|
|
70
|
+
console.log(' --env, -e <env> # 指定环境(直接输入sks-maximo 可进行打开配置目录)');
|
|
61
71
|
console.log(' --file <fileName> # 请求体文件路径(JSON)');
|
|
62
72
|
console.log(' --params <params> # URL参数(JSON格式)');
|
|
63
73
|
console.log('');
|
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',
|