1
0
Code Issues Pull Requests Actions Packages Projects Releases Wiki Activity GitHub Gitee
react-native-update-cli/lib/package.js

145 lines
4.3 KiB
JavaScript
Raw Normal View History

2024-08-13 00:32:02 +08:00
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.commands = undefined;
exports.listPackage = listPackage;
exports.choosePackage = choosePackage;
var _api = require('./api');
var _utils = require('./utils');
var _app = require('./app');
var _ttyTable = require('tty-table');
var _ttyTable2 = _interopRequireDefault(_ttyTable);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
async function listPackage(appId) {
const { data } = await (0, _api.get)(`/app/${appId}/package/list?limit=1000`);
const header = [{ value: '原生包 Id' }, { value: '原生版本' }];
const rows = [];
for (const pkg of data) {
const { version } = pkg;
let versionInfo = '';
if (version) {
versionInfo = `, 已绑定:${version.name} (${version.id})`;
} else {
// versionInfo = ' (newest)';
}
let output = pkg.name;
if (pkg.status === 'paused') {
output += '(已暂停)';
}
if (pkg.status === 'expired') {
output += '(已过期)';
}
output += versionInfo;
rows.push([pkg.id, output]);
}
console.log((0, _ttyTable2.default)(header, rows).render());
console.log(`\n${data.length} 个包`);
return data;
}
async function choosePackage(appId) {
const list = await listPackage(appId);
while (true) {
const id = await (0, _utils.question)('输入原生包 id:');
const app = list.find(v => v.id === (id | 0));
if (app) {
return app;
}
}
}
const commands = exports.commands = {
uploadIpa: async function ({ args }) {
const fn = args[0];
if (!fn || !fn.endsWith('.ipa')) {
throw new Error('使用方法: pushy uploadIpa ipa后缀文件');
}
const {
versionName,
buildTime,
appId: appIdInPkg,
appKey: appKeyInPkg
} = await (0, _utils.getIpaInfo)(fn);
const { appId, appKey } = await (0, _app.getSelectedApp)('ios');
if (appIdInPkg && appIdInPkg != appId) {
throw new Error(`appId不匹配当前ipa: ${appIdInPkg}, 当前update.json: ${appId}`);
}
if (appKeyInPkg && appKeyInPkg !== appKey) {
throw new Error(`appKey不匹配当前ipa: ${appKeyInPkg}, 当前update.json: ${appKey}`);
}
const { hash } = await (0, _api.uploadFile)(fn);
const { id } = await (0, _api.post)(`/app/${appId}/package/create`, {
name: versionName,
hash,
buildTime
});
(0, _utils.saveToLocal)(fn, `${appId}/package/${id}.ipa`);
console.log(`已成功上传ipa原生包id: ${id}, version: ${versionName}, buildTime: ${buildTime}`);
},
uploadApk: async function ({ args }) {
const fn = args[0];
if (!fn || !fn.endsWith('.apk')) {
throw new Error('使用方法: pushy uploadApk apk后缀文件');
}
const {
versionName,
buildTime,
appId: appIdInPkg,
appKey: appKeyInPkg
} = await (0, _utils.getApkInfo)(fn);
const { appId, appKey } = await (0, _app.getSelectedApp)('android');
if (appIdInPkg && appIdInPkg != appId) {
throw new Error(`appId不匹配当前apk: ${appIdInPkg}, 当前update.json: ${appId}`);
}
if (appKeyInPkg && appKeyInPkg !== appKey) {
throw new Error(`appKey不匹配当前apk: ${appKeyInPkg}, 当前update.json: ${appKey}`);
}
const { hash } = await (0, _api.uploadFile)(fn);
const { id } = await (0, _api.post)(`/app/${appId}/package/create`, {
name: versionName,
hash,
buildTime
});
(0, _utils.saveToLocal)(fn, `${appId}/package/${id}.apk`);
console.log(`已成功上传apk原生包id: ${id}, version: ${versionName}, buildTime: ${buildTime}`);
},
parseIpa: async function ({ args }) {
const fn = args[0];
if (!fn || !fn.endsWith('.ipa')) {
throw new Error('使用方法: pushy parseIpa ipa后缀文件');
}
console.log((await (0, _utils.getIpaInfo)(fn)));
},
parseApk: async function ({ args }) {
const fn = args[0];
if (!fn || !fn.endsWith('.apk')) {
throw new Error('使用方法: pushy parseApk apk后缀文件');
}
console.log((await (0, _utils.getApkInfo)(fn)));
},
packages: async function ({ options }) {
const platform = (0, _app.checkPlatform)(options.platform || (await (0, _utils.question)('平台(ios/android):')));
const { appId } = await (0, _app.getSelectedApp)(platform);
await listPackage(appId);
}
};