From ae628b310ae1e7379154b04a4c346441bc245b6f Mon Sep 17 00:00:00 2001 From: tdzl2003 Date: Sat, 2 Apr 2016 20:55:03 +0800 Subject: [PATCH] get version from apk/ipa file. --- local-cli/src/utils.js | 18 +++++++++++++++++- package.json | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/local-cli/src/utils.js b/local-cli/src/utils.js index 5ab9562..dc43bcf 100644 --- a/local-cli/src/utils.js +++ b/local-cli/src/utils.js @@ -4,6 +4,8 @@ import * as path from 'path'; import * as fs from 'fs'; +import ApkReader from 'node-apk-parser'; +import ipaMetadata from 'ipa-metadata'; var read = require('read'); @@ -40,4 +42,18 @@ export function getRNVersion() { major: match[1] | 0, minor: match[2] | 0, }; -} \ No newline at end of file +} + +export function getApkVersion(fn) { + const reader = ApkReader.readFile(fn); + const manifest = reader.readManifestSync(); + return Promise.resolve(manifest.versionName); +} + +export function getIPAVersion(fn) { + return new Promise((resolve, reject) => { + ipaMetadata(fn, (err, data) => { + err ? reject(err) : resolve(data); + }); + }); +} diff --git a/package.json b/package.json index ceaa677..b20e3be 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,10 @@ "dependencies": { "cli-arguments": "^0.2.1", "fs-promise": "^0.4.1", + "ipa-metadata": "^1.4.0", "isomorphic-fetch": "^2.2.1", "mkdir-recursive": "^0.2.1", + "node-apk-parser": "^0.2.3", "node-bsdiff": "^0.1.2", "read": "^1.0.7", "yauzl": "^2.4.1",