@stampgis/webrtc 1.0.0 → 1.0.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 +114 -161
- package/assets/config/stamp_core_config.js +1 -26
- package/dist/index.cjs +16058 -6258
- package/dist/index.d.mts +8491 -1254
- package/dist/index.d.ts +8491 -1254
- package/dist/index.js +15826 -5989
- package/dist-cli/cli.js +220 -0
- package/package.json +29 -5
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist-cli/cli.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* StampAutoAPI CLI 入口
|
|
5
|
+
*
|
|
6
|
+
* 用法:
|
|
7
|
+
* stamp-autoapi <input-file> [output-dir] [--pkg <packageName>] [--no-stamputil]
|
|
8
|
+
*
|
|
9
|
+
* 示例:
|
|
10
|
+
* stamp-autoapi ./src/StampUtil.ts ./output
|
|
11
|
+
* stamp-autoapi ./src/StampUtil.ts ./output --pkg @stampgis/webrtc
|
|
12
|
+
* npx tsx cli/cli.ts src/StampUtil.ts ./output
|
|
13
|
+
*/
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
+
}) : function(o, v) {
|
|
28
|
+
o["default"] = v;
|
|
29
|
+
});
|
|
30
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
+
var ownKeys = function(o) {
|
|
32
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
+
var ar = [];
|
|
34
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
return ownKeys(o);
|
|
38
|
+
};
|
|
39
|
+
return function (mod) {
|
|
40
|
+
if (mod && mod.__esModule) return mod;
|
|
41
|
+
var result = {};
|
|
42
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
const parser_1 = require("./parser");
|
|
49
|
+
const json_generator_1 = require("./json-generator");
|
|
50
|
+
const fs = __importStar(require("fs"));
|
|
51
|
+
const path = __importStar(require("path"));
|
|
52
|
+
/** 默认配置 */
|
|
53
|
+
const DEFAULT_PACKAGE_NAME = '@stampgis/webrtc';
|
|
54
|
+
const DEFAULT_OUTPUT_DIR = './output';
|
|
55
|
+
/**
|
|
56
|
+
* 解析命令行参数
|
|
57
|
+
*
|
|
58
|
+
* 支持的位置参数:
|
|
59
|
+
* argv[0] = 输入文件路径
|
|
60
|
+
* argv[1] = 输出目录(可选)
|
|
61
|
+
*
|
|
62
|
+
* 支持的选项参数:
|
|
63
|
+
* --pkg <name> 指定包名(默认 @stampgis/webrtc)
|
|
64
|
+
* --no-stamputil 非 StampUtil 模式(使用具名导入)
|
|
65
|
+
* --help, -h 显示帮助
|
|
66
|
+
*/
|
|
67
|
+
function parseArgs(argv) {
|
|
68
|
+
const args = argv.slice(2); // 跳过 node 和脚本路径
|
|
69
|
+
let input = '';
|
|
70
|
+
let outputDir = DEFAULT_OUTPUT_DIR;
|
|
71
|
+
let packageName = DEFAULT_PACKAGE_NAME;
|
|
72
|
+
let isStampUtil = true;
|
|
73
|
+
for (let i = 0; i < args.length; i++) {
|
|
74
|
+
const arg = args[i];
|
|
75
|
+
switch (arg) {
|
|
76
|
+
case '--help':
|
|
77
|
+
case '-h':
|
|
78
|
+
printHelp();
|
|
79
|
+
process.exit(0);
|
|
80
|
+
break;
|
|
81
|
+
case '--pkg':
|
|
82
|
+
packageName = args[++i] ?? DEFAULT_PACKAGE_NAME;
|
|
83
|
+
break;
|
|
84
|
+
case '--no-stamputil':
|
|
85
|
+
isStampUtil = false;
|
|
86
|
+
break;
|
|
87
|
+
case '--out':
|
|
88
|
+
outputDir = args[++i] ?? DEFAULT_OUTPUT_DIR;
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
if (!input) {
|
|
92
|
+
input = arg;
|
|
93
|
+
}
|
|
94
|
+
else if (outputDir === DEFAULT_OUTPUT_DIR) {
|
|
95
|
+
outputDir = arg;
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!input) {
|
|
101
|
+
console.error('错误:缺少输入文件路径');
|
|
102
|
+
printHelp();
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
input: path.resolve(input),
|
|
107
|
+
outputDir: path.resolve(outputDir),
|
|
108
|
+
packageName,
|
|
109
|
+
isStampUtil,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** 打印帮助信息 */
|
|
113
|
+
function printHelp() {
|
|
114
|
+
console.log(`
|
|
115
|
+
StampAutoAPI - StampGIS SDK 接口自动化文档生成工具
|
|
116
|
+
|
|
117
|
+
用法:
|
|
118
|
+
stamp-autoapi <input-file> [output-dir] [options]
|
|
119
|
+
|
|
120
|
+
参数:
|
|
121
|
+
input-file 输入的 TypeScript 文件路径(如 src/StampUtil.ts)
|
|
122
|
+
output-dir 输出目录(默认:./output)
|
|
123
|
+
|
|
124
|
+
选项:
|
|
125
|
+
--pkg <name> 指定包名(默认:@stampgis/webrtc)
|
|
126
|
+
--no-stamputil 非 StampUtil 模式,使用具名导入而非默认导入
|
|
127
|
+
--out <dir> 指定输出目录(与位置参数二选一)
|
|
128
|
+
-h, --help 显示帮助信息
|
|
129
|
+
|
|
130
|
+
示例:
|
|
131
|
+
stamp-autoapi ./src/StampUtil.ts ./output
|
|
132
|
+
stamp-autoapi ./src/StampUtil.ts ./output --pkg @stampgis/webrtc
|
|
133
|
+
npx tsx cli/cli.ts src/StampUtil.ts ./output
|
|
134
|
+
`);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 主函数
|
|
138
|
+
*/
|
|
139
|
+
function main() {
|
|
140
|
+
const args = parseArgs(process.argv);
|
|
141
|
+
// 验证输入文件存在
|
|
142
|
+
if (!fs.existsSync(args.input)) {
|
|
143
|
+
console.error(`错误:输入文件不存在 - ${args.input}`);
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
// 确保输出目录存在
|
|
147
|
+
if (!fs.existsSync(args.outputDir)) {
|
|
148
|
+
fs.mkdirSync(args.outputDir, { recursive: true });
|
|
149
|
+
}
|
|
150
|
+
console.log('━'.repeat(60));
|
|
151
|
+
console.log(' StampAutoAPI - 接口文档自动生成工具');
|
|
152
|
+
console.log('━'.repeat(60));
|
|
153
|
+
console.log(` 输入文件:${args.input}`);
|
|
154
|
+
console.log(` 输出目录:${args.outputDir}`);
|
|
155
|
+
console.log(` 包名: ${args.packageName}`);
|
|
156
|
+
console.log(` 模式: ${args.isStampUtil ? 'StampUtil(默认导入)' : '具名导入'}`);
|
|
157
|
+
console.log('━'.repeat(60));
|
|
158
|
+
console.log('');
|
|
159
|
+
try {
|
|
160
|
+
// Step 1: 解析 TypeScript 文件
|
|
161
|
+
console.log('▶ 正在解析 TypeScript 文件...');
|
|
162
|
+
const methods = (0, parser_1.parseStampUtil)(args.input, args.packageName, args.isStampUtil);
|
|
163
|
+
console.log(` ✓ 共解析到 ${methods.length} 个接口方法`);
|
|
164
|
+
if (methods.length === 0) {
|
|
165
|
+
console.warn(' ⚠ 未解析到任何方法,请检查输入文件是否包含类定义');
|
|
166
|
+
process.exit(0);
|
|
167
|
+
}
|
|
168
|
+
// 统计分类
|
|
169
|
+
const categories = new Set(methods.map((m) => m.category));
|
|
170
|
+
console.log(` ✓ 共 ${categories.size} 个分类`);
|
|
171
|
+
// 统计有描述的方法数
|
|
172
|
+
const withDesc = methods.filter((m) => m.desc && m.desc !== `${m.name} 方法`).length;
|
|
173
|
+
console.log(` ✓ ${withDesc}/${methods.length} 个方法有描述`);
|
|
174
|
+
console.log('');
|
|
175
|
+
// Step 2: 生成 JSON 文件
|
|
176
|
+
console.log('▶ 正在生成 JSON 文件...');
|
|
177
|
+
const jsonPath = (0, json_generator_1.generateJson)(methods, args.outputDir);
|
|
178
|
+
// console.log(` ✓ 已生成:${jsonPath}`);
|
|
179
|
+
// 同时生成的 JS 文件
|
|
180
|
+
const jsPath = path.join(args.outputDir, 'jsSdkSchemaStore.js');
|
|
181
|
+
console.log(` ✓ 已生成:${jsPath}`);
|
|
182
|
+
console.log('');
|
|
183
|
+
// // Step 3: 生成 Markdown 文档
|
|
184
|
+
// console.log('▶ 正在生成 Markdown 文档...');
|
|
185
|
+
// const mdPath = generateMarkdown(methods, args.outputDir);
|
|
186
|
+
// console.log(` ✓ 已生成:${mdPath}`);
|
|
187
|
+
// console.log('');
|
|
188
|
+
// 完成
|
|
189
|
+
console.log('━'.repeat(60));
|
|
190
|
+
console.log(' ✅ MCPJSON文件生成完成!');
|
|
191
|
+
console.log('━'.repeat(60));
|
|
192
|
+
console.log('');
|
|
193
|
+
console.log(' 生成文件:');
|
|
194
|
+
// console.log(` 1. ${jsonPath} (JSON 接口描述)`);
|
|
195
|
+
console.log(` 1. ${jsPath} (JS 可直接引用)`);
|
|
196
|
+
// console.log(` 3. ${mdPath} (Markdown 文档)`);
|
|
197
|
+
console.log('');
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
console.error('');
|
|
201
|
+
console.error('━'.repeat(60));
|
|
202
|
+
console.error(' ❌ 生成失败!');
|
|
203
|
+
console.error('━'.repeat(60));
|
|
204
|
+
console.error('');
|
|
205
|
+
if (err instanceof Error) {
|
|
206
|
+
console.error(` 错误信息:${err.message}`);
|
|
207
|
+
if (err.stack) {
|
|
208
|
+
console.error('');
|
|
209
|
+
console.error(' 堆栈信息:');
|
|
210
|
+
console.error(err.stack);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
console.error(` 错误:${String(err)}`);
|
|
215
|
+
}
|
|
216
|
+
console.error('');
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stampgis/webrtc",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "StampGIS
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "StampGIS 地图SDK,封装 StampUtil 接口库与 core 脚本加载逻辑",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"stamp-autoapi": "dist-cli/cli.js"
|
|
10
|
+
},
|
|
8
11
|
"exports": {
|
|
9
12
|
".": {
|
|
10
13
|
"types": "./dist/index.d.ts",
|
|
@@ -19,10 +22,21 @@
|
|
|
19
22
|
"README.md"
|
|
20
23
|
],
|
|
21
24
|
"sideEffects": false,
|
|
25
|
+
"//": {
|
|
26
|
+
"dev": "开发环境,监听文件变化并自动编译",
|
|
27
|
+
"build": "生产环境,编译代码",
|
|
28
|
+
"build:cli": "编译 cli 代码",
|
|
29
|
+
"generate": "生成 jsapi json 文件",
|
|
30
|
+
"docs": "生成 jsapi HTML静态页面",
|
|
31
|
+
"docs:serve": "启动 jsapi HTML静态页面服务"
|
|
32
|
+
},
|
|
22
33
|
"scripts": {
|
|
23
34
|
"dev": "tsup --watch",
|
|
24
35
|
"build": "tsup",
|
|
25
|
-
"
|
|
36
|
+
"build:cli": "tsc -p tsconfig.cli.json",
|
|
37
|
+
"generate": "npm run build:cli && node dist-cli/cli.js src/StampUtil.ts ../StampMCPServer/schemaStore",
|
|
38
|
+
"docs": "jsdoc -c jsdoc.config.json",
|
|
39
|
+
"docs:serve": "jsdoc -c jsdoc.config.json && npx http-server jsapi-docs -p 8080"
|
|
26
40
|
},
|
|
27
41
|
"keywords": [
|
|
28
42
|
"map",
|
|
@@ -37,6 +51,7 @@
|
|
|
37
51
|
"registry": "https://registry.npmjs.org/"
|
|
38
52
|
},
|
|
39
53
|
"dependencies": {
|
|
54
|
+
"axios": "^1.20.0",
|
|
40
55
|
"file-saver": "^2.0.5",
|
|
41
56
|
"jszip": "^3.10.1"
|
|
42
57
|
},
|
|
@@ -45,8 +60,17 @@
|
|
|
45
60
|
"jszip": "^3.10.1"
|
|
46
61
|
},
|
|
47
62
|
"devDependencies": {
|
|
63
|
+
"@babel/core": "^7.29.7",
|
|
64
|
+
"@babel/preset-env": "^7.29.7",
|
|
65
|
+
"@babel/preset-typescript": "^7.29.7",
|
|
48
66
|
"@types/file-saver": "^2.0.7",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
67
|
+
"@types/node": "^20.0.0",
|
|
68
|
+
"jsdoc": "^4.0.5",
|
|
69
|
+
"jsdoc-babel": "^0.5.0",
|
|
70
|
+
"taffydb": "^2.7.3",
|
|
71
|
+
"tsup": "^8.0.0",
|
|
72
|
+
"tsx": "^4.0.0",
|
|
73
|
+
"tui-jsdoc-template": "^1.2.2",
|
|
74
|
+
"typescript": "^5.4.0"
|
|
51
75
|
}
|
|
52
76
|
}
|