1.0.7 • Published 9 months ago

harmony-app-parser v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

harmony-app-parser

  1. 解析鸿蒙安装包.app/.hap/.hsp/.har文件的pack.info/module.json的信息
  2. 支持 browser 和 node 环境
  3. 支持读取包中任何文本文件内容,支持入参指定文件名

安装

    npm i harmony-app-parser

API

宝子们注意下啊, 浏览器和node环境入参类型有差异,个人觉得更实用一点

浏览器API

 harmonyParser(file:File, fileList?: Array<FileInfo>):Promise

nodeAPI

harmonyParser(filePath:String, fileList?: Array<FileInfo>):Promise

公共API

isHarmonyAPP(fileName: String):Boolean  // 文件名是否以.app结尾

类型

FileList (指定读取包中的哪些文本文件的内容,默认读取pack.info 和 module.json)

    interface FileInfo {key: string, fileName: string}

    // 默认设置的入参,不可覆盖且不可重名
    [
        {
            key: 'packInfo',
            fileName: 'pack.info',
        },
        {
            key: 'moduleInfo',
            fileName: 'module.json'
        }
    ]

使用

浏览器

  • 注入widnow
<body>
    <input type="file" name="file" id="file">
    <script src="./node_modules/harmony-app-parser/dist/harmonyParser-browser.js"></script>
    <script>
        let inputFile = document.querySelector('input');
        inputFile.onchange = function () {
            harmonyParser(this.files[0]).then(res => {
                console.log('res:', res);
            }).catch(err => {
                console.log('err:', err)
            })
        }
    </script>
</body>
  • esmodule
<body>
    <input type="file" name="file" id="file">
    <script type="module">
        import { harmonyParser } from '../dist/harmonyParser-esm.js'
        let inputFile = document.querySelector('input');
        inputFile.onchange = function () {
            harmonyParser(this.files[0]).then(res => {
                console.log('res:', res);
            }).catch(err => {
                console.log('err:', err)
            })
        }
    </script>
</body>
  • 或者
import { harmonyParser } from 'harmony-app-parser';

function parserApp(e){
  let file = document.querySelector('input').files[0];
  harmonyParser(file, [{ fileName: 'map.json', key: 'mapInfo'}]).then(res=> {
    console.log('res:', res)
  }).catch(err=> {
    console.log('err:', err);
  })
}

nodejs

const { isHarmonyApp, harmonyParser } = require('harmony-app-parser')
const path = require('path');

harmonyParser(path.join(__dirname, './module-router-harmony-default-signed.app')).then(res => {
    console.log('res:', res)
}).catch(err => {
    console.log('err:', err)
})

联系方式:

邮箱: 724228803@qq.com

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago