1
0
mirror of https://gitcode.com/github-mirrors/react-native-update-cli.git synced 2025-09-16 09:41:38 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Improve parse

This commit is contained in:
sunnylqm
2020-09-15 15:13:52 +08:00
parent 5e69793925
commit 2d5c01e990
2 changed files with 30 additions and 14 deletions

View File

@@ -19,7 +19,9 @@ export async function listPackage(appId) {
const { version } = pkg; const { version } = pkg;
let versionInfo = ''; let versionInfo = '';
if (version) { if (version) {
versionInfo = ` - ${version.id} ${version.hash.slice(0, 8)} ${version.name}`; versionInfo = ` - ${version.id} ${version.hash.slice(0, 8)} ${
version.name
}`;
} else { } else {
versionInfo = ' (newest)'; versionInfo = ' (newest)';
} }
@@ -37,7 +39,7 @@ export async function choosePackage(appId) {
while (true) { while (true) {
const id = await question('Enter Package Id:'); const id = await question('Enter Package Id:');
const app = list.find(v => v.id === (id | 0)); const app = list.find((v) => v.id === (id | 0));
if (app) { if (app) {
return app; return app;
} }
@@ -45,7 +47,7 @@ export async function choosePackage(appId) {
} }
export const commands = { export const commands = {
uploadIpa: async function({ args }) { uploadIpa: async function ({ args }) {
const fn = args[0]; const fn = args[0];
if (!fn || !fn.endsWith('.ipa')) { if (!fn || !fn.endsWith('.ipa')) {
throw new Error('Usage: pushy uploadIpa <ipaFile>'); throw new Error('Usage: pushy uploadIpa <ipaFile>');
@@ -63,7 +65,7 @@ export const commands = {
saveToLocal(fn, `${appId}/package/${id}.ipa`); saveToLocal(fn, `${appId}/package/${id}.ipa`);
console.log(`Ipa uploaded: ${id}`); console.log(`Ipa uploaded: ${id}`);
}, },
uploadApk: async function({ args }) { uploadApk: async function ({ args }) {
const fn = args[0]; const fn = args[0];
if (!fn || !fn.endsWith('.apk')) { if (!fn || !fn.endsWith('.apk')) {
throw new Error('Usage: pushy uploadApk <apkFile>'); throw new Error('Usage: pushy uploadApk <apkFile>');
@@ -81,24 +83,24 @@ export const commands = {
saveToLocal(fn, `${appId}/package/${id}.apk`); saveToLocal(fn, `${appId}/package/${id}.apk`);
console.log(`Apk uploaded: ${id}`); console.log(`Apk uploaded: ${id}`);
}, },
parseIpa: async function({ args }) { parseIpa: async function ({ args }) {
const fn = args[0]; const fn = args[0];
if (!fn || !fn.endsWith('.ipa')) { if (!fn || !fn.endsWith('.ipa')) {
throw new Error('Usage: pushy parseIpa <ipaFile>'); throw new Error('Usage: pushy parseIpa <ipaFile>');
} }
const { versionName, buildTime } = await getIpaInfo(fn); console.log(await getIpaInfo(fn));
console.log(`版本号: ${versionName}, 编译时间戳: ${buildTime}`);
}, },
parseApk: async function({ args }) { parseApk: async function ({ args }) {
const fn = args[0]; const fn = args[0];
if (!fn || !fn.endsWith('.apk')) { if (!fn || !fn.endsWith('.apk')) {
throw new Error('Usage: pushy parseApk <apkFile>'); throw new Error('Usage: pushy parseApk <apkFile>');
} }
const { versionName, buildTime } = await getApkInfo(fn); console.log(await getApkInfo(fn));
console.log(`版本号: ${versionName}, 编译时间戳: ${buildTime}`);
}, },
packages: async function({ options }) { packages: async function ({ options }) {
const platform = checkPlatform(options.platform || (await question('Platform(ios/android):'))); const platform = checkPlatform(
options.platform || (await question('Platform(ios/android):')),
);
const { appId } = await getSelectedApp(platform); const { appId } = await getSelectedApp(platform);
await listPackage(appId); await listPackage(appId);
}, },

View File

@@ -65,6 +65,13 @@ export async function getApkInfo(fn) {
'找不到bundle文件。请确保此apk为release版本且bundle文件名为默认的index.android.bundle', '找不到bundle文件。请确保此apk为release版本且bundle文件名为默认的index.android.bundle',
); );
} }
const updateJsonFile = await appInfoParser.parser.getEntry(
/res\/raw\/update.json/,
);
if (!updateJsonFile) {
throw new Error('找不到update.json文件');
}
const appCredential = JSON.parse(updateJsonFile.toString()).android;
const { versionName, application } = await appInfoParser.parse(); const { versionName, application } = await appInfoParser.parse();
let buildTime = 0; let buildTime = 0;
if (Array.isArray(application.metaData)) { if (Array.isArray(application.metaData)) {
@@ -79,7 +86,7 @@ export async function getApkInfo(fn) {
'无法获取此包的编译时间戳。请更新react-native-update到最新版本后重新打包上传。', '无法获取此包的编译时间戳。请更新react-native-update到最新版本后重新打包上传。',
); );
} }
return { versionName, buildTime }; return { versionName, buildTime, ...appCredential };
} }
export async function getIpaInfo(fn) { export async function getIpaInfo(fn) {
@@ -92,6 +99,13 @@ export async function getIpaInfo(fn) {
'找不到bundle文件。请确保此ipa为release版本且bundle文件名为默认的main.jsbundle', '找不到bundle文件。请确保此ipa为release版本且bundle文件名为默认的main.jsbundle',
); );
} }
const updateJsonFile = await appInfoParser.parser.getEntry(
/payload\/.+?\.app\/assets\/update.json/,
);
if (!updateJsonFile) {
throw new Error('找不到update.json文件');
}
const appCredential = JSON.parse(updateJsonFile.toString()).ios;
const { const {
CFBundleShortVersionString: versionName, CFBundleShortVersionString: versionName,
} = await appInfoParser.parse(); } = await appInfoParser.parse();
@@ -110,7 +124,7 @@ export async function getIpaInfo(fn) {
); );
} }
const buildTime = buildTimeTxtBuffer.toString().replace('\n', ''); const buildTime = buildTimeTxtBuffer.toString().replace('\n', '');
return { versionName, buildTime }; return { versionName, buildTime, ...appCredential };
} }
const localDir = path.resolve(os.homedir(), '.pushy'); const localDir = path.resolve(os.homedir(), '.pushy');