mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-17 18:06:10 +08:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ec8d6a767b | ||
![]() |
fa8290fcbf | ||
![]() |
46d308c7c2 | ||
![]() |
9e721e1858 | ||
![]() |
c30454976c | ||
![]() |
3d73b95140 | ||
![]() |
32cafd92bf | ||
![]() |
ea10cd7828 | ||
![]() |
574a52b126 | ||
![]() |
c00a7a72fe |
33
cli.json
33
cli.json
@@ -123,7 +123,7 @@
|
|||||||
"description": "Create diff patch",
|
"description": "Create diff patch",
|
||||||
"options": {
|
"options": {
|
||||||
"output": {
|
"output": {
|
||||||
"default": "build/output/diff",
|
"default": ".pushy/output/diff",
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@
|
|||||||
"description": "Create diff patch from a Android package(.apk)",
|
"description": "Create diff patch from a Android package(.apk)",
|
||||||
"options": {
|
"options": {
|
||||||
"output": {
|
"output": {
|
||||||
"default": "build/output/diff-${time}.apk-patch",
|
"default": ".pushy/output/diff-${time}.apk-patch",
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,34 @@
|
|||||||
"description": "Create diff patch from a iOS package(.ipa)",
|
"description": "Create diff patch from a iOS package(.ipa)",
|
||||||
"options": {
|
"options": {
|
||||||
"output": {
|
"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
|
"hasValue": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update-cli",
|
"name": "react-native-update-cli",
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
26
src/api.js
26
src/api.js
@@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const defaultEndpoint = 'http://u.reactnative.cn/api'
|
const defaultEndpoint = 'http://u.reactnative.cn/api';
|
||||||
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
import request from 'request';
|
import request from 'request';
|
||||||
@@ -22,7 +22,7 @@ let savedSession = undefined;
|
|||||||
|
|
||||||
const userAgent = `react-native-update-cli/${packageJson.version}`;
|
const userAgent = `react-native-update-cli/${packageJson.version}`;
|
||||||
|
|
||||||
exports.loadSession = async function() {
|
exports.loadSession = async function () {
|
||||||
if (fs.existsSync('.update')) {
|
if (fs.existsSync('.update')) {
|
||||||
try {
|
try {
|
||||||
exports.replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
|
exports.replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
|
||||||
@@ -36,15 +36,15 @@ exports.loadSession = async function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getSession = function() {
|
exports.getSession = function () {
|
||||||
return session;
|
return session;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.replaceSession = function(newSession) {
|
exports.replaceSession = function (newSession) {
|
||||||
session = newSession;
|
session = newSession;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.saveSession = function() {
|
exports.saveSession = function () {
|
||||||
// Only save on change.
|
// Only save on change.
|
||||||
if (session !== savedSession) {
|
if (session !== savedSession) {
|
||||||
const current = session;
|
const current = session;
|
||||||
@@ -54,7 +54,7 @@ exports.saveSession = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.closeSession = function() {
|
exports.closeSession = function () {
|
||||||
if (fs.existsSync('.update')) {
|
if (fs.existsSync('.update')) {
|
||||||
fs.unlinkSync('.update');
|
fs.unlinkSync('.update');
|
||||||
savedSession = undefined;
|
savedSession = undefined;
|
||||||
@@ -75,7 +75,7 @@ async function query(url, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function queryWithoutBody(method) {
|
function queryWithoutBody(method) {
|
||||||
return function(api) {
|
return function (api) {
|
||||||
return query(host + api, {
|
return query(host + api, {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -87,7 +87,7 @@ function queryWithoutBody(method) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function queryWithBody(method) {
|
function queryWithBody(method) {
|
||||||
return function(api, body) {
|
return function (api, body) {
|
||||||
return query(host + api, {
|
return query(host + api, {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -107,7 +107,7 @@ exports.doDelete = queryWithBody('DELETE');
|
|||||||
|
|
||||||
async function uploadFile(fn, key) {
|
async function uploadFile(fn, key) {
|
||||||
const { url, backupUrl, formData, maxSize } = await exports.post('/upload', {
|
const { url, backupUrl, formData, maxSize } = await exports.post('/upload', {
|
||||||
ext: path.extname(fn)
|
ext: path.extname(fn),
|
||||||
});
|
});
|
||||||
let realUrl = url;
|
let realUrl = url;
|
||||||
|
|
||||||
@@ -126,7 +126,11 @@ async function uploadFile(fn, key) {
|
|||||||
|
|
||||||
const fileSize = fs.statSync(fn).size;
|
const fileSize = fs.statSync(fn).size;
|
||||||
if (maxSize && fileSize > filesizeParser(maxSize)) {
|
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', {
|
const bar = new ProgressBar(' Uploading [:bar] :percent :etas', {
|
||||||
@@ -141,7 +145,7 @@ async function uploadFile(fn, key) {
|
|||||||
}
|
}
|
||||||
formData.file = fs.createReadStream(fn);
|
formData.file = fs.createReadStream(fn);
|
||||||
|
|
||||||
formData.file.on('data', function(data) {
|
formData.file.on('data', function (data) {
|
||||||
bar.tick(data.length);
|
bar.tick(data.length);
|
||||||
});
|
});
|
||||||
request.post(
|
request.post(
|
||||||
|
128
src/bundle.js
128
src/bundle.js
@@ -13,20 +13,14 @@ const { spawn, spawnSync } = require('child_process');
|
|||||||
const g2js = require('gradle-to-js/lib/parser');
|
const g2js = require('gradle-to-js/lib/parser');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
|
|
||||||
var diff;
|
var bsdiff, hdiff, diff;
|
||||||
try {
|
try {
|
||||||
var bsdiff = require('node-bsdiff');
|
bsdiff = require('node-bsdiff').diff;
|
||||||
diff = typeof bsdiff != 'function' ? bsdiff.diff : bsdiff;
|
} catch (e) {}
|
||||||
} catch (e) {
|
|
||||||
diff = function () {
|
try {
|
||||||
console.warn(
|
hdiff = require('node-hdiffpatch').diff;
|
||||||
'This function needs "node-bsdiff". Please run "npm i node-bsdiff" from your project directory first!',
|
} catch (e) {}
|
||||||
);
|
|
||||||
throw new Error(
|
|
||||||
'This function needs module "node-bsdiff". Please install it first.',
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runReactNativeBundleCommand(
|
async function runReactNativeBundleCommand(
|
||||||
bundleName,
|
bundleName,
|
||||||
@@ -40,9 +34,9 @@ async function runReactNativeBundleCommand(
|
|||||||
let gradleConfig = {};
|
let gradleConfig = {};
|
||||||
if (platform === 'android') {
|
if (platform === 'android') {
|
||||||
gradleConfig = await checkGradleConfig();
|
gradleConfig = await checkGradleConfig();
|
||||||
if (gradleConfig.crunchPngs !== false) {
|
// 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')
|
// 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 = [];
|
let reactNativeBundleArgs = [];
|
||||||
@@ -139,7 +133,7 @@ async function checkGradleConfig() {
|
|||||||
return {
|
return {
|
||||||
enableHermes,
|
enableHermes,
|
||||||
crunchPngs,
|
crunchPngs,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compileHermesByteCode(bundleName, outputFolder) {
|
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 = {
|
export const commands = {
|
||||||
bundle: async function ({ options }) {
|
bundle: async function ({ options }) {
|
||||||
const platform = checkPlatform(
|
const platform = checkPlatform(
|
||||||
@@ -535,30 +565,41 @@ export const commands = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async diff({ args, options }) {
|
async diff({ args, options }) {
|
||||||
const [origin, next] = args;
|
const { origin, next, realOutput } = diffArgsCheck(args, options, 'diff');
|
||||||
const { output } = options;
|
|
||||||
|
|
||||||
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
|
await diffFromPPK(origin, next, realOutput, 'index.bundlejs');
|
||||||
|
console.log(`${realOutput} generated.`);
|
||||||
|
},
|
||||||
|
|
||||||
if (!origin || !next) {
|
async hdiff({ args, options }) {
|
||||||
console.error('pushy diff <origin> <next>');
|
const { origin, next, realOutput } = diffArgsCheck(args, options, 'hdiff');
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
await diffFromPPK(origin, next, realOutput, 'index.bundlejs');
|
await diffFromPPK(origin, next, realOutput, 'index.bundlejs');
|
||||||
console.log(`${realOutput} generated.`);
|
console.log(`${realOutput} generated.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
async diffFromApk({ args, options }) {
|
async diffFromApk({ args, options }) {
|
||||||
const [origin, next] = args;
|
const { origin, next, realOutput } = diffArgsCheck(
|
||||||
const { output } = options;
|
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) {
|
async hdiffFromApk({ args, options }) {
|
||||||
console.error('pushy diffFromApk <origin> <next>');
|
const { origin, next, realOutput } = diffArgsCheck(
|
||||||
process.exit(1);
|
args,
|
||||||
}
|
options,
|
||||||
|
'hdiffFromApk',
|
||||||
|
);
|
||||||
|
|
||||||
await diffFromPackage(
|
await diffFromPackage(
|
||||||
origin,
|
origin,
|
||||||
@@ -570,15 +611,26 @@ export const commands = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async diffFromIpa({ args, options }) {
|
async diffFromIpa({ args, options }) {
|
||||||
const [origin, next] = args;
|
const { origin, next, realOutput } = diffArgsCheck(
|
||||||
const { output } = options;
|
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.log(`${realOutput} generated.`);
|
||||||
console.error('pushy diffFromIpa <origin> <next>');
|
},
|
||||||
process.exit(1);
|
|
||||||
}
|
async hdiffFromIpa({ args, options }) {
|
||||||
|
const { origin, next, realOutput } = diffArgsCheck(
|
||||||
|
args,
|
||||||
|
options,
|
||||||
|
'hdiffFromIpa',
|
||||||
|
);
|
||||||
|
|
||||||
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', (v) => {
|
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', (v) => {
|
||||||
const m = /^Payload\/[^/]+\/(.+)$/.exec(v);
|
const m = /^Payload\/[^/]+\/(.+)$/.exec(v);
|
||||||
|
Reference in New Issue
Block a user