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

Compare commits

..

23 Commits

Author SHA1 Message Date
sunnylqm
32d7ed9b00 v1.5.0 2021-09-01 14:55:09 +08:00
sunnylqm
6f3d45c3f2 Add acc option 2021-09-01 14:54:17 +08:00
sunnylqm
25cb724921 v1.4.2 2021-06-23 10:05:55 +08:00
sunnylqm
a7b79a30e8 Print server error 2021-06-23 10:05:29 +08:00
sunnylqm
11799dd0c1 v1.4.1 2021-04-11 23:29:56 +08:00
sunnylqm
2ab0cad7e5 Detect hermes first 2021-04-11 23:29:44 +08:00
sunnylqm
ec8d6a767b v1.4.0 2021-04-11 23:26:59 +08:00
sunnylqm
fa8290fcbf Re-enable gradle check for hermes 2021-04-11 23:26:43 +08:00
sunnylqm
46d308c7c2 v1.4.0-beta1 2021-04-11 18:11:24 +08:00
sunnylqm
9e721e1858 try require diff separately 2021-04-11 18:11:08 +08:00
sunnylqm
c30454976c v1.4.0-beta0 2021-04-08 16:07:10 +08:00
sunnylqm
3d73b95140 Add hdiff 2021-04-07 22:09:48 +08:00
sunnylqm
32cafd92bf v1.3.2 2021-03-05 12:27:53 +08:00
sunnylqm
ea10cd7828 Show current filesize 2021-03-05 12:27:38 +08:00
sunnylqm
574a52b126 v1.3.1 2021-01-21 17:46:16 +08:00
sunnylqm
c00a7a72fe Disable crunchPngs check 2021-01-21 17:45:15 +08:00
sunnylqm
0e8e3aa420 v1.3.0 2021-01-20 23:30:26 +08:00
sunnylqm
7426e93647 Update gitignore 2021-01-20 23:30:04 +08:00
sunnylqm
b6fb2e7d2a Check does appId/appKey match 2021-01-20 23:29:53 +08:00
sunnylqm
7f1dcbb571 Use table for listApp 2021-01-20 23:29:31 +08:00
sunnylqm
59fad93832 Change local build foler name 2021-01-11 14:06:14 +08:00
sunnylqm
3db4f803e2 v1.2.3 2021-01-05 21:54:04 +08:00
sunnylqm
56d44b8c85 Update defaultEndpoint 2021-01-05 21:53:46 +08:00
8 changed files with 252 additions and 100 deletions

1
.gitignore vendored
View File

@@ -104,3 +104,4 @@ dist
.tern-port
lib/
.DS_Store

View File

@@ -106,11 +106,11 @@
"hasValue": true
},
"intermediaDir": {
"default": "build/intermedia/${platform}",
"default": ".pushy/intermedia/${platform}",
"hasValue": true
},
"output": {
"default": "build/output/${platform}.${time}.ppk",
"default": ".pushy/output/${platform}.${time}.ppk",
"hasValue": true
},
"verbose": {}
@@ -123,7 +123,7 @@
"description": "Create diff patch",
"options": {
"output": {
"default": "build/output/diff",
"default": ".pushy/output/diff",
"hasValue": true
}
}
@@ -132,7 +132,7 @@
"description": "Create diff patch from a Android package(.apk)",
"options": {
"output": {
"default": "build/output/diff-${time}.apk-patch",
"default": ".pushy/output/diff-${time}.apk-patch",
"hasValue": true
}
}
@@ -141,7 +141,34 @@
"description": "Create diff patch from a iOS package(.ipa)",
"options": {
"output": {
"default": "build/output/diff-${time}.ipa-patch",
"default": ".pushy/output/diff-${time}.ipa-patch",
"hasValue": true
}
}
},
"hdiff": {
"description": "Create hdiff patch",
"options": {
"output": {
"default": ".pushy/output/hdiff",
"hasValue": true
}
}
},
"hdiffFromApk": {
"description": "Create hdiff patch from a Android package(.apk)",
"options": {
"output": {
"default": ".pushy/output/hdiff-${time}.apk-patch",
"hasValue": true
}
}
},
"hdiffFromIpa": {
"description": "Create hdiff patch from a iOS package(.ipa)",
"options": {
"output": {
"default": ".pushy/output/hdiff-${time}.ipa-patch",
"hasValue": true
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update-cli",
"version": "1.2.2",
"version": "1.5.0",
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
"main": "index.js",
"bin": {

View File

@@ -3,7 +3,8 @@
*/
const fetch = require('node-fetch');
let host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn/api';
const defaultEndpoint = 'http://u.reactnative.cn/api';
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
const fs = require('fs');
import request from 'request';
import ProgressBar from 'progress';
@@ -21,7 +22,7 @@ let savedSession = undefined;
const userAgent = `react-native-update-cli/${packageJson.version}`;
exports.loadSession = async function() {
exports.loadSession = async function () {
if (fs.existsSync('.update')) {
try {
exports.replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
@@ -35,15 +36,15 @@ exports.loadSession = async function() {
}
};
exports.getSession = function() {
exports.getSession = function () {
return session;
};
exports.replaceSession = function(newSession) {
exports.replaceSession = function (newSession) {
session = newSession;
};
exports.saveSession = function() {
exports.saveSession = function () {
// Only save on change.
if (session !== savedSession) {
const current = session;
@@ -53,18 +54,25 @@ exports.saveSession = function() {
}
};
exports.closeSession = function() {
exports.closeSession = function () {
if (fs.existsSync('.update')) {
fs.unlinkSync('.update');
savedSession = undefined;
}
session = undefined;
host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn/api';
host = process.env.PUSHY_REGISTRY || defaultEndpoint;
};
async function query(url, options) {
const resp = await fetch(url, options);
const json = await resp.json();
const text = await resp.text();
let json;
try {
json = JSON.parse(text);
} catch (e) {
throw new Error(`Server error: ${text}`);
}
if (resp.status !== 200) {
throw Object.assign(new Error(json.message || json.error), {
status: resp.status,
@@ -74,7 +82,7 @@ async function query(url, options) {
}
function queryWithoutBody(method) {
return function(api) {
return function (api) {
return query(host + api, {
method,
headers: {
@@ -86,7 +94,7 @@ function queryWithoutBody(method) {
}
function queryWithBody(method) {
return function(api, body) {
return function (api, body) {
return query(host + api, {
method,
headers: {
@@ -106,26 +114,34 @@ exports.doDelete = queryWithBody('DELETE');
async function uploadFile(fn, key) {
const { url, backupUrl, formData, maxSize } = await exports.post('/upload', {
ext: path.extname(fn)
ext: path.extname(fn),
});
let realUrl = url;
if (backupUrl) {
const pingResult = await tcpPing({
address: url.replace('https://', ''),
attempts: 4,
timeout: 1000,
});
// console.log({pingResult});
if (isNaN(pingResult.avg) || pingResult.avg > 150) {
if (global.USE_ACC_OSS) {
realUrl = backupUrl;
} else {
const pingResult = await tcpPing({
address: url.replace('https://', ''),
attempts: 4,
timeout: 1000,
});
// console.log({pingResult});
if (isNaN(pingResult.avg) || pingResult.avg > 150) {
realUrl = backupUrl;
}
}
// console.log({realUrl});
}
const fileSize = fs.statSync(fn).size;
if (maxSize && fileSize > filesizeParser(maxSize)) {
throw new Error(`此文件大小超出上限${maxSize}。您可以考虑升级付费业务以提升此限制。详情请访问:${pricingPageUrl}`)
throw new Error(
`此文件大小${(fileSize / 1048576).toFixed(
1,
)}m, 超出当前额度${maxSize}。您可以考虑升级付费业务以提升此额度。详情请访问:${pricingPageUrl}`,
);
}
const bar = new ProgressBar(' Uploading [:bar] :percent :etas', {
@@ -140,7 +156,7 @@ async function uploadFile(fn, key) {
}
formData.file = fs.createReadStream(fn);
formData.file.on('data', function(data) {
formData.file.on('data', function (data) {
bar.tick(data.length);
});
request.post(

View File

@@ -2,14 +2,11 @@
* Created by tdzl2003 on 2/13/16.
*/
import {question} from './utils';
import { question } from './utils';
import fs from 'fs';
const Table = require('tty-table');
const {
post,
get,
doDelete,
} = require('./api');
const { post, get, doDelete } = require('./api');
const validPlatforms = {
ios: 1,
@@ -20,28 +17,42 @@ export function checkPlatform(platform) {
if (!validPlatforms[platform]) {
throw new Error(`Invalid platform '${platform}'`);
}
return platform
return platform;
}
export function getSelectedApp(platform) {
checkPlatform(platform);
if (!fs.existsSync('update.json')){
throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
if (!fs.existsSync('update.json')) {
throw new Error(
`App not selected. run 'pushy selectApp --platform ${platform}' first!`,
);
}
const updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
if (!updateInfo[platform]) {
throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
throw new Error(
`App not selected. run 'pushy selectApp --platform ${platform}' first!`,
);
}
return updateInfo[platform];
}
export async function listApp(platform){
const {data} = await get('/app/list');
const list = platform?data.filter(v=>v.platform===platform):data;
export async function listApp(platform) {
const { data } = await get('/app/list');
const list = platform ? data.filter((v) => v.platform === platform) : data;
const header = [
{ value: 'App Id' },
{ value: 'App Name' },
{ value: 'Platform' },
];
const rows = [];
for (const app of list) {
console.log(`${app.id}) ${app.name}(${app.platform})`);
rows.push([app.id, app.name, app.platform]);
}
console.log(Table(header, rows).render());
if (platform) {
console.log(`\nTotal ${list.length} ${platform} apps`);
} else {
@@ -55,7 +66,7 @@ export async function chooseApp(platform) {
while (true) {
const id = await question('Enter appId:');
const app = list.find(v=>v.id === (id|0));
const app = list.find((v) => v.id === (id | 0));
if (app) {
return app;
}
@@ -63,19 +74,21 @@ export async function chooseApp(platform) {
}
export const commands = {
createApp: async function ({options}) {
const name = options.name || await question('App Name:');
const {downloadUrl} = options;
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
const {id} = await post('/app/create', {name, platform});
createApp: async function ({ options }) {
const name = options.name || (await question('App Name:'));
const { downloadUrl } = options;
const platform = checkPlatform(
options.platform || (await question('Platform(ios/android):')),
);
const { id } = await post('/app/create', { name, platform });
console.log(`Created app ${id}`);
await this.selectApp({
args: [id],
options: {platform, downloadUrl},
options: { platform, downloadUrl },
});
},
deleteApp: async function ({args, options}) {
const {platform} = options;
deleteApp: async function ({ args, options }) {
const { platform } = options;
const id = args[0] || chooseApp(platform);
if (!id) {
console.log('Canceled');
@@ -83,12 +96,14 @@ export const commands = {
await doDelete(`/app/${id}`);
console.log('Ok.');
},
apps: async function ({options}){
const {platform} = options;
apps: async function ({ options }) {
const { platform } = options;
listApp(platform);
},
selectApp: async function({args, options}) {
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
selectApp: async function ({ args, options }) {
const platform = checkPlatform(
options.platform || (await question('Platform(ios/android):')),
);
const id = args[0] || (await chooseApp(platform)).id;
let updateInfo = {};
@@ -96,15 +111,21 @@ export const commands = {
try {
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
} catch (e) {
console.error('Failed to parse file `update.json`. Try to remove it manually.');
console.error(
'Failed to parse file `update.json`. Try to remove it manually.',
);
throw e;
}
}
const {appKey} = await get(`/app/${id}`);
const { appKey } = await get(`/app/${id}`);
updateInfo[platform] = {
appId: id,
appKey,
};
fs.writeFileSync('update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
fs.writeFileSync(
'update.json',
JSON.stringify(updateInfo, null, 4),
'utf8',
);
},
}
};

View File

@@ -13,20 +13,14 @@ const { spawn, spawnSync } = require('child_process');
const g2js = require('gradle-to-js/lib/parser');
const os = require('os');
var diff;
var bsdiff, hdiff, diff;
try {
var bsdiff = require('node-bsdiff');
diff = typeof bsdiff != 'function' ? bsdiff.diff : bsdiff;
} catch (e) {
diff = function () {
console.warn(
'This function needs "node-bsdiff". Please run "npm i node-bsdiff" from your project directory first!',
);
throw new Error(
'This function needs module "node-bsdiff". Please install it first.',
);
};
}
bsdiff = require('node-bsdiff').diff;
} catch (e) {}
try {
hdiff = require('node-hdiffpatch').diff;
} catch (e) {}
async function runReactNativeBundleCommand(
bundleName,
@@ -40,9 +34,9 @@ async function runReactNativeBundleCommand(
let gradleConfig = {};
if (platform === 'android') {
gradleConfig = await checkGradleConfig();
if (gradleConfig.crunchPngs !== false) {
throw new Error('请先禁用android的crunchPngs优化具体请参考 https://pushy.reactnative.cn/docs/getting-started.html#%E7%A6%81%E7%94%A8android%E7%9A%84crunch%E4%BC%98%E5%8C%96')
}
// if (gradleConfig.crunchPngs !== false) {
// throw new Error('请先禁用android的crunchPngs优化具体请参考 https://pushy.reactnative.cn/docs/getting-started.html#%E7%A6%81%E7%94%A8android%E7%9A%84crunch%E4%BC%98%E5%8C%96')
// }
}
let reactNativeBundleArgs = [];
@@ -125,7 +119,6 @@ async function checkGradleConfig() {
try {
const gradleConfig = await g2js.parseFile('android/app/build.gradle');
const projectConfig = gradleConfig['project.ext.react'];
crunchPngs = gradleConfig.android.buildTypes.release.crunchPngs;
for (const packagerConfig of projectConfig) {
if (
packagerConfig.includes('enableHermes') &&
@@ -135,11 +128,12 @@ async function checkGradleConfig() {
break;
}
}
crunchPngs = gradleConfig.android.buildTypes.release.crunchPngs;
} catch (e) {}
return {
enableHermes,
crunchPngs,
}
};
}
async function compileHermesByteCode(bundleName, outputFolder) {
@@ -482,6 +476,42 @@ function enumZipEntries(zipFn, callback) {
});
}
function diffArgsCheck(args, options, diffFn) {
const [origin, next] = args;
if (!origin || !next) {
console.error(`Usage: pushy ${diffFn} <origin> <next>`);
process.exit(1);
}
if (diffFn.startsWith('hdiff')) {
if (!hdiff) {
console.error(
`This function needs "node-hdiffpatch".
Please run "npm i node-hdiffpatch" to install`,
);
process.exit(1);
}
diff = hdiff;
} else {
if (!bsdiff) {
console.error(
`This function needs "node-bsdiff".
Please run "npm i node-bsdiff" to install`,
);
process.exit(1);
}
diff = bsdiff;
}
const { output } = options;
return {
origin,
next,
realOutput: output.replace(/\$\{time\}/g, '' + Date.now()),
};
}
export const commands = {
bundle: async function ({ options }) {
const platform = checkPlatform(
@@ -535,30 +565,41 @@ export const commands = {
},
async diff({ args, options }) {
const [origin, next] = args;
const { output } = options;
const { origin, next, realOutput } = diffArgsCheck(args, options, 'diff');
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
await diffFromPPK(origin, next, realOutput, 'index.bundlejs');
console.log(`${realOutput} generated.`);
},
if (!origin || !next) {
console.error('pushy diff <origin> <next>');
process.exit(1);
}
async hdiff({ args, options }) {
const { origin, next, realOutput } = diffArgsCheck(args, options, 'hdiff');
await diffFromPPK(origin, next, realOutput, 'index.bundlejs');
console.log(`${realOutput} generated.`);
},
async diffFromApk({ args, options }) {
const [origin, next] = args;
const { output } = options;
const { origin, next, realOutput } = diffArgsCheck(
args,
options,
'diffFromApk',
);
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
await diffFromPackage(
origin,
next,
realOutput,
'assets/index.android.bundle',
);
console.log(`${realOutput} generated.`);
},
if (!origin || !next) {
console.error('pushy diffFromApk <origin> <next>');
process.exit(1);
}
async hdiffFromApk({ args, options }) {
const { origin, next, realOutput } = diffArgsCheck(
args,
options,
'hdiffFromApk',
);
await diffFromPackage(
origin,
@@ -570,15 +611,26 @@ export const commands = {
},
async diffFromIpa({ args, options }) {
const [origin, next] = args;
const { output } = options;
const { origin, next, realOutput } = diffArgsCheck(
args,
options,
'diffFromIpa',
);
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', (v) => {
const m = /^Payload\/[^/]+\/(.+)$/.exec(v);
return m && m[1];
});
if (!origin || !next) {
console.error('pushy diffFromIpa <origin> <next>');
process.exit(1);
}
console.log(`${realOutput} generated.`);
},
async hdiffFromIpa({ args, options }) {
const { origin, next, realOutput } = diffArgsCheck(
args,
options,
'hdiffFromIpa',
);
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', (v) => {
const m = /^Payload\/[^/]+\/(.+)$/.exec(v);

View File

@@ -36,6 +36,7 @@ function run() {
const argv = require('cli-arguments').parse(require('../cli.json'));
global.NO_INTERACTIVE = argv.options['no-interactive'];
global.USE_ACC_OSS = argv.options['acc'];
loadSession()
.then(()=>commands[argv.command](argv))

View File

@@ -52,8 +52,25 @@ export const commands = {
if (!fn || !fn.endsWith('.ipa')) {
throw new Error('Usage: pushy uploadIpa <ipaFile>');
}
const { versionName, buildTime } = await getIpaInfo(fn);
const { appId } = await getSelectedApp('ios');
const {
versionName,
buildTime,
appId: appIdInPkg,
appKey: appKeyInPkg,
} = await getIpaInfo(fn);
const { appId, appKey } = await 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 uploadFile(fn);
@@ -70,8 +87,25 @@ export const commands = {
if (!fn || !fn.endsWith('.apk')) {
throw new Error('Usage: pushy uploadApk <apkFile>');
}
const { versionName, buildTime } = await getApkInfo(fn);
const { appId } = await getSelectedApp('android');
const {
versionName,
buildTime,
appId: appIdInPkg,
appKey: appKeyInPkg,
} = await getApkInfo(fn);
const { appId, appKey } = await 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 uploadFile(fn);