Skip to content

parseManifest

解析UniApp manifest.json配置,提取应用ID、名称等信息。

前置依赖

依赖参数

参数名类型说明
deps.existsSyncFileSystem['existsSync']检查文件是否存在
deps.readFileSyncFileSystem['readFileSync']读取文件内容
deps.joinPath['join']路径拼接
deps.parseJSON5Parser['parse']JSON5 解析函数

环境要求

  • json5: JSON5 解析库
bash
npm install json5

函数签名

typescript
function parseManifest(
  projectPath: string,
  deps: ParseManifestDeps
): { success: boolean; manifest?: UniAppManifest; error?: string }

interface UniAppManifest {
  appid: string
  name: string
  description?: string
}

参数

参数名类型必填说明
projectPathstring项目路径
depsParseManifestDeps依赖注入对象

返回值

类型说明
{ success: boolean; manifest?: UniAppManifest; error?: string }解析结果对象

工作原理

  1. 检测项目类型:使用 detectProjectType 检测项目类型并获取 manifest.json 路径
  2. 读取文件:读取 manifest.json 文件内容
  3. 解析JSON5:使用 JSON5 解析器解析文件内容(支持注释和尾随逗号)
  4. 提取配置:提取 appid、name、description 等配置信息
  5. 返回结果:返回解析结果,包含成功状态、manifest对象或错误信息

支持 HBuilderX 和 CLI 工程,自动识别 manifest.json 位置(src目录或根目录)。