1# 工具使用说明 2 3## 工具包结构 4 5``` 6apiCollector-x.x.x.zip 7|- libs // ES库 8|- api-collector.js // 执行脚本 9``` 10 11查看工具命令行参数,**api-collector.js 需要指定路径,以下例子命令行默认在解压目录下执行** 12 13```shell 14node api-collector.js -h 15``` 16 17```shell 18Usage: api-collector [options] 19 20collect api from app's source code. 21 22Options: 23 -V, --version output the version number 24 --app <string> app root directory 25 --appDir <string> a path that contains multiple applications 26 --sdk <string> sdk path, need to specify the ets directory, e.g sdk-root/version/ets 27 --sdkRoot <string> sdk root path 28 --output <string> the path to output the report 29 --format <json,excel> format of the output report 30 --scanTest scan ohosTest 31 --debug output debug logs 32 -h, --help display help for command 33``` 34 35工具输出 app_api.xlsx 或者 collectedApi.json,具体格式和路径取决于 --format, --output 参数 36 37## 扫描单个应用 38 39```shell 40node api-collector.js --app 工程根目录 41``` 42 43上述命令的行为: 44 451. 解析 local.properties 获取 sdk 根目录 462. 解析 build-profile.json5 获取 sdk 版本 473. 拼接完整 sdk 路径,指向到 sdk 目录下的 ets 目录 484. 扫描 build-profile.json5 中 modules 下的代码目录 49 50上述命令执行时可能存在 local.properties 文件不存在,导致 sdk 根目录无法获取,此时需要使用 --sdkRoot 指定 sdk 根目录 51 52```shell 53node api-collector.js --app 工程根目录 --sdkRoot sdk根目录 54``` 55 56上述命令执行时还可能存在 build-profile.json5 文件找不到,或者无法解析到 sdk 的版本号,此时需要 --sdk 指定 sdk 目录中 ets 目录的路径 57 58```shell 59node api-collector.js --app 工程根目录 --sdk sdk根目录/9/ets 60``` 61 62## 扫描目录下的多个应用 63 64```shell 65node api-collector.js --appDir 文件夹路径 66``` 67 68上述命令的行为: 69 701. 搜集目录下所有工程路径 712. 遍历所有工程路径,按单个应用的方式进行扫描 72 73因此,上述命令也可能会遇到 sdk 路径无法识别的问题, 可以通过 --sdkRoot 指定 sdk 根目录 74 75```shell 76node api-collector.js --appDir 文件夹路径 --sdkRoot sdk根目录 77``` 78 79扫描多个应用不支持 --sdk 参数,因为 --sdk 参数限定了 sdk 的版本号,而每个应用的版本号并不一致。批量扫描应用时,sdk 的版本号统一从 build-profile.json5 中 compileSdkVersion 字段获取,若 build-profile.json5 文件不存在或 compileSdkVersion 没有,则跳过此工程。 80 81## 令参数 82 83--output 指定扫描报告的输出路径,不指定则默认输出在应用工程根目录 84 85--format 指定扫描报告的格式, 支持 excel, json,默认为 excel 表格 86 87--scanTest 扫描 ohosTest 目录下的代码 88 89--debug 打开debug日志