cuxml 2.1.0 → 2.1.2

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 CHANGED
@@ -34,13 +34,41 @@ cuxml -i ./ribbon.xml # 输出到 ./ribbon_temp.js
34
34
  # 指定输出路径
35
35
  cuxml -i ./ribbon.xml -o ./ribbon.js
36
36
 
37
- # 监视模式(文件变化时自动转换)
38
- cuxml -i ./ribbon.xml -w # 输出到 ./ribbon_temp.js
37
+ # 监视模式(文件变化时自动转换,默认覆盖输出文件)
38
+ cuxml -i ./ribbon.xml -w
39
+
40
+ # 非 watch 模式下覆盖已存在的输出文件
41
+ cuxml -i ./ribbon.xml -o ./ribbon.js --overwrite
39
42
 
40
43
  # 使用默认输入路径(当前目录下的 ribbon.xml)
41
44
  cuxml # 需要在当前目录有 ribbon.xml 文件
42
45
  ```
43
46
 
47
+ **选项说明:**
48
+
49
+ | 选项 | 说明 |
50
+ |------|------|
51
+ | `-i, --input` | 输入的 XML 文件路径 |
52
+ | `-o, --output` | 输出的 JS 文件路径 |
53
+ | `-w, --watch` | 监视文件变化并自动转换(自动覆盖) |
54
+ | `--overwrite` | 覆盖输出文件(非 watch 模式使用) |
55
+
56
+ #### convert 子命令
57
+
58
+ ```bash
59
+ # 基本转换
60
+ cuxml convert ./ribbon.xml
61
+
62
+ # 指定输入输出
63
+ cuxml convert ./ribbon.xml ./ribbon.js
64
+
65
+ # 监视模式
66
+ cuxml convert ./ribbon.xml ./ribbon.js -w
67
+
68
+ # 非 watch 模式下覆盖文件
69
+ cuxml convert ./ribbon.xml ./ribbon.js --overwrite
70
+ ```
71
+
44
72
  #### 检查 XML 文件
45
73
 
46
74
  ```bash
@@ -109,10 +137,6 @@ npm install @modelcontextprotocol/sdk
109
137
  }
110
138
  ```
111
139
 
112
- ## 📖 详细文档
113
-
114
- 完整的使用文档和技术细节请参考:[CUXML Agent 文档](./test/agent_new.md)
115
-
116
140
  ## 🔧 功能说明
117
141
 
118
142
  ### XML 到 JavaScript 转换
@@ -246,8 +270,3 @@ try {
246
270
  - ✨ 改进的错误处理和日志输出
247
271
  - 🔧 优化项目结构
248
272
  - 🐛 修复多个已知问题
249
-
250
- ### v1.0.x
251
-
252
- - 初始版本
253
- - 基本的 XML 转换和检查功能
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cuxml",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "A tool to help use ribbon UI for your WPS Office Client JS add-in project.",
5
5
  "keywords": [
6
6
  "wps office",
package/src/cli.js CHANGED
@@ -33,15 +33,20 @@ program
33
33
  .option('-i, --input <file>', '输入的 XML 文件路径', './ribbon.xml')
34
34
  .option('-o, --output <file>', '输出的 JS 文件路径')
35
35
  .option('-w, --watch', '监视文件变化并自动转换')
36
+ .option('--overwrite', '覆盖输出文件(非 watch 模式)')
36
37
  .action((options) => {
37
38
  const outputPath = options.output || getDefaultOutputPath(options.input);
38
39
  try {
40
+ const watchOptions = options.watch ? { overwrite: true } : { overwrite: options.overwrite };
41
+
39
42
  if (options.watch) {
40
43
  console.log('🚀 启动监视模式...\n');
41
- CUXMLAPI.watch(options.input, outputPath);
44
+ CUXMLAPI.watch(options.input, outputPath, watchOptions);
42
45
  } else {
43
46
  console.log('🔄 开始转换...\n');
44
- const result = CUXMLAPI.convertSync(options.input, outputPath);
47
+ const result = CUXMLAPI.convertSync(options.input, outputPath, {
48
+ overwrite: options.overwrite
49
+ });
45
50
 
46
51
  if (result.success) {
47
52
  console.log(`✅ ${result.message}`);
@@ -99,12 +104,14 @@ program
99
104
  .argument('<inputFile>', '输入的 XML 文件路径')
100
105
  .argument('[outputFile]', '输出的 JS 文件路径', './ribbon_temp.js')
101
106
  .option('-w, --watch', '监视文件变化并自动转换')
102
- .option('--overwrite', '覆盖输出文件')
107
+ .option('--overwrite', '覆盖输出文件(非 watch 模式)')
103
108
  .action((inputFile, outputFile, options) => {
104
109
  try {
110
+ const watchOptions = options.watch ? { overwrite: true } : { overwrite: options.overwrite };
111
+
105
112
  if (options.watch) {
106
113
  console.log('🚀 启动监视模式...\n');
107
- CUXMLAPI.watch(inputFile, outputFile, { overwrite: options.overwrite });
114
+ CUXMLAPI.watch(inputFile, outputFile, watchOptions);
108
115
  } else {
109
116
  console.log('🔄 开始转换...\n');
110
117
  const result = CUXMLAPI.convertSync(inputFile, outputFile, {
package/src/converter.js CHANGED
@@ -206,16 +206,16 @@ class XMLConverter {
206
206
  }
207
207
  });
208
208
 
209
- // 添加导出语句
209
+ // 添加导出语句(浏览器端使用 export default)
210
210
  const exportStatement = `
211
211
  // 导出所有回调函数(如果不需要导出,可以注释掉以下语句)
212
- module.exports = {
212
+ export default {
213
213
  ${functions.map(func => ` ${func.name},`).join('\n')}
214
214
  };
215
215
  `;
216
216
 
217
217
  // 检查是否已经有导出语句
218
- if (!existingContent.includes('module.exports = {')) {
218
+ if (!existingContent.includes('export default {')) {
219
219
  fs.appendFileSync(outputPath, exportStatement, 'utf-8');
220
220
  }
221
221
  }