mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-17 18:06:10 +08:00
Compare commits
78 Commits
v1.0.1
...
v1.4.0-bet
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f51223a662 | ||
![]() |
3d73b95140 | ||
![]() |
32cafd92bf | ||
![]() |
ea10cd7828 | ||
![]() |
574a52b126 | ||
![]() |
c00a7a72fe | ||
![]() |
0e8e3aa420 | ||
![]() |
7426e93647 | ||
![]() |
b6fb2e7d2a | ||
![]() |
7f1dcbb571 | ||
![]() |
59fad93832 | ||
![]() |
3db4f803e2 | ||
![]() |
56d44b8c85 | ||
![]() |
ecd951265f | ||
![]() |
62d455ac07 | ||
![]() |
acfc2dd65b | ||
![]() |
7f062f681a | ||
![]() |
7f5b9fd7fd | ||
![]() |
13b21c49c1 | ||
![]() |
85db61704c | ||
![]() |
57ddfc5d7d | ||
![]() |
6cb38eeec1 | ||
![]() |
8a7c21fb50 | ||
![]() |
7223fa1389 | ||
![]() |
2d5c01e990 | ||
![]() |
16b1cc3ed4 | ||
![]() |
5e69793925 | ||
![]() |
b3c8e1f8e3 | ||
![]() |
27ed4bd8d1 | ||
![]() |
f0ad8bdcde | ||
![]() |
62a37a955b | ||
![]() |
233e661f17 | ||
![]() |
3a9bf67703 | ||
![]() |
aa5fd4b4b1 | ||
![]() |
6ed6420dd1 | ||
![]() |
92f7d7efc4 | ||
![]() |
de68470060 | ||
![]() |
dfee2dd762 | ||
![]() |
d726987b2c | ||
![]() |
01f11822e1 | ||
![]() |
37353222ef | ||
![]() |
b76a2eb989 | ||
![]() |
05b97d1e1e | ||
![]() |
ba4969fe68 | ||
![]() |
dad63743c1 | ||
![]() |
924c58d254 | ||
![]() |
b950d3dbe8 | ||
![]() |
1206cd4461 | ||
![]() |
0147582561 | ||
![]() |
a343999cb6 | ||
![]() |
ef28133cfc | ||
![]() |
d16292a7a6 | ||
![]() |
2146940d01 | ||
![]() |
755485b4cb | ||
![]() |
6bc7ee7091 | ||
![]() |
9d00325519 | ||
![]() |
84facadf3d | ||
![]() |
a9dea5c188 | ||
![]() |
83fe70f840 | ||
![]() |
f1dd31cd56 | ||
![]() |
a6477b4f0f | ||
![]() |
15b82b440e | ||
![]() |
cc3f5dc093 | ||
![]() |
19c6656dcf | ||
![]() |
27f640f305 | ||
![]() |
552db6d2b3 | ||
![]() |
443e4c14f6 | ||
![]() |
80b45469eb | ||
![]() |
6b32a4c3aa | ||
![]() |
1d5379c837 | ||
![]() |
7b3872265b | ||
![]() |
9750984a69 | ||
![]() |
0b217484b7 | ||
![]() |
76d958c623 | ||
![]() |
4a062c68af | ||
![]() |
d63ba619ba | ||
![]() |
772929837f | ||
![]() |
60351c64f1 |
8
.babelrc
8
.babelrc
@@ -1,14 +1,8 @@
|
||||
{
|
||||
"plugins": [
|
||||
"syntax-object-rest-spread",
|
||||
"syntax-async-functions",
|
||||
"transform-es2015-arrow-functions",
|
||||
"transform-async-to-generator",
|
||||
"transform-es2015-modules-commonjs",
|
||||
"transform-es2015-destructuring",
|
||||
"transform-es2015-spread",
|
||||
"transform-object-rest-spread",
|
||||
"transform-es2015-parameters",
|
||||
"transform-strict-mode"
|
||||
"transform-object-rest-spread"
|
||||
]
|
||||
}
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -104,3 +104,4 @@ dist
|
||||
.tern-port
|
||||
|
||||
lib/
|
||||
.DS_Store
|
||||
|
35
cli.json
35
cli.json
@@ -2,15 +2,11 @@
|
||||
"useCommand": true,
|
||||
"defaultCommand": "help",
|
||||
"commands": {
|
||||
"help": {
|
||||
},
|
||||
"help": {},
|
||||
|
||||
"login":{
|
||||
},
|
||||
"logout": {
|
||||
},
|
||||
"me": {
|
||||
},
|
||||
"login": {},
|
||||
"logout": {},
|
||||
"me": {},
|
||||
|
||||
"createApp": {
|
||||
"options": {
|
||||
@@ -29,8 +25,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"deleteApp": {
|
||||
},
|
||||
"deleteApp": {},
|
||||
"selectApp": {
|
||||
"options": {
|
||||
"platform": {
|
||||
@@ -39,10 +34,10 @@
|
||||
}
|
||||
},
|
||||
|
||||
"uploadIpa": {
|
||||
},
|
||||
"uploadApk": {
|
||||
},
|
||||
"uploadIpa": {},
|
||||
"uploadApk": {},
|
||||
"parseIpa": {},
|
||||
"parseApk": {},
|
||||
"packages": {
|
||||
"options": {
|
||||
"platform": {
|
||||
@@ -102,7 +97,7 @@
|
||||
"platform": {
|
||||
"hasValue": true
|
||||
},
|
||||
"bundleName":{
|
||||
"bundleName": {
|
||||
"default": "index.bundlejs",
|
||||
"hasValue": true
|
||||
},
|
||||
@@ -111,16 +106,14 @@
|
||||
"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": {
|
||||
|
||||
}
|
||||
"verbose": {}
|
||||
}
|
||||
},
|
||||
"release": {
|
||||
@@ -154,7 +147,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"globalOptions":{
|
||||
"globalOptions": {
|
||||
"no-interactive": {
|
||||
"default": false
|
||||
}
|
||||
|
40
package.json
40
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update-cli",
|
||||
"version": "1.0.1",
|
||||
"version": "1.4.0-beta0",
|
||||
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
@@ -32,31 +32,29 @@
|
||||
},
|
||||
"homepage": "https://github.com/reactnativecn/react-native-pushy/tree/master/react-native-pushy-cli",
|
||||
"dependencies": {
|
||||
"app-info-parser": "^0.3.8",
|
||||
"app-info-parser": "^1.0.0",
|
||||
"cli-arguments": "^0.2.1",
|
||||
"fs-extra": "^8.1.0",
|
||||
"filesize-parser": "^1.5.0",
|
||||
"fs-extra": "8",
|
||||
"gradle-to-js": "^2.0.0",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"progress": "^1.1.8",
|
||||
"node-fetch": "^2.6.1",
|
||||
"progress": "^2.0.3",
|
||||
"read": "^1.0.7",
|
||||
"request": "^2.69.0",
|
||||
"tty-table": "^2.7.0",
|
||||
"update-notifier": "^4.1.0",
|
||||
"request": "^2.88.2",
|
||||
"tcp-ping": "^0.1.1",
|
||||
"tty-table": "4.1",
|
||||
"update-notifier": "^4.1.1",
|
||||
"yauzl": "^2.10.0",
|
||||
"yazl": "2.3.0"
|
||||
"yazl": "2.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.5.1",
|
||||
"babel-eslint": "^4.1.6",
|
||||
"babel-plugin-syntax-async-functions": "^6.5.0",
|
||||
"babel-plugin-syntax-object-rest-spread": "^6.5.0",
|
||||
"babel-plugin-transform-async-to-generator": "^6.3.13",
|
||||
"babel-plugin-transform-es2015-arrow-functions": "^6.5.2",
|
||||
"babel-plugin-transform-es2015-destructuring": "^6.3.15",
|
||||
"babel-plugin-transform-es2015-modules-commonjs": "^6.3.16",
|
||||
"babel-plugin-transform-es2015-parameters": "^6.5.0",
|
||||
"babel-plugin-transform-es2015-spread": "^6.5.2",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.5.0",
|
||||
"babel-plugin-transform-strict-mode": "^6.5.2"
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
|
||||
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
|
||||
"babel-plugin-transform-es2015-spread": "^6.22.0",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.26.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
}
|
||||
|
90
src/api.js
90
src/api.js
@@ -2,36 +2,49 @@
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
const fetch = require('isomorphic-fetch');
|
||||
let host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn/api';
|
||||
const fs = require('fs-extra');
|
||||
const fetch = require('node-fetch');
|
||||
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';
|
||||
const packageJson = require('../package.json');
|
||||
const tcpp = require('tcp-ping');
|
||||
const util = require('util');
|
||||
const path = require('path');
|
||||
import filesizeParser from 'filesize-parser';
|
||||
import { pricingPageUrl } from './utils';
|
||||
|
||||
const tcpPing = util.promisify(tcpp.ping);
|
||||
|
||||
let session = undefined;
|
||||
let savedSession = undefined;
|
||||
|
||||
exports.loadSession = async function() {
|
||||
const userAgent = `react-native-update-cli/${packageJson.version}`;
|
||||
|
||||
exports.loadSession = async function () {
|
||||
if (fs.existsSync('.update')) {
|
||||
try {
|
||||
exports.replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
|
||||
savedSession = session;
|
||||
} catch (e) {
|
||||
console.error('Failed to parse file `.update`. Try to remove it manually.');
|
||||
console.error(
|
||||
'Failed to parse file `.update`. Try to remove it manually.',
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
@@ -41,29 +54,32 @@ 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';
|
||||
host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
||||
};
|
||||
|
||||
async function query(url, options) {
|
||||
const resp = await fetch(url, options);
|
||||
const json = await resp.json();
|
||||
if (resp.status !== 200) {
|
||||
throw Object.assign(new Error(json.message || json.error), { status: resp.status });
|
||||
throw Object.assign(new Error(json.message || json.error), {
|
||||
status: resp.status,
|
||||
});
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
function queryWithoutBody(method) {
|
||||
return function(api) {
|
||||
return function (api) {
|
||||
return query(host + api, {
|
||||
method,
|
||||
headers: {
|
||||
'User-Agent': userAgent,
|
||||
'X-AccessToken': session ? session.token : '',
|
||||
},
|
||||
});
|
||||
@@ -71,10 +87,11 @@ function queryWithoutBody(method) {
|
||||
}
|
||||
|
||||
function queryWithBody(method) {
|
||||
return function(api, body) {
|
||||
return function (api, body) {
|
||||
return query(host + api, {
|
||||
method,
|
||||
headers: {
|
||||
'User-Agent': userAgent,
|
||||
'Content-Type': 'application/json',
|
||||
'X-AccessToken': session ? session.token : '',
|
||||
},
|
||||
@@ -88,15 +105,33 @@ exports.post = queryWithBody('POST');
|
||||
exports.put = queryWithBody('PUT');
|
||||
exports.doDelete = queryWithBody('DELETE');
|
||||
|
||||
async function uploadFile(fn) {
|
||||
const { url, fieldName, formData } = await exports.post('/upload', {});
|
||||
async function uploadFile(fn, key) {
|
||||
const { url, backupUrl, formData, maxSize } = await exports.post('/upload', {
|
||||
ext: path.extname(fn),
|
||||
});
|
||||
let realUrl = url;
|
||||
|
||||
if (!/^https?\:\/\//.test(url)) {
|
||||
realUrl = host + 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) {
|
||||
realUrl = backupUrl;
|
||||
}
|
||||
// console.log({realUrl});
|
||||
}
|
||||
|
||||
const fileSize = fs.statSync(fn).size;
|
||||
if (maxSize && fileSize > filesizeParser(maxSize)) {
|
||||
throw new Error(
|
||||
`此文件大小${(fileSize / 1048576).toFixed(
|
||||
1,
|
||||
)}m, 超出当前额度${maxSize}。您可以考虑升级付费业务以提升此额度。详情请访问:${pricingPageUrl}`,
|
||||
);
|
||||
}
|
||||
|
||||
const bar = new ProgressBar(' Uploading [:bar] :percent :etas', {
|
||||
complete: '=',
|
||||
@@ -105,24 +140,39 @@ async function uploadFile(fn) {
|
||||
});
|
||||
|
||||
const info = await new Promise((resolve, reject) => {
|
||||
if (key) {
|
||||
formData.key = key;
|
||||
}
|
||||
formData.file = fs.createReadStream(fn);
|
||||
|
||||
formData.file.on('data', function(data) {
|
||||
formData.file.on('data', function (data) {
|
||||
bar.tick(data.length);
|
||||
});
|
||||
request.post(
|
||||
realUrl,
|
||||
{
|
||||
formData,
|
||||
headers: {
|
||||
'User-Agent': userAgent,
|
||||
'X-AccessToken': session ? session.token : '',
|
||||
},
|
||||
},
|
||||
(err, resp, body) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
if (resp.statusCode > 299) {
|
||||
return reject(Object.assign(new Error(body), { status: resp.statusCode }));
|
||||
return reject(
|
||||
Object.assign(new Error(body), { status: resp.statusCode }),
|
||||
);
|
||||
}
|
||||
resolve(JSON.parse(body));
|
||||
resolve(
|
||||
body
|
||||
? // qiniu
|
||||
JSON.parse(body)
|
||||
: // aliyun oss
|
||||
{ hash: formData.key },
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
85
src/app.js
85
src/app.js
@@ -2,14 +2,11 @@
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
import {question} from './utils';
|
||||
import * as fs from 'fs-extra';
|
||||
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',
|
||||
);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
333
src/bundle.js
333
src/bundle.js
@@ -7,34 +7,17 @@ import { getRNVersion, translateOptions } from './utils';
|
||||
import * as fs from 'fs-extra';
|
||||
import { ZipFile } from 'yazl';
|
||||
import { open as openZipFile } from 'yauzl';
|
||||
import { question } from './utils';
|
||||
import { question, printVersionCommand } from './utils';
|
||||
import { checkPlatform } from './app';
|
||||
const { spawn, spawnSync, execSync } = require('child_process');
|
||||
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.');
|
||||
};
|
||||
}
|
||||
|
||||
function exec(command) {
|
||||
const commandResult = spawnSync(command, {
|
||||
shell: true,
|
||||
stdio: 'inherit',
|
||||
});
|
||||
if (commandResult.error) {
|
||||
throw commandResult.error;
|
||||
}
|
||||
}
|
||||
bsdiff = require('node-bsdiff').diff;
|
||||
hdiff = require('node-hdiffpatch').diff;
|
||||
} catch (e) {}
|
||||
|
||||
async function runReactNativeBundleCommand(
|
||||
bundleName,
|
||||
@@ -45,19 +28,30 @@ async function runReactNativeBundleCommand(
|
||||
sourcemapOutput,
|
||||
config,
|
||||
) {
|
||||
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')
|
||||
// }
|
||||
// }
|
||||
|
||||
let reactNativeBundleArgs = [];
|
||||
|
||||
let envArgs = process.env.PUSHY_ENV_ARGS;
|
||||
|
||||
if (envArgs) {
|
||||
Array.prototype.push.apply(reactNativeBundleArgs, envArgs.trim().split(/\s+/));
|
||||
Array.prototype.push.apply(
|
||||
reactNativeBundleArgs,
|
||||
envArgs.trim().split(/\s+/),
|
||||
);
|
||||
}
|
||||
|
||||
fs.emptyDirSync(outputFolder);
|
||||
|
||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||
path.join("node_modules", "react-native", "local-cli", "cli.js"),
|
||||
"bundle",
|
||||
path.join('node_modules', 'react-native', 'local-cli', 'cli.js'),
|
||||
'bundle',
|
||||
'--assets-dest',
|
||||
outputFolder,
|
||||
'--bundle-output',
|
||||
@@ -80,22 +74,28 @@ async function runReactNativeBundleCommand(
|
||||
}
|
||||
|
||||
const reactNativeBundleProcess = spawn('node', reactNativeBundleArgs);
|
||||
console.log(`Running bundle command: node ${reactNativeBundleArgs.join(' ')}`);
|
||||
console.log(
|
||||
`Running bundle command: node ${reactNativeBundleArgs.join(' ')}`,
|
||||
);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
reactNativeBundleProcess.stdout.on('data', data => {
|
||||
reactNativeBundleProcess.stdout.on('data', (data) => {
|
||||
console.log(data.toString().trim());
|
||||
});
|
||||
|
||||
reactNativeBundleProcess.stderr.on('data', data => {
|
||||
reactNativeBundleProcess.stderr.on('data', (data) => {
|
||||
console.error(data.toString().trim());
|
||||
});
|
||||
|
||||
reactNativeBundleProcess.on('close', async exitCode => {
|
||||
reactNativeBundleProcess.on('close', async (exitCode) => {
|
||||
if (exitCode) {
|
||||
reject(new Error(`"react-native bundle" command exited with code ${exitCode}.`));
|
||||
reject(
|
||||
new Error(
|
||||
`"react-native bundle" command exited with code ${exitCode}.`,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
if (platform === 'android') {
|
||||
if (gradleConfig.enableHermes) {
|
||||
await compileHermesByteCode(bundleName, outputFolder);
|
||||
}
|
||||
resolve(null);
|
||||
@@ -110,28 +110,51 @@ function getHermesOSBin() {
|
||||
if (os.platform() === 'linux') return 'linux64-bin';
|
||||
}
|
||||
|
||||
async function compileHermesByteCode(bundleName, outputFolder) {
|
||||
async function checkGradleConfig() {
|
||||
let enableHermes = false;
|
||||
let crunchPngs;
|
||||
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') && packagerConfig.includes('true')) {
|
||||
if (
|
||||
packagerConfig.includes('enableHermes') &&
|
||||
packagerConfig.includes('true')
|
||||
) {
|
||||
enableHermes = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
if (enableHermes) {
|
||||
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
|
||||
const hermesPath = fs.existsSync('node_modules/hermes-engine')
|
||||
? 'node_modules/hermes-engine'
|
||||
: 'node_modules/hermesvm';
|
||||
execSync(
|
||||
`${hermesPath}/${getHermesOSBin()}/hermes -emit-binary -out ${outputFolder}/${bundleName} ${outputFolder}/${bundleName} -O`,
|
||||
{ stdio: 'ignore' },
|
||||
);
|
||||
}
|
||||
return {
|
||||
enableHermes,
|
||||
crunchPngs,
|
||||
};
|
||||
}
|
||||
|
||||
async function compileHermesByteCode(bundleName, outputFolder) {
|
||||
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
|
||||
const hermesPackage = fs.existsSync('node_modules/hermes-engine')
|
||||
? 'node_modules/hermes-engine' // 0.2+
|
||||
: 'node_modules/hermesvm'; // < 0.2
|
||||
const hermesPath = `${hermesPackage}/${getHermesOSBin()}`;
|
||||
|
||||
const hermesCommand = fs.existsSync(`${hermesPath}/hermesc`)
|
||||
? `${hermesPath}/hermesc` // 0.5+
|
||||
: `${hermesPath}/hermes`; // < 0.5
|
||||
|
||||
spawnSync(
|
||||
path.join.apply(null, hermesCommand.split('/')),
|
||||
[
|
||||
'-emit-binary',
|
||||
'-out',
|
||||
path.join(outputFolder, bundleName),
|
||||
path.join(outputFolder, bundleName),
|
||||
'-O',
|
||||
],
|
||||
{ stdio: 'ignore' },
|
||||
);
|
||||
}
|
||||
|
||||
async function pack(dir, output) {
|
||||
@@ -163,10 +186,12 @@ async function pack(dir, output) {
|
||||
|
||||
addDirectory(dir, '');
|
||||
|
||||
zipfile.outputStream.on('error', err => reject(err));
|
||||
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', function() {
|
||||
resolve();
|
||||
});
|
||||
zipfile.outputStream.on('error', (err) => reject(err));
|
||||
zipfile.outputStream
|
||||
.pipe(fs.createWriteStream(output))
|
||||
.on('close', function () {
|
||||
resolve();
|
||||
});
|
||||
zipfile.end();
|
||||
});
|
||||
console.log('Bundled saved to: ' + output);
|
||||
@@ -213,24 +238,30 @@ async function diffFromPPK(origin, next, output) {
|
||||
|
||||
if (entry.fileName === 'index.bundlejs') {
|
||||
// This is source.
|
||||
return readEntire(entry, zipFile).then(v => (originSource = v));
|
||||
return readEntire(entry, zipFile).then((v) => (originSource = v));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
originSource = originSource || new Buffer(0);
|
||||
if (!originSource) {
|
||||
throw new Error(
|
||||
`Bundle file not found! Please use default bundle file name and path.`,
|
||||
);
|
||||
}
|
||||
|
||||
const copies = {};
|
||||
|
||||
var zipfile = new ZipFile();
|
||||
|
||||
const writePromise = new Promise((resolve, reject) => {
|
||||
zipfile.outputStream.on('error', err => {
|
||||
zipfile.outputStream.on('error', (err) => {
|
||||
throw err;
|
||||
});
|
||||
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', function() {
|
||||
resolve();
|
||||
});
|
||||
zipfile.outputStream
|
||||
.pipe(fs.createWriteStream(output))
|
||||
.on('close', function () {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
const addedEntry = {};
|
||||
@@ -259,9 +290,12 @@ async function diffFromPPK(origin, next, output) {
|
||||
}
|
||||
} else if (entry.fileName === 'index.bundlejs') {
|
||||
//console.log('Found bundle');
|
||||
return readEntire(entry, nextZipfile).then(newSource => {
|
||||
return readEntire(entry, nextZipfile).then((newSource) => {
|
||||
//console.log('Begin diff');
|
||||
zipfile.addBuffer(diff(originSource, newSource), 'index.bundlejs.patch');
|
||||
zipfile.addBuffer(
|
||||
diff(originSource, newSource),
|
||||
'index.bundlejs.patch',
|
||||
);
|
||||
//console.log('End diff');
|
||||
});
|
||||
} else {
|
||||
@@ -286,7 +320,7 @@ async function diffFromPPK(origin, next, output) {
|
||||
addEntry(basename(entry.fileName));
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
nextZipfile.openReadStream(entry, function(err, readStream) {
|
||||
nextZipfile.openReadStream(entry, function (err, readStream) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
@@ -310,12 +344,21 @@ async function diffFromPPK(origin, next, output) {
|
||||
}
|
||||
|
||||
//console.log({copies, deletes});
|
||||
zipfile.addBuffer(new Buffer(JSON.stringify({ copies, deletes })), '__diff.json');
|
||||
zipfile.addBuffer(
|
||||
Buffer.from(JSON.stringify({ copies, deletes })),
|
||||
'__diff.json',
|
||||
);
|
||||
zipfile.end();
|
||||
await writePromise;
|
||||
}
|
||||
|
||||
async function diffFromPackage(origin, next, output, originBundleName, transformPackagePath = v => v) {
|
||||
async function diffFromPackage(
|
||||
origin,
|
||||
next,
|
||||
output,
|
||||
originBundleName,
|
||||
transformPackagePath = (v) => v,
|
||||
) {
|
||||
fs.ensureDirSync(path.dirname(output));
|
||||
|
||||
const originEntries = {};
|
||||
@@ -337,24 +380,30 @@ async function diffFromPackage(origin, next, output, originBundleName, transform
|
||||
|
||||
if (fn === originBundleName) {
|
||||
// This is source.
|
||||
return readEntire(entry, zipFile).then(v => (originSource = v));
|
||||
return readEntire(entry, zipFile).then((v) => (originSource = v));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
originSource = originSource || new Buffer(0);
|
||||
if (!originSource) {
|
||||
throw new Error(
|
||||
`Bundle file not found! Please use default bundle file name and path.`,
|
||||
);
|
||||
}
|
||||
|
||||
const copies = {};
|
||||
|
||||
var zipfile = new ZipFile();
|
||||
|
||||
const writePromise = new Promise((resolve, reject) => {
|
||||
zipfile.outputStream.on('error', err => {
|
||||
zipfile.outputStream.on('error', (err) => {
|
||||
throw err;
|
||||
});
|
||||
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', function() {
|
||||
resolve();
|
||||
});
|
||||
zipfile.outputStream
|
||||
.pipe(fs.createWriteStream(output))
|
||||
.on('close', function () {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
await enumZipEntries(next, (entry, nextZipfile) => {
|
||||
@@ -363,9 +412,12 @@ async function diffFromPackage(origin, next, output, originBundleName, transform
|
||||
zipfile.addEmptyDirectory(entry.fileName);
|
||||
} else if (entry.fileName === 'index.bundlejs') {
|
||||
//console.log('Found bundle');
|
||||
return readEntire(entry, nextZipfile).then(newSource => {
|
||||
return readEntire(entry, nextZipfile).then((newSource) => {
|
||||
//console.log('Begin diff');
|
||||
zipfile.addBuffer(diff(originSource, newSource), 'index.bundlejs.patch');
|
||||
zipfile.addBuffer(
|
||||
diff(originSource, newSource),
|
||||
'index.bundlejs.patch',
|
||||
);
|
||||
//console.log('End diff');
|
||||
});
|
||||
} else {
|
||||
@@ -381,7 +433,7 @@ async function diffFromPackage(origin, next, output, originBundleName, transform
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
nextZipfile.openReadStream(entry, function(err, readStream) {
|
||||
nextZipfile.openReadStream(entry, function (err, readStream) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
@@ -395,7 +447,7 @@ async function diffFromPackage(origin, next, output, originBundleName, transform
|
||||
}
|
||||
});
|
||||
|
||||
zipfile.addBuffer(new Buffer(JSON.stringify({ copies })), '__diff.json');
|
||||
zipfile.addBuffer(Buffer.from(JSON.stringify({ copies })), '__diff.json');
|
||||
zipfile.end();
|
||||
await writePromise;
|
||||
}
|
||||
@@ -408,7 +460,7 @@ function enumZipEntries(zipFn, callback) {
|
||||
}
|
||||
zipfile.on('end', resolve);
|
||||
zipfile.on('error', reject);
|
||||
zipfile.on('entry', entry => {
|
||||
zipfile.on('entry', (entry) => {
|
||||
const result = callback(entry, zipfile);
|
||||
if (result && typeof result.then === 'function') {
|
||||
result.then(() => zipfile.readEntry());
|
||||
@@ -421,11 +473,56 @@ function enumZipEntries(zipFn, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
export const commands = {
|
||||
bundle: async function({ options }) {
|
||||
const platform = checkPlatform(options.platform || (await question('Platform(ios/android):')));
|
||||
function diffArgsCheck({ args, options, diffFn }) {
|
||||
const [origin, next] = args;
|
||||
|
||||
let { bundleName, entryFile, intermediaDir, output, dev, verbose } = translateOptions({
|
||||
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(
|
||||
options.platform || (await question('Platform(ios/android):')),
|
||||
);
|
||||
|
||||
let {
|
||||
bundleName,
|
||||
entryFile,
|
||||
intermediaDir,
|
||||
output,
|
||||
dev,
|
||||
verbose,
|
||||
} = translateOptions({
|
||||
...options,
|
||||
platform,
|
||||
});
|
||||
@@ -440,9 +537,16 @@ export const commands = {
|
||||
|
||||
const { version, major, minor } = getRNVersion();
|
||||
|
||||
console.log('Bundling with React Native version: ', version);
|
||||
console.log('Bundling with react-native: ', version);
|
||||
printVersionCommand();
|
||||
|
||||
await runReactNativeBundleCommand(bundleName, dev, entryFile, intermediaDir, platform);
|
||||
await runReactNativeBundleCommand(
|
||||
bundleName,
|
||||
dev,
|
||||
entryFile,
|
||||
intermediaDir,
|
||||
platform,
|
||||
);
|
||||
|
||||
await pack(path.resolve(intermediaDir), realOutput);
|
||||
|
||||
@@ -458,47 +562,78 @@ 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, next, realOutput, 'assets/index.android.bundle');
|
||||
await diffFromPackage(
|
||||
origin,
|
||||
next,
|
||||
realOutput,
|
||||
'assets/index.android.bundle',
|
||||
);
|
||||
console.log(`${realOutput} generated.`);
|
||||
},
|
||||
|
||||
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.`);
|
||||
},
|
||||
|
||||
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', v => {
|
||||
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);
|
||||
return m && m[1];
|
||||
});
|
||||
|
27
src/index.js
27
src/index.js
@@ -5,9 +5,10 @@
|
||||
|
||||
const {loadSession} = require('./api');
|
||||
const updateNotifier = require('update-notifier');
|
||||
import { printVersionCommand } from './utils/index.js';
|
||||
const pkg = require('../package.json');
|
||||
|
||||
updateNotifier({pkg}).notify();
|
||||
updateNotifier({pkg}).notify({isGlobal: true});
|
||||
|
||||
function printUsage({args}) {
|
||||
// const commandName = args[0];
|
||||
@@ -18,25 +19,6 @@ function printUsage({args}) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
function printVersionCommand() {
|
||||
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
|
||||
console.log('react-native-update-cli: ' + pkg.version);
|
||||
try {
|
||||
const PACKAGE_JSON_PATH = path.resolve(
|
||||
process.cwd(),
|
||||
'node_modules',
|
||||
'react-native-update',
|
||||
'package.json'
|
||||
);
|
||||
console.log('react-native-update: ' + require(PACKAGE_JSON_PATH).version);
|
||||
} catch (e) {
|
||||
console.log('react-native-update: n/a - not inside a React Native project directory')
|
||||
}
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
const commands = {
|
||||
...require('./user').commands,
|
||||
...require('./bundle').commands,
|
||||
@@ -47,7 +29,10 @@ const commands = {
|
||||
};
|
||||
|
||||
function run() {
|
||||
printVersionCommand();
|
||||
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
|
||||
printVersionCommand();
|
||||
process.exit();
|
||||
}
|
||||
|
||||
const argv = require('cli-arguments').parse(require('../cli.json'));
|
||||
global.NO_INTERACTIVE = argv.options['no-interactive'];
|
||||
|
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
const { get, post, uploadFile } = require('./api');
|
||||
import { question } from './utils';
|
||||
import { question, saveToLocal } from './utils';
|
||||
|
||||
import { checkPlatform, getSelectedApp } from './app';
|
||||
|
||||
@@ -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,13 +47,30 @@ export async function choosePackage(appId) {
|
||||
}
|
||||
|
||||
export const commands = {
|
||||
uploadIpa: async function({ args }) {
|
||||
uploadIpa: async function ({ args }) {
|
||||
const fn = args[0];
|
||||
if (!fn) {
|
||||
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);
|
||||
|
||||
@@ -60,15 +79,33 @@ export const commands = {
|
||||
hash,
|
||||
buildTime,
|
||||
});
|
||||
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) {
|
||||
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);
|
||||
|
||||
@@ -77,10 +114,27 @@ export const commands = {
|
||||
hash,
|
||||
buildTime,
|
||||
});
|
||||
saveToLocal(fn, `${appId}/package/${id}.apk`);
|
||||
console.log(`Apk uploaded: ${id}`);
|
||||
},
|
||||
packages: async function({ options }) {
|
||||
const platform = checkPlatform(options.platform || (await question('Platform(ios/android):')));
|
||||
parseIpa: async function ({ args }) {
|
||||
const fn = args[0];
|
||||
if (!fn || !fn.endsWith('.ipa')) {
|
||||
throw new Error('Usage: pushy parseIpa <ipaFile>');
|
||||
}
|
||||
console.log(await getIpaInfo(fn));
|
||||
},
|
||||
parseApk: async function ({ args }) {
|
||||
const fn = args[0];
|
||||
if (!fn || !fn.endsWith('.apk')) {
|
||||
throw new Error('Usage: pushy parseApk <apkFile>');
|
||||
}
|
||||
console.log(await getApkInfo(fn));
|
||||
},
|
||||
packages: async function ({ options }) {
|
||||
const platform = checkPlatform(
|
||||
options.platform || (await question('Platform(ios/android):')),
|
||||
);
|
||||
const { appId } = await getSelectedApp(platform);
|
||||
await listPackage(appId);
|
||||
},
|
||||
|
@@ -2,8 +2,10 @@
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs-extra';
|
||||
import fs from 'fs-extra';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
const pkg = require('../../package.json');
|
||||
const AppInfoParser = require('app-info-parser');
|
||||
|
||||
var read = require('read');
|
||||
@@ -29,7 +31,7 @@ export function translateOptions(options) {
|
||||
for (let key in options) {
|
||||
const v = options[key];
|
||||
if (typeof v === 'string') {
|
||||
ret[key] = v.replace(/\$\{(\w+)\}/g, function(v, n) {
|
||||
ret[key] = v.replace(/\$\{(\w+)\}/g, function (v, n) {
|
||||
return options[n] || process.env[n] || v;
|
||||
});
|
||||
} else {
|
||||
@@ -40,7 +42,9 @@ export function translateOptions(options) {
|
||||
}
|
||||
|
||||
export function getRNVersion() {
|
||||
const version = JSON.parse(fs.readFileSync(path.resolve('node_modules/react-native/package.json'))).version;
|
||||
const version = JSON.parse(
|
||||
fs.readFileSync(path.resolve('node_modules/react-native/package.json')),
|
||||
).version;
|
||||
|
||||
// We only care about major and minor version.
|
||||
const match = /^(\d+)\.(\d+)\./.exec(version);
|
||||
@@ -53,6 +57,21 @@ export function getRNVersion() {
|
||||
|
||||
export async function getApkInfo(fn) {
|
||||
const appInfoParser = new AppInfoParser(fn);
|
||||
const bundleFile = await appInfoParser.parser.getEntry(
|
||||
/assets\/index.android.bundle/,
|
||||
);
|
||||
if (!bundleFile) {
|
||||
throw new Error(
|
||||
'找不到bundle文件。请确保此apk为release版本,且bundle文件名为默认的index.android.bundle',
|
||||
);
|
||||
}
|
||||
const updateJsonFile = await appInfoParser.parser.getEntry(
|
||||
/res\/raw\/update.json/,
|
||||
);
|
||||
let appCredential = {};
|
||||
if (updateJsonFile) {
|
||||
appCredential = JSON.parse(updateJsonFile.toString()).android;
|
||||
}
|
||||
const { versionName, application } = await appInfoParser.parse();
|
||||
let buildTime = 0;
|
||||
if (Array.isArray(application.metaData)) {
|
||||
@@ -63,22 +82,73 @@ export async function getApkInfo(fn) {
|
||||
}
|
||||
}
|
||||
if (buildTime == 0) {
|
||||
throw new Error('Can not get build time for this app.');
|
||||
throw new Error(
|
||||
'无法获取此包的编译时间戳。请更新react-native-update到最新版本后重新打包上传。',
|
||||
);
|
||||
}
|
||||
return { versionName, buildTime };
|
||||
return { versionName, buildTime, ...appCredential };
|
||||
}
|
||||
|
||||
export async function getIpaInfo(fn) {
|
||||
const appInfoParser = new AppInfoParser(fn);
|
||||
const { CFBundleShortVersionString: versionName } = await appInfoParser.parse();
|
||||
let buildTimeTxtBuffer = await appInfoParser.parser.getEntry(/payload\/.+?\.app\/pushy_build_time.txt/);
|
||||
const bundleFile = await appInfoParser.parser.getEntry(
|
||||
/payload\/.+?\.app\/main.jsbundle/,
|
||||
);
|
||||
if (!bundleFile) {
|
||||
throw new Error(
|
||||
'找不到bundle文件。请确保此ipa为release版本,且bundle文件名为默认的main.jsbundle',
|
||||
);
|
||||
}
|
||||
const updateJsonFile = await appInfoParser.parser.getEntry(
|
||||
/payload\/.+?\.app\/assets\/update.json/,
|
||||
);
|
||||
let appCredential = {};
|
||||
if (updateJsonFile) {
|
||||
appCredential = JSON.parse(updateJsonFile.toString()).ios;
|
||||
}
|
||||
const {
|
||||
CFBundleShortVersionString: versionName,
|
||||
} = await appInfoParser.parse();
|
||||
let buildTimeTxtBuffer = await appInfoParser.parser.getEntry(
|
||||
/payload\/.+?\.app\/pushy_build_time.txt/,
|
||||
);
|
||||
if (!buildTimeTxtBuffer) {
|
||||
// Not in root bundle when use `use_frameworks`
|
||||
buildTimeTxtBuffer = await appInfoParser.parser.getEntry(/payload\/.+?\.app\/frameworks\/react_native_update.framework\/pushy_build_time.txt/);
|
||||
buildTimeTxtBuffer = await appInfoParser.parser.getEntry(
|
||||
/payload\/.+?\.app\/frameworks\/react_native_update.framework\/pushy_build_time.txt/,
|
||||
);
|
||||
}
|
||||
if (!buildTimeTxtBuffer) {
|
||||
throw new Error('Can not get build time for this app.');
|
||||
throw new Error(
|
||||
'无法获取此包的编译时间戳。请更新react-native-update到最新版本后重新打包上传。',
|
||||
);
|
||||
}
|
||||
const buildTime = buildTimeTxtBuffer.toString().replace('\n', '');
|
||||
return { versionName, buildTime };
|
||||
return { versionName, buildTime, ...appCredential };
|
||||
}
|
||||
|
||||
const localDir = path.resolve(os.homedir(), '.pushy');
|
||||
fs.ensureDirSync(localDir);
|
||||
export function saveToLocal(originPath, destName) {
|
||||
// TODO
|
||||
// const destPath = path.join(localDir, destName);
|
||||
// fs.ensureDirSync(path.dirname(destPath));
|
||||
// fs.copyFileSync(originPath, destPath);
|
||||
}
|
||||
|
||||
export function printVersionCommand() {
|
||||
console.log('react-native-update-cli: ' + pkg.version);
|
||||
try {
|
||||
const PACKAGE_JSON_PATH = path.resolve(
|
||||
process.cwd(),
|
||||
'node_modules',
|
||||
'react-native-update',
|
||||
'package.json',
|
||||
);
|
||||
console.log('react-native-update: ' + require(PACKAGE_JSON_PATH).version);
|
||||
} catch (e) {
|
||||
console.log('react-native-update: 无法获取版本号,请在项目目录中运行命令');
|
||||
}
|
||||
}
|
||||
|
||||
export const pricingPageUrl = 'https://pushy.reactnative.cn/pricing.html';
|
||||
|
@@ -8,7 +8,7 @@ const {
|
||||
put,
|
||||
uploadFile,
|
||||
} = require('./api');
|
||||
import { question } from './utils';
|
||||
import { question, saveToLocal } from './utils';
|
||||
|
||||
import { checkPlatform, getSelectedApp } from './app';
|
||||
import { choosePackage } from './package';
|
||||
@@ -86,6 +86,8 @@ export const commands = {
|
||||
description: description || await question('Enter description:'),
|
||||
metaInfo: metaInfo || await question('Enter meta info:'),
|
||||
});
|
||||
// TODO local diff
|
||||
saveToLocal(fn, `${appId}/ppk/${id}.ppk`);
|
||||
console.log(`Version published: ${id}`);
|
||||
|
||||
const v = await question('Would you like to bind packages to this version?(Y/N)');
|
||||
|
Reference in New Issue
Block a user