mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-16 09:41:38 +08:00
Improve parse
This commit is contained in:
@@ -19,7 +19,9 @@ export async function listPackage(appId) {
|
||||
const { version } = pkg;
|
||||
let versionInfo = '';
|
||||
if (version) {
|
||||
versionInfo = ` - ${version.id} ${version.hash.slice(0, 8)} ${version.name}`;
|
||||
versionInfo = ` - ${version.id} ${version.hash.slice(0, 8)} ${
|
||||
version.name
|
||||
}`;
|
||||
} else {
|
||||
versionInfo = ' (newest)';
|
||||
}
|
||||
@@ -37,7 +39,7 @@ export async function choosePackage(appId) {
|
||||
|
||||
while (true) {
|
||||
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) {
|
||||
return app;
|
||||
}
|
||||
@@ -45,7 +47,7 @@ export async function choosePackage(appId) {
|
||||
}
|
||||
|
||||
export const commands = {
|
||||
uploadIpa: async function({ args }) {
|
||||
uploadIpa: async function ({ args }) {
|
||||
const fn = args[0];
|
||||
if (!fn || !fn.endsWith('.ipa')) {
|
||||
throw new Error('Usage: pushy uploadIpa <ipaFile>');
|
||||
@@ -63,7 +65,7 @@ export const commands = {
|
||||
saveToLocal(fn, `${appId}/package/${id}.ipa`);
|
||||
console.log(`Ipa uploaded: ${id}`);
|
||||
},
|
||||
uploadApk: async function({ args }) {
|
||||
uploadApk: async function ({ args }) {
|
||||
const fn = args[0];
|
||||
if (!fn || !fn.endsWith('.apk')) {
|
||||
throw new Error('Usage: pushy uploadApk <apkFile>');
|
||||
@@ -81,24 +83,24 @@ export const commands = {
|
||||
saveToLocal(fn, `${appId}/package/${id}.apk`);
|
||||
console.log(`Apk uploaded: ${id}`);
|
||||
},
|
||||
parseIpa: async function({ args }) {
|
||||
parseIpa: async function ({ args }) {
|
||||
const fn = args[0];
|
||||
if (!fn || !fn.endsWith('.ipa')) {
|
||||
throw new Error('Usage: pushy parseIpa <ipaFile>');
|
||||
}
|
||||
const { versionName, buildTime } = await getIpaInfo(fn);
|
||||
console.log(`版本号: ${versionName}, 编译时间戳: ${buildTime}`);
|
||||
console.log(await getIpaInfo(fn));
|
||||
},
|
||||
parseApk: async function({ args }) {
|
||||
parseApk: async function ({ args }) {
|
||||
const fn = args[0];
|
||||
if (!fn || !fn.endsWith('.apk')) {
|
||||
throw new Error('Usage: pushy parseApk <apkFile>');
|
||||
}
|
||||
const { versionName, buildTime } = await getApkInfo(fn);
|
||||
console.log(`版本号: ${versionName}, 编译时间戳: ${buildTime}`);
|
||||
console.log(await getApkInfo(fn));
|
||||
},
|
||||
packages: async function({ options }) {
|
||||
const platform = checkPlatform(options.platform || (await question('Platform(ios/android):')));
|
||||
packages: async function ({ options }) {
|
||||
const platform = checkPlatform(
|
||||
options.platform || (await question('Platform(ios/android):')),
|
||||
);
|
||||
const { appId } = await getSelectedApp(platform);
|
||||
await listPackage(appId);
|
||||
},
|
||||
|
@@ -65,6 +65,13 @@ export async function getApkInfo(fn) {
|
||||
'找不到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();
|
||||
let buildTime = 0;
|
||||
if (Array.isArray(application.metaData)) {
|
||||
@@ -79,7 +86,7 @@ export async function getApkInfo(fn) {
|
||||
'无法获取此包的编译时间戳。请更新react-native-update到最新版本后重新打包上传。',
|
||||
);
|
||||
}
|
||||
return { versionName, buildTime };
|
||||
return { versionName, buildTime, ...appCredential };
|
||||
}
|
||||
|
||||
export async function getIpaInfo(fn) {
|
||||
@@ -92,6 +99,13 @@ export async function getIpaInfo(fn) {
|
||||
'找不到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 {
|
||||
CFBundleShortVersionString: versionName,
|
||||
} = await appInfoParser.parse();
|
||||
@@ -110,7 +124,7 @@ export async function getIpaInfo(fn) {
|
||||
);
|
||||
}
|
||||
const buildTime = buildTimeTxtBuffer.toString().replace('\n', '');
|
||||
return { versionName, buildTime };
|
||||
return { versionName, buildTime, ...appCredential };
|
||||
}
|
||||
|
||||
const localDir = path.resolve(os.homedir(), '.pushy');
|
||||
|
Reference in New Issue
Block a user