mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-17 18:06:10 +08:00
Compare commits
82 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
dae3e4024f | ||
![]() |
d673b5736a | ||
![]() |
732845faad | ||
![]() |
bcfdd67ea8 | ||
![]() |
27ea54c1ec | ||
![]() |
ba0fa836d1 | ||
![]() |
bde76094fc | ||
![]() |
f1d6c3744e | ||
![]() |
768484d7b5 | ||
![]() |
d6632ffcc6 | ||
![]() |
24f5b316a9 | ||
![]() |
03a4108a08 | ||
![]() |
32d7ed9b00 | ||
![]() |
6f3d45c3f2 | ||
![]() |
25cb724921 | ||
![]() |
a7b79a30e8 | ||
![]() |
11799dd0c1 | ||
![]() |
2ab0cad7e5 | ||
![]() |
ec8d6a767b | ||
![]() |
fa8290fcbf | ||
![]() |
46d308c7c2 | ||
![]() |
9e721e1858 | ||
![]() |
c30454976c | ||
![]() |
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 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -104,3 +104,4 @@ dist
|
|||||||
.tern-port
|
.tern-port
|
||||||
|
|
||||||
lib/
|
lib/
|
||||||
|
.DS_Store
|
||||||
|
29
LICENSE
29
LICENSE
@@ -1,29 +0,0 @@
|
|||||||
BSD 3-Clause License
|
|
||||||
|
|
||||||
Copyright (c) 2020, reactnativecn
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer in the documentation
|
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
3. Neither the name of the copyright holder nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
68
cli.json
68
cli.json
@@ -2,15 +2,11 @@
|
|||||||
"useCommand": true,
|
"useCommand": true,
|
||||||
"defaultCommand": "help",
|
"defaultCommand": "help",
|
||||||
"commands": {
|
"commands": {
|
||||||
"help": {
|
"help": {},
|
||||||
},
|
|
||||||
|
|
||||||
"login":{
|
"login": {},
|
||||||
},
|
"logout": {},
|
||||||
"logout": {
|
"me": {},
|
||||||
},
|
|
||||||
"me": {
|
|
||||||
},
|
|
||||||
|
|
||||||
"createApp": {
|
"createApp": {
|
||||||
"options": {
|
"options": {
|
||||||
@@ -29,8 +25,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"deleteApp": {
|
"deleteApp": {},
|
||||||
},
|
|
||||||
"selectApp": {
|
"selectApp": {
|
||||||
"options": {
|
"options": {
|
||||||
"platform": {
|
"platform": {
|
||||||
@@ -39,10 +34,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"uploadIpa": {
|
"uploadIpa": {},
|
||||||
},
|
"uploadApk": {},
|
||||||
"uploadApk": {
|
"parseIpa": {},
|
||||||
},
|
"parseApk": {},
|
||||||
"packages": {
|
"packages": {
|
||||||
"options": {
|
"options": {
|
||||||
"platform": {
|
"platform": {
|
||||||
@@ -85,6 +80,10 @@
|
|||||||
},
|
},
|
||||||
"packageId": {
|
"packageId": {
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
|
},
|
||||||
|
|
||||||
|
"packageVersion": {
|
||||||
|
"hasValue": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -111,16 +110,14 @@
|
|||||||
"hasValue": true
|
"hasValue": true
|
||||||
},
|
},
|
||||||
"intermediaDir": {
|
"intermediaDir": {
|
||||||
"default": "build/intermedia/${platform}",
|
"default": ".pushy/intermedia/${platform}",
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"default": "build/output/${platform}.${time}.ppk",
|
"default": ".pushy/output/${platform}.${time}.ppk",
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
},
|
},
|
||||||
"verbose": {
|
"verbose": {}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"release": {
|
"release": {
|
||||||
@@ -130,7 +127,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,7 +136,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,7 +145,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
package.json
15
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update-cli",
|
"name": "react-native-update-cli",
|
||||||
"version": "1.0.9",
|
"version": "1.8.1",
|
||||||
"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": {
|
||||||
@@ -32,24 +32,23 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/reactnativecn/react-native-pushy/tree/master/react-native-pushy-cli",
|
"homepage": "https://github.com/reactnativecn/react-native-pushy/tree/master/react-native-pushy-cli",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"app-info-parser": "^0.3.9",
|
"app-info-parser": "^1.0.0",
|
||||||
"cli-arguments": "^0.2.1",
|
"cli-arguments": "^0.2.1",
|
||||||
"fs-extra": "^8.1.0",
|
"filesize-parser": "^1.5.0",
|
||||||
|
"fs-extra": "8",
|
||||||
"gradle-to-js": "^2.0.0",
|
"gradle-to-js": "^2.0.0",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.1",
|
||||||
"progress": "^2.0.3",
|
"progress": "^2.0.3",
|
||||||
"read": "^1.0.7",
|
"read": "^1.0.7",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"tcp-ping": "^0.1.1",
|
"tcp-ping": "^0.1.1",
|
||||||
"tty-table": "2.8",
|
"tty-table": "4.1",
|
||||||
"uid-safe": "^2.1.5",
|
"update-notifier": "^4.1.1",
|
||||||
"update-notifier": "^4.1.0",
|
|
||||||
"yauzl": "^2.10.0",
|
"yauzl": "^2.10.0",
|
||||||
"yazl": "2.5.1"
|
"yazl": "2.5.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-cli": "^6.26.0",
|
"babel-cli": "^6.26.0",
|
||||||
"babel-eslint": "^10.1.0",
|
|
||||||
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
|
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
|
||||||
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
|
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
|
||||||
"babel-plugin-transform-es2015-spread": "^6.22.0",
|
"babel-plugin-transform-es2015-spread": "^6.22.0",
|
||||||
|
3035
pnpm-lock.yaml
generated
Normal file
3035
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
48
src/api.js
48
src/api.js
@@ -1,15 +1,15 @@
|
|||||||
/**
|
|
||||||
* Created by tdzl2003 on 2/13/16.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
let host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn/api';
|
const defaultEndpoint = 'http://u.reactnative.cn/api';
|
||||||
const fs = require('fs-extra');
|
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
||||||
|
const fs = require('fs');
|
||||||
import request from 'request';
|
import request from 'request';
|
||||||
import ProgressBar from 'progress';
|
import ProgressBar from 'progress';
|
||||||
const packageJson = require('../package.json');
|
const packageJson = require('../package.json');
|
||||||
const tcpp = require('tcp-ping');
|
const tcpp = require('tcp-ping');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
const path = require('path');
|
||||||
|
import filesizeParser from 'filesize-parser';
|
||||||
|
import { pricingPageUrl } from './utils';
|
||||||
|
|
||||||
const tcpPing = util.promisify(tcpp.ping);
|
const tcpPing = util.promisify(tcpp.ping);
|
||||||
|
|
||||||
@@ -56,12 +56,19 @@ exports.closeSession = function() {
|
|||||||
savedSession = undefined;
|
savedSession = undefined;
|
||||||
}
|
}
|
||||||
session = undefined;
|
session = undefined;
|
||||||
host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn';
|
host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function query(url, options) {
|
async function query(url, options) {
|
||||||
const resp = await fetch(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) {
|
if (resp.status !== 200) {
|
||||||
throw Object.assign(new Error(json.message || json.error), {
|
throw Object.assign(new Error(json.message || json.error), {
|
||||||
status: resp.status,
|
status: resp.status,
|
||||||
@@ -102,10 +109,15 @@ exports.put = queryWithBody('PUT');
|
|||||||
exports.doDelete = queryWithBody('DELETE');
|
exports.doDelete = queryWithBody('DELETE');
|
||||||
|
|
||||||
async function uploadFile(fn, key) {
|
async function uploadFile(fn, key) {
|
||||||
const { url, backupUrl, formData } = await exports.post('/upload', {});
|
const { url, backupUrl, formData, maxSize } = await exports.post('/upload', {
|
||||||
|
ext: path.extname(fn),
|
||||||
|
});
|
||||||
let realUrl = url;
|
let realUrl = url;
|
||||||
|
|
||||||
if (backupUrl) {
|
if (backupUrl) {
|
||||||
|
if (global.USE_ACC_OSS) {
|
||||||
|
realUrl = backupUrl;
|
||||||
|
} else {
|
||||||
const pingResult = await tcpPing({
|
const pingResult = await tcpPing({
|
||||||
address: url.replace('https://', ''),
|
address: url.replace('https://', ''),
|
||||||
attempts: 4,
|
attempts: 4,
|
||||||
@@ -115,12 +127,20 @@ async function uploadFile(fn, key) {
|
|||||||
if (isNaN(pingResult.avg) || pingResult.avg > 150) {
|
if (isNaN(pingResult.avg) || pingResult.avg > 150) {
|
||||||
realUrl = backupUrl;
|
realUrl = backupUrl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// console.log({realUrl});
|
// console.log({realUrl});
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileSize = fs.statSync(fn).size;
|
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', {
|
const bar = new ProgressBar(' 上传中 [:bar] :percent :etas', {
|
||||||
complete: '=',
|
complete: '=',
|
||||||
incomplete: ' ',
|
incomplete: ' ',
|
||||||
total: fileSize,
|
total: fileSize,
|
||||||
@@ -149,13 +169,7 @@ async function uploadFile(fn, key) {
|
|||||||
Object.assign(new Error(body), { status: resp.statusCode }),
|
Object.assign(new Error(body), { status: resp.statusCode }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
resolve(
|
resolve({ hash: formData.key });
|
||||||
body
|
|
||||||
? // qiniu
|
|
||||||
JSON.parse(body)
|
|
||||||
: // aliyun oss
|
|
||||||
{ hash: formData.key },
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
77
src/app.js
77
src/app.js
@@ -1,15 +1,8 @@
|
|||||||
/**
|
|
||||||
* Created by tdzl2003 on 2/13/16.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { question } from './utils';
|
import { question } from './utils';
|
||||||
import * as fs from 'fs-extra';
|
import fs from 'fs';
|
||||||
|
const Table = require('tty-table');
|
||||||
|
|
||||||
const {
|
const { post, get, doDelete } = require('./api');
|
||||||
post,
|
|
||||||
get,
|
|
||||||
doDelete,
|
|
||||||
} = require('./api');
|
|
||||||
|
|
||||||
const validPlatforms = {
|
const validPlatforms = {
|
||||||
ios: 1,
|
ios: 1,
|
||||||
@@ -18,34 +11,48 @@ const validPlatforms = {
|
|||||||
|
|
||||||
export function checkPlatform(platform) {
|
export function checkPlatform(platform) {
|
||||||
if (!validPlatforms[platform]) {
|
if (!validPlatforms[platform]) {
|
||||||
throw new Error(`Invalid platform '${platform}'`);
|
throw new Error(`无法识别的平台 '${platform}'`);
|
||||||
}
|
}
|
||||||
return platform
|
return platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSelectedApp(platform) {
|
export function getSelectedApp(platform) {
|
||||||
checkPlatform(platform);
|
checkPlatform(platform);
|
||||||
|
|
||||||
if (!fs.existsSync('update.json')) {
|
if (!fs.existsSync('update.json')) {
|
||||||
throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
|
throw new Error(
|
||||||
|
`App not selected. run 'pushy selectApp --platform ${platform}' first!`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
const updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
||||||
if (!updateInfo[platform]) {
|
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];
|
return updateInfo[platform];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listApp(platform) {
|
export async function listApp(platform) {
|
||||||
const { data } = await get('/app/list');
|
const { data } = await get('/app/list');
|
||||||
const list = platform?data.filter(v=>v.platform===platform):data;
|
const list = platform ? data.filter((v) => v.platform === platform) : data;
|
||||||
|
|
||||||
|
const header = [
|
||||||
|
{ value: '应用 id' },
|
||||||
|
{ value: '应用名称' },
|
||||||
|
{ value: '平台' },
|
||||||
|
];
|
||||||
|
const rows = [];
|
||||||
for (const app of list) {
|
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) {
|
if (platform) {
|
||||||
console.log(`\nTotal ${list.length} ${platform} apps`);
|
console.log(`\共 ${list.length} ${platform} 个应用`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`\nTotal ${list.length} apps`);
|
console.log(`\共 ${list.length} 个应用`);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -54,8 +61,8 @@ export async function chooseApp(platform) {
|
|||||||
const list = await listApp(platform);
|
const list = await listApp(platform);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const id = await question('Enter appId:');
|
const id = await question('输入应用 id:');
|
||||||
const app = list.find(v=>v.id === (id|0));
|
const app = list.find((v) => v.id === (id | 0));
|
||||||
if (app) {
|
if (app) {
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
@@ -64,11 +71,13 @@ export async function chooseApp(platform) {
|
|||||||
|
|
||||||
export const commands = {
|
export const commands = {
|
||||||
createApp: async function ({ options }) {
|
createApp: async function ({ options }) {
|
||||||
const name = options.name || await question('App Name:');
|
const name = options.name || (await question('应用名称:'));
|
||||||
const { downloadUrl } = options;
|
const { downloadUrl } = options;
|
||||||
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
const platform = checkPlatform(
|
||||||
|
options.platform || (await question('平台(ios/android):')),
|
||||||
|
);
|
||||||
const { id } = await post('/app/create', { name, platform });
|
const { id } = await post('/app/create', { name, platform });
|
||||||
console.log(`Created app ${id}`);
|
console.log(`已成功创建应用(id: ${id})`);
|
||||||
await this.selectApp({
|
await this.selectApp({
|
||||||
args: [id],
|
args: [id],
|
||||||
options: { platform, downloadUrl },
|
options: { platform, downloadUrl },
|
||||||
@@ -78,25 +87,29 @@ export const commands = {
|
|||||||
const { platform } = options;
|
const { platform } = options;
|
||||||
const id = args[0] || chooseApp(platform);
|
const id = args[0] || chooseApp(platform);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
console.log('Canceled');
|
console.log('已取消');
|
||||||
}
|
}
|
||||||
await doDelete(`/app/${id}`);
|
await doDelete(`/app/${id}`);
|
||||||
console.log('Ok.');
|
console.log('操作成功');
|
||||||
},
|
},
|
||||||
apps: async function ({ options }) {
|
apps: async function ({ options }) {
|
||||||
const { platform } = options;
|
const { platform } = options;
|
||||||
listApp(platform);
|
listApp(platform);
|
||||||
},
|
},
|
||||||
selectApp: async function ({ args, options }) {
|
selectApp: async function ({ args, options }) {
|
||||||
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
const platform = checkPlatform(
|
||||||
const id = args[0] || (await chooseApp(platform)).id;
|
options.platform || (await question('平台(ios/android):')),
|
||||||
|
);
|
||||||
|
const id = args[0] ? parseInt(args[0]) : (await chooseApp(platform)).id;
|
||||||
|
|
||||||
let updateInfo = {};
|
let updateInfo = {};
|
||||||
if (fs.existsSync('update.json')) {
|
if (fs.existsSync('update.json')) {
|
||||||
try {
|
try {
|
||||||
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
||||||
} catch (e) {
|
} 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;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,6 +118,10 @@ export const commands = {
|
|||||||
appId: id,
|
appId: id,
|
||||||
appKey,
|
appKey,
|
||||||
};
|
};
|
||||||
fs.writeFileSync('update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
|
fs.writeFileSync(
|
||||||
|
'update.json',
|
||||||
|
JSON.stringify(updateInfo, null, 4),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
306
src/bundle.js
306
src/bundle.js
@@ -1,40 +1,22 @@
|
|||||||
/**
|
|
||||||
* Created by tdzl2003 on 2/22/16.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
import { getRNVersion, translateOptions } from './utils';
|
import { getRNVersion, translateOptions } from './utils';
|
||||||
import * as fs from 'fs-extra';
|
import * as fs from 'fs-extra';
|
||||||
import { ZipFile } from 'yazl';
|
import { ZipFile } from 'yazl';
|
||||||
import { open as openZipFile } from 'yauzl';
|
import { open as openZipFile } from 'yauzl';
|
||||||
import { question } from './utils';
|
import { question, printVersionCommand } from './utils';
|
||||||
import { checkPlatform } from './app';
|
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 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() {
|
|
||||||
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) {
|
try {
|
||||||
const commandResult = spawnSync(command, {
|
hdiff = require('node-hdiffpatch').diff;
|
||||||
shell: true,
|
} catch (e) {}
|
||||||
stdio: 'inherit',
|
|
||||||
});
|
|
||||||
if (commandResult.error) {
|
|
||||||
throw commandResult.error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runReactNativeBundleCommand(
|
async function runReactNativeBundleCommand(
|
||||||
bundleName,
|
bundleName,
|
||||||
@@ -45,19 +27,30 @@ async function runReactNativeBundleCommand(
|
|||||||
sourcemapOutput,
|
sourcemapOutput,
|
||||||
config,
|
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 reactNativeBundleArgs = [];
|
||||||
|
|
||||||
let envArgs = process.env.PUSHY_ENV_ARGS;
|
let envArgs = process.env.PUSHY_ENV_ARGS;
|
||||||
|
|
||||||
if (envArgs) {
|
if (envArgs) {
|
||||||
Array.prototype.push.apply(reactNativeBundleArgs, envArgs.trim().split(/\s+/));
|
Array.prototype.push.apply(
|
||||||
|
reactNativeBundleArgs,
|
||||||
|
envArgs.trim().split(/\s+/),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.emptyDirSync(outputFolder);
|
fs.emptyDirSync(outputFolder);
|
||||||
|
|
||||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||||
path.join("node_modules", "react-native", "local-cli", "cli.js"),
|
path.join('node_modules', 'react-native', 'local-cli', 'cli.js'),
|
||||||
"bundle",
|
'bundle',
|
||||||
'--assets-dest',
|
'--assets-dest',
|
||||||
outputFolder,
|
outputFolder,
|
||||||
'--bundle-output',
|
'--bundle-output',
|
||||||
@@ -80,22 +73,28 @@ async function runReactNativeBundleCommand(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const reactNativeBundleProcess = spawn('node', reactNativeBundleArgs);
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
reactNativeBundleProcess.stdout.on('data', data => {
|
reactNativeBundleProcess.stdout.on('data', (data) => {
|
||||||
console.log(data.toString().trim());
|
console.log(data.toString().trim());
|
||||||
});
|
});
|
||||||
|
|
||||||
reactNativeBundleProcess.stderr.on('data', data => {
|
reactNativeBundleProcess.stderr.on('data', (data) => {
|
||||||
console.error(data.toString().trim());
|
console.error(data.toString().trim());
|
||||||
});
|
});
|
||||||
|
|
||||||
reactNativeBundleProcess.on('close', async exitCode => {
|
reactNativeBundleProcess.on('close', async (exitCode) => {
|
||||||
if (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 {
|
} else {
|
||||||
if (platform === 'android') {
|
if (gradleConfig.enableHermes) {
|
||||||
await compileHermesByteCode(bundleName, outputFolder);
|
await compileHermesByteCode(bundleName, outputFolder);
|
||||||
}
|
}
|
||||||
resolve(null);
|
resolve(null);
|
||||||
@@ -110,29 +109,52 @@ function getHermesOSBin() {
|
|||||||
if (os.platform() === 'linux') return 'linux64-bin';
|
if (os.platform() === 'linux') return 'linux64-bin';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compileHermesByteCode(bundleName, outputFolder) {
|
async function checkGradleConfig() {
|
||||||
let enableHermes = false;
|
let enableHermes = false;
|
||||||
|
let crunchPngs;
|
||||||
try {
|
try {
|
||||||
const gradleConfig = await g2js.parseFile('android/app/build.gradle');
|
const gradleConfig = await g2js.parseFile('android/app/build.gradle');
|
||||||
const projectConfig = gradleConfig['project.ext.react'];
|
const projectConfig = gradleConfig['project.ext.react'];
|
||||||
for (const packagerConfig of projectConfig) {
|
for (const packagerConfig of projectConfig) {
|
||||||
if (packagerConfig.includes('enableHermes') && packagerConfig.includes('true')) {
|
if (
|
||||||
|
packagerConfig.includes('enableHermes') &&
|
||||||
|
packagerConfig.includes('true')
|
||||||
|
) {
|
||||||
enableHermes = true;
|
enableHermes = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
crunchPngs = gradleConfig.android.buildTypes.release.crunchPngs;
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
if (enableHermes) {
|
return {
|
||||||
|
enableHermes,
|
||||||
|
crunchPngs,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function compileHermesByteCode(bundleName, outputFolder) {
|
||||||
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
|
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
|
||||||
const hermesPath = fs.existsSync('node_modules/hermes-engine')
|
const hermesPackage = fs.existsSync('node_modules/hermes-engine')
|
||||||
? 'node_modules/hermes-engine'
|
? 'node_modules/hermes-engine' // 0.2+
|
||||||
: 'node_modules/hermesvm';
|
: 'node_modules/hermesvm'; // < 0.2
|
||||||
execSync(
|
const hermesPath = `${hermesPackage}/${getHermesOSBin()}`;
|
||||||
`${hermesPath}/${getHermesOSBin()}/hermes -emit-binary -out ${outputFolder}/${bundleName} ${outputFolder}/${bundleName} -O`,
|
|
||||||
|
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' },
|
{ stdio: 'ignore' },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function pack(dir, output) {
|
async function pack(dir, output) {
|
||||||
console.log('Packing');
|
console.log('Packing');
|
||||||
@@ -163,13 +185,15 @@ async function pack(dir, output) {
|
|||||||
|
|
||||||
addDirectory(dir, '');
|
addDirectory(dir, '');
|
||||||
|
|
||||||
zipfile.outputStream.on('error', err => reject(err));
|
zipfile.outputStream.on('error', (err) => reject(err));
|
||||||
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', function() {
|
zipfile.outputStream
|
||||||
|
.pipe(fs.createWriteStream(output))
|
||||||
|
.on('close', function () {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
zipfile.end();
|
zipfile.end();
|
||||||
});
|
});
|
||||||
console.log('Bundled saved to: ' + output);
|
console.log('ppk热更包已生成并保存到: ' + output);
|
||||||
}
|
}
|
||||||
|
|
||||||
function readEntire(entry, zipFile) {
|
function readEntire(entry, zipFile) {
|
||||||
@@ -213,13 +237,15 @@ async function diffFromPPK(origin, next, output) {
|
|||||||
|
|
||||||
if (entry.fileName === 'index.bundlejs') {
|
if (entry.fileName === 'index.bundlejs') {
|
||||||
// This is source.
|
// This is source.
|
||||||
return readEntire(entry, zipFile).then(v => (originSource = v));
|
return readEntire(entry, zipFile).then((v) => (originSource = v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!originSource) {
|
if (!originSource) {
|
||||||
throw new Error(`Bundle file not found! Please use default bundle file name and path.`);
|
throw new Error(
|
||||||
|
`Bundle file not found! Please use default bundle file name and path.`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const copies = {};
|
const copies = {};
|
||||||
@@ -227,10 +253,12 @@ async function diffFromPPK(origin, next, output) {
|
|||||||
var zipfile = new ZipFile();
|
var zipfile = new ZipFile();
|
||||||
|
|
||||||
const writePromise = new Promise((resolve, reject) => {
|
const writePromise = new Promise((resolve, reject) => {
|
||||||
zipfile.outputStream.on('error', err => {
|
zipfile.outputStream.on('error', (err) => {
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', function() {
|
zipfile.outputStream
|
||||||
|
.pipe(fs.createWriteStream(output))
|
||||||
|
.on('close', function () {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -261,9 +289,12 @@ async function diffFromPPK(origin, next, output) {
|
|||||||
}
|
}
|
||||||
} else if (entry.fileName === 'index.bundlejs') {
|
} else if (entry.fileName === 'index.bundlejs') {
|
||||||
//console.log('Found bundle');
|
//console.log('Found bundle');
|
||||||
return readEntire(entry, nextZipfile).then(newSource => {
|
return readEntire(entry, nextZipfile).then((newSource) => {
|
||||||
//console.log('Begin diff');
|
//console.log('Begin diff');
|
||||||
zipfile.addBuffer(diff(originSource, newSource), 'index.bundlejs.patch');
|
zipfile.addBuffer(
|
||||||
|
diff(originSource, newSource),
|
||||||
|
'index.bundlejs.patch',
|
||||||
|
);
|
||||||
//console.log('End diff');
|
//console.log('End diff');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -312,12 +343,21 @@ async function diffFromPPK(origin, next, output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//console.log({copies, deletes});
|
//console.log({copies, deletes});
|
||||||
zipfile.addBuffer(Buffer.from(JSON.stringify({ copies, deletes })), '__diff.json');
|
zipfile.addBuffer(
|
||||||
|
Buffer.from(JSON.stringify({ copies, deletes })),
|
||||||
|
'__diff.json',
|
||||||
|
);
|
||||||
zipfile.end();
|
zipfile.end();
|
||||||
await writePromise;
|
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));
|
fs.ensureDirSync(path.dirname(output));
|
||||||
|
|
||||||
const originEntries = {};
|
const originEntries = {};
|
||||||
@@ -339,13 +379,15 @@ async function diffFromPackage(origin, next, output, originBundleName, transform
|
|||||||
|
|
||||||
if (fn === originBundleName) {
|
if (fn === originBundleName) {
|
||||||
// This is source.
|
// This is source.
|
||||||
return readEntire(entry, zipFile).then(v => (originSource = v));
|
return readEntire(entry, zipFile).then((v) => (originSource = v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!originSource) {
|
if (!originSource) {
|
||||||
throw new Error(`Bundle file not found! Please use default bundle file name and path.`);
|
throw new Error(
|
||||||
|
`Bundle file not found! Please use default bundle file name and path.`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const copies = {};
|
const copies = {};
|
||||||
@@ -353,10 +395,12 @@ async function diffFromPackage(origin, next, output, originBundleName, transform
|
|||||||
var zipfile = new ZipFile();
|
var zipfile = new ZipFile();
|
||||||
|
|
||||||
const writePromise = new Promise((resolve, reject) => {
|
const writePromise = new Promise((resolve, reject) => {
|
||||||
zipfile.outputStream.on('error', err => {
|
zipfile.outputStream.on('error', (err) => {
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', function() {
|
zipfile.outputStream
|
||||||
|
.pipe(fs.createWriteStream(output))
|
||||||
|
.on('close', function () {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -367,9 +411,12 @@ async function diffFromPackage(origin, next, output, originBundleName, transform
|
|||||||
zipfile.addEmptyDirectory(entry.fileName);
|
zipfile.addEmptyDirectory(entry.fileName);
|
||||||
} else if (entry.fileName === 'index.bundlejs') {
|
} else if (entry.fileName === 'index.bundlejs') {
|
||||||
//console.log('Found bundle');
|
//console.log('Found bundle');
|
||||||
return readEntire(entry, nextZipfile).then(newSource => {
|
return readEntire(entry, nextZipfile).then((newSource) => {
|
||||||
//console.log('Begin diff');
|
//console.log('Begin diff');
|
||||||
zipfile.addBuffer(diff(originSource, newSource), 'index.bundlejs.patch');
|
zipfile.addBuffer(
|
||||||
|
diff(originSource, newSource),
|
||||||
|
'index.bundlejs.patch',
|
||||||
|
);
|
||||||
//console.log('End diff');
|
//console.log('End diff');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -412,7 +459,7 @@ function enumZipEntries(zipFn, callback) {
|
|||||||
}
|
}
|
||||||
zipfile.on('end', resolve);
|
zipfile.on('end', resolve);
|
||||||
zipfile.on('error', reject);
|
zipfile.on('error', reject);
|
||||||
zipfile.on('entry', entry => {
|
zipfile.on('entry', (entry) => {
|
||||||
const result = callback(entry, zipfile);
|
const result = callback(entry, zipfile);
|
||||||
if (result && typeof result.then === 'function') {
|
if (result && typeof result.then === 'function') {
|
||||||
result.then(() => zipfile.readEntry());
|
result.then(() => zipfile.readEntry());
|
||||||
@@ -425,11 +472,56 @@ 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(options.platform || (await question('Platform(ios/android):')));
|
const platform = checkPlatform(
|
||||||
|
options.platform || (await question('平台(ios/android):')),
|
||||||
|
);
|
||||||
|
|
||||||
let { bundleName, entryFile, intermediaDir, output, dev, verbose } = translateOptions({
|
let {
|
||||||
|
bundleName,
|
||||||
|
entryFile,
|
||||||
|
intermediaDir,
|
||||||
|
output,
|
||||||
|
dev,
|
||||||
|
verbose,
|
||||||
|
} = translateOptions({
|
||||||
...options,
|
...options,
|
||||||
platform,
|
platform,
|
||||||
});
|
});
|
||||||
@@ -444,13 +536,20 @@ export const commands = {
|
|||||||
|
|
||||||
const { version, major, minor } = getRNVersion();
|
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);
|
await pack(path.resolve(intermediaDir), realOutput);
|
||||||
|
|
||||||
const v = await question('Would you like to publish it?(Y/N)');
|
const v = await question('是否现在上传此热更包?(Y/N)');
|
||||||
if (v.toLowerCase() === 'y') {
|
if (v.toLowerCase() === 'y') {
|
||||||
await this.publish({
|
await this.publish({
|
||||||
args: [realOutput],
|
args: [realOutput],
|
||||||
@@ -462,47 +561,74 @@ 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(origin, next, realOutput, 'assets/index.android.bundle');
|
await diffFromPackage(
|
||||||
|
origin,
|
||||||
|
next,
|
||||||
|
realOutput,
|
||||||
|
'assets/index.android.bundle',
|
||||||
|
);
|
||||||
console.log(`${realOutput} generated.`);
|
console.log(`${realOutput} generated.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
const m = /^Payload\/[^/]+\/(.+)$/.exec(v);
|
||||||
return m && m[1];
|
return m && m[1];
|
||||||
});
|
});
|
||||||
|
41
src/index.js
41
src/index.js
@@ -1,40 +1,21 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
/**
|
|
||||||
* Created by tdzl2003 on 2/13/16.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const { loadSession } = require('./api');
|
const { loadSession } = require('./api');
|
||||||
const updateNotifier = require('update-notifier');
|
const updateNotifier = require('update-notifier');
|
||||||
|
import { printVersionCommand } from './utils/index.js';
|
||||||
const pkg = require('../package.json');
|
const pkg = require('../package.json');
|
||||||
|
|
||||||
updateNotifier({pkg}).notify();
|
updateNotifier({ pkg }).notify({ isGlobal: true });
|
||||||
|
|
||||||
function printUsage({ args }) {
|
function printUsage({ args }) {
|
||||||
// const commandName = args[0];
|
// const commandName = args[0];
|
||||||
// TODO: print usage of commandName, or print global usage.
|
// TODO: print usage of commandName, or print global usage.
|
||||||
|
|
||||||
console.log('Usage is under development now.')
|
console.log('Usage is under development now.');
|
||||||
console.log('Visit `https://github.com/reactnativecn/react-native-pushy` for early document.');
|
console.log(
|
||||||
process.exit(1);
|
'Visit `https://github.com/reactnativecn/react-native-pushy` for early document.',
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
process.exit(1);
|
||||||
} catch (e) {
|
|
||||||
console.log('react-native-update: n/a - not inside a React Native project directory')
|
|
||||||
}
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const commands = {
|
const commands = {
|
||||||
@@ -47,21 +28,25 @@ const commands = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
|
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
|
||||||
printVersionCommand();
|
printVersionCommand();
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
const argv = require('cli-arguments').parse(require('../cli.json'));
|
const argv = require('cli-arguments').parse(require('../cli.json'));
|
||||||
global.NO_INTERACTIVE = argv.options['no-interactive'];
|
global.NO_INTERACTIVE = argv.options['no-interactive'];
|
||||||
|
global.USE_ACC_OSS = argv.options['acc'];
|
||||||
|
|
||||||
loadSession()
|
loadSession()
|
||||||
.then(() => commands[argv.command](argv))
|
.then(() => commands[argv.command](argv))
|
||||||
.catch(err=>{
|
.catch((err) => {
|
||||||
if (err.status === 401) {
|
if (err.status === 401) {
|
||||||
console.log('Not loggined.\nRun `pushy login` at your project directory to login.');
|
console.log('尚未登录。\n请在项目目录中运行`pushy login`命令来登录');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
run();
|
run();
|
@@ -8,31 +8,34 @@ import { question, saveToLocal } from './utils';
|
|||||||
import { checkPlatform, getSelectedApp } from './app';
|
import { checkPlatform, getSelectedApp } from './app';
|
||||||
|
|
||||||
import { getApkInfo, getIpaInfo } from './utils';
|
import { getApkInfo, getIpaInfo } from './utils';
|
||||||
|
|
||||||
import uid from 'uid-safe';
|
|
||||||
const uidSync = uid.sync;
|
|
||||||
|
|
||||||
const Table = require('tty-table');
|
const Table = require('tty-table');
|
||||||
|
|
||||||
export async function listPackage(appId) {
|
export async function listPackage(appId) {
|
||||||
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
||||||
|
|
||||||
const header = [{ value: 'Package Id' }, { value: 'Version' }];
|
const header = [{ value: '原生包 Id' }, { value: '原生版本' }];
|
||||||
const rows = [];
|
const rows = [];
|
||||||
for (const pkg of data) {
|
for (const pkg of data) {
|
||||||
const { version } = pkg;
|
const { version } = pkg;
|
||||||
let versionInfo = '';
|
let versionInfo = '';
|
||||||
if (version) {
|
if (version) {
|
||||||
versionInfo = ` - ${version.id} ${version.hash.slice(0, 8)} ${version.name}`;
|
versionInfo = `, 已绑定:${version.name} (${version.id})`;
|
||||||
} else {
|
} else {
|
||||||
versionInfo = ' (newest)';
|
// versionInfo = ' (newest)';
|
||||||
}
|
}
|
||||||
|
let output = pkg.name;
|
||||||
rows.push([pkg.id, `${pkg.name}(${pkg.status})${versionInfo}`]);
|
if (pkg.status === 'paused') {
|
||||||
|
output += '(已暂停)';
|
||||||
|
}
|
||||||
|
if (pkg.status === 'expired') {
|
||||||
|
output += '(已过期)';
|
||||||
|
}
|
||||||
|
output += versionInfo;
|
||||||
|
rows.push([pkg.id, output]);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(Table(header, rows).render());
|
console.log(Table(header, rows).render());
|
||||||
console.log(`\nTotal ${data.length} package(s).`);
|
console.log(`\n共 ${data.length} 个包`);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,8 +43,8 @@ export async function choosePackage(appId) {
|
|||||||
const list = await listPackage(appId);
|
const list = await listPackage(appId);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const id = await question('Enter Package Id:');
|
const id = await question('输入原生包 id:');
|
||||||
const app = list.find(v => v.id === (id | 0));
|
const app = list.find((v) => v.id === (id | 0));
|
||||||
if (app) {
|
if (app) {
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
@@ -52,12 +55,29 @@ export const commands = {
|
|||||||
uploadIpa: async function ({ args }) {
|
uploadIpa: async function ({ args }) {
|
||||||
const fn = args[0];
|
const fn = args[0];
|
||||||
if (!fn || !fn.endsWith('.ipa')) {
|
if (!fn || !fn.endsWith('.ipa')) {
|
||||||
throw new Error('Usage: pushy uploadIpa <ipaFile>');
|
throw new Error('使用方法: pushy uploadIpa ipa后缀文件');
|
||||||
}
|
}
|
||||||
const { versionName, buildTime } = await getIpaInfo(fn);
|
const {
|
||||||
const { appId } = await getSelectedApp('ios');
|
versionName,
|
||||||
|
buildTime,
|
||||||
|
appId: appIdInPkg,
|
||||||
|
appKey: appKeyInPkg,
|
||||||
|
} = await getIpaInfo(fn);
|
||||||
|
const { appId, appKey } = await getSelectedApp('ios');
|
||||||
|
|
||||||
const { hash } = await uploadFile(fn, `i/${uidSync(19)}`);
|
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);
|
||||||
|
|
||||||
const { id } = await post(`/app/${appId}/package/create`, {
|
const { id } = await post(`/app/${appId}/package/create`, {
|
||||||
name: versionName,
|
name: versionName,
|
||||||
@@ -65,17 +85,34 @@ export const commands = {
|
|||||||
buildTime,
|
buildTime,
|
||||||
});
|
});
|
||||||
saveToLocal(fn, `${appId}/package/${id}.ipa`);
|
saveToLocal(fn, `${appId}/package/${id}.ipa`);
|
||||||
console.log(`Ipa uploaded: ${id}`);
|
console.log(`已成功上传ipa原生包(id: ${id})`);
|
||||||
},
|
},
|
||||||
uploadApk: async function ({ args }) {
|
uploadApk: async function ({ args }) {
|
||||||
const fn = args[0];
|
const fn = args[0];
|
||||||
if (!fn || !fn.endsWith('.apk')) {
|
if (!fn || !fn.endsWith('.apk')) {
|
||||||
throw new Error('Usage: pushy uploadApk <apkFile>');
|
throw new Error('使用方法: pushy uploadApk apk后缀文件');
|
||||||
}
|
}
|
||||||
const { versionName, buildTime } = await getApkInfo(fn);
|
const {
|
||||||
const { appId } = await getSelectedApp('android');
|
versionName,
|
||||||
|
buildTime,
|
||||||
|
appId: appIdInPkg,
|
||||||
|
appKey: appKeyInPkg,
|
||||||
|
} = await getApkInfo(fn);
|
||||||
|
const { appId, appKey } = await getSelectedApp('android');
|
||||||
|
|
||||||
const { hash } = await uploadFile(fn, `a/${uidSync(19)}`);
|
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);
|
||||||
|
|
||||||
const { id } = await post(`/app/${appId}/package/create`, {
|
const { id } = await post(`/app/${appId}/package/create`, {
|
||||||
name: versionName,
|
name: versionName,
|
||||||
@@ -83,10 +120,26 @@ export const commands = {
|
|||||||
buildTime,
|
buildTime,
|
||||||
});
|
});
|
||||||
saveToLocal(fn, `${appId}/package/${id}.apk`);
|
saveToLocal(fn, `${appId}/package/${id}.apk`);
|
||||||
console.log(`Apk uploaded: ${id}`);
|
console.log(`已成功上传apk原生包(id: ${id})`);
|
||||||
|
},
|
||||||
|
parseIpa: async function ({ args }) {
|
||||||
|
const fn = args[0];
|
||||||
|
if (!fn || !fn.endsWith('.ipa')) {
|
||||||
|
throw new Error('使用方法: pushy parseIpa ipa后缀文件');
|
||||||
|
}
|
||||||
|
console.log(await getIpaInfo(fn));
|
||||||
|
},
|
||||||
|
parseApk: async function ({ args }) {
|
||||||
|
const fn = args[0];
|
||||||
|
if (!fn || !fn.endsWith('.apk')) {
|
||||||
|
throw new Error('使用方法: pushy parseApk apk后缀文件');
|
||||||
|
}
|
||||||
|
console.log(await getApkInfo(fn));
|
||||||
},
|
},
|
||||||
packages: async function ({ options }) {
|
packages: async function ({ options }) {
|
||||||
const platform = checkPlatform(options.platform || (await question('Platform(ios/android):')));
|
const platform = checkPlatform(
|
||||||
|
options.platform || (await question('平台(ios/android):')),
|
||||||
|
);
|
||||||
const { appId } = await getSelectedApp(platform);
|
const { appId } = await getSelectedApp(platform);
|
||||||
await listPackage(appId);
|
await listPackage(appId);
|
||||||
},
|
},
|
||||||
|
@@ -26,11 +26,11 @@ exports.commands = {
|
|||||||
});
|
});
|
||||||
replaceSession({token});
|
replaceSession({token});
|
||||||
await saveSession();
|
await saveSession();
|
||||||
console.log(`Welcome, ${info.name}.`);
|
console.log(`欢迎使用 pushy 热更新服务, ${info.name}.`);
|
||||||
},
|
},
|
||||||
logout: async function (){
|
logout: async function (){
|
||||||
await closeSession();
|
await closeSession();
|
||||||
console.log('Logged out.');
|
console.log('已退出登录');
|
||||||
},
|
},
|
||||||
me: async function (){
|
me: async function (){
|
||||||
const me = await get('/user/me');
|
const me = await get('/user/me');
|
||||||
|
@@ -2,9 +2,10 @@
|
|||||||
* Created by tdzl2003 on 2/13/16.
|
* Created by tdzl2003 on 2/13/16.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
const pkg = require('../../package.json');
|
||||||
const AppInfoParser = require('app-info-parser');
|
const AppInfoParser = require('app-info-parser');
|
||||||
|
|
||||||
var read = require('read');
|
var read = require('read');
|
||||||
@@ -56,6 +57,21 @@ export function getRNVersion() {
|
|||||||
|
|
||||||
export async function getApkInfo(fn) {
|
export async function getApkInfo(fn) {
|
||||||
const appInfoParser = new AppInfoParser(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();
|
const { versionName, application } = await appInfoParser.parse();
|
||||||
let buildTime = 0;
|
let buildTime = 0;
|
||||||
if (Array.isArray(application.metaData)) {
|
if (Array.isArray(application.metaData)) {
|
||||||
@@ -66,13 +82,30 @@ export async function getApkInfo(fn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (buildTime == 0) {
|
if (buildTime == 0) {
|
||||||
throw new Error('无法获取此包的编译时间戳。请更新react-native-update到最新版本后重新打包上传。');
|
throw new Error(
|
||||||
|
'无法获取此包的编译时间戳。请更新react-native-update到最新版本后重新打包上传。',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return { versionName, buildTime };
|
return { versionName, buildTime, ...appCredential };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getIpaInfo(fn) {
|
export async function getIpaInfo(fn) {
|
||||||
const appInfoParser = new AppInfoParser(fn);
|
const appInfoParser = new AppInfoParser(fn);
|
||||||
|
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 {
|
const {
|
||||||
CFBundleShortVersionString: versionName,
|
CFBundleShortVersionString: versionName,
|
||||||
} = await appInfoParser.parse();
|
} = await appInfoParser.parse();
|
||||||
@@ -86,10 +119,12 @@ export async function getIpaInfo(fn) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!buildTimeTxtBuffer) {
|
if (!buildTimeTxtBuffer) {
|
||||||
throw new Error('无法获取此包的编译时间戳。请更新react-native-update到最新版本后重新打包上传。');
|
throw new Error(
|
||||||
|
'无法获取此包的编译时间戳。请更新react-native-update到最新版本后重新打包上传。',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const buildTime = buildTimeTxtBuffer.toString().replace('\n', '');
|
const buildTime = buildTimeTxtBuffer.toString().replace('\n', '');
|
||||||
return { versionName, buildTime };
|
return { versionName, buildTime, ...appCredential };
|
||||||
}
|
}
|
||||||
|
|
||||||
const localDir = path.resolve(os.homedir(), '.pushy');
|
const localDir = path.resolve(os.homedir(), '.pushy');
|
||||||
@@ -100,3 +135,20 @@ export function saveToLocal(originPath, destName) {
|
|||||||
// fs.ensureDirSync(path.dirname(destPath));
|
// fs.ensureDirSync(path.dirname(destPath));
|
||||||
// fs.copyFileSync(originPath, 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';
|
||||||
|
113
src/versions.js
113
src/versions.js
@@ -1,25 +1,17 @@
|
|||||||
/**
|
const { get, post, put, uploadFile } = require('./api');
|
||||||
* Created by tdzl2003 on 4/2/16.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const {
|
|
||||||
get,
|
|
||||||
post,
|
|
||||||
put,
|
|
||||||
uploadFile,
|
|
||||||
} = require('./api');
|
|
||||||
import { question, saveToLocal } from './utils';
|
import { question, saveToLocal } from './utils';
|
||||||
|
|
||||||
import { checkPlatform, getSelectedApp } from './app';
|
import { checkPlatform, getSelectedApp } from './app';
|
||||||
import { choosePackage } from './package';
|
import { choosePackage } from './package';
|
||||||
import uid from 'uid-safe';
|
|
||||||
const uidSync = uid.sync;
|
|
||||||
|
|
||||||
async function showVersion(appId, offset) {
|
async function showVersion(appId, offset) {
|
||||||
const { data, count } = await get(`/app/${appId}/version/list`);
|
const { data, count } = await get(`/app/${appId}/version/list`);
|
||||||
console.log(`Offset ${offset}`);
|
console.log(`Offset ${offset}`);
|
||||||
for (const version of data) {
|
for (const version of data) {
|
||||||
let packageInfo = version.packages.slice(0, 3).map(v=>v.name).join(', ');
|
let packageInfo = version.packages
|
||||||
|
.slice(0, 3)
|
||||||
|
.map((v) => v.name)
|
||||||
|
.join(', ');
|
||||||
const count = version.packages.length;
|
const count = version.packages.length;
|
||||||
if (count > 3) {
|
if (count > 3) {
|
||||||
packageInfo += `...and ${count - 3} more`;
|
packageInfo += `...and ${count - 3} more`;
|
||||||
@@ -29,7 +21,11 @@ async function showVersion(appId, offset) {
|
|||||||
} else {
|
} else {
|
||||||
packageInfo = `[${packageInfo}]`;
|
packageInfo = `[${packageInfo}]`;
|
||||||
}
|
}
|
||||||
console.log(`${version.id}) ${version.hash.slice(0, 8)} ${version.name} ${packageInfo}`);
|
console.log(
|
||||||
|
`${version.id}) ${version.hash.slice(0, 8)} ${
|
||||||
|
version.name
|
||||||
|
} ${packageInfo}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -40,10 +36,17 @@ async function listVersions(appId) {
|
|||||||
await showVersion(appId, offset);
|
await showVersion(appId, offset);
|
||||||
const cmd = await question('page Up/page Down/Begin/Quit(U/D/B/Q)');
|
const cmd = await question('page Up/page Down/Begin/Quit(U/D/B/Q)');
|
||||||
switch (cmd.toLowerCase()) {
|
switch (cmd.toLowerCase()) {
|
||||||
case 'u': offset = Math.max(0, offset - 10); break;
|
case 'u':
|
||||||
case 'd': offset += 10; break;
|
offset = Math.max(0, offset - 10);
|
||||||
case 'b': offset = 0; break;
|
break;
|
||||||
case 'q': return;
|
case 'd':
|
||||||
|
offset += 10;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
offset = 0;
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,14 +55,21 @@ async function chooseVersion(appId) {
|
|||||||
let offset = 0;
|
let offset = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
const data = await showVersion(appId, offset);
|
const data = await showVersion(appId, offset);
|
||||||
const cmd = await question('Enter versionId or page Up/page Down/Begin(U/D/B)');
|
const cmd = await question(
|
||||||
|
'Enter versionId or page Up/page Down/Begin(U/D/B)',
|
||||||
|
);
|
||||||
switch (cmd.toLowerCase()) {
|
switch (cmd.toLowerCase()) {
|
||||||
case 'U': offset = Math.max(0, offset - 10); break;
|
case 'U':
|
||||||
case 'D': offset += 10; break;
|
offset = Math.max(0, offset - 10);
|
||||||
case 'B': offset = 0; break;
|
break;
|
||||||
default:
|
case 'D':
|
||||||
{
|
offset += 10;
|
||||||
const v = data.find(v=>v.id === (cmd | 0));
|
break;
|
||||||
|
case 'B':
|
||||||
|
offset = 0;
|
||||||
|
break;
|
||||||
|
default: {
|
||||||
|
const v = data.find((v) => v.id === (cmd | 0));
|
||||||
if (v) {
|
if (v) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@@ -74,42 +84,69 @@ export const commands = {
|
|||||||
const { name, description, metaInfo } = options;
|
const { name, description, metaInfo } = options;
|
||||||
|
|
||||||
if (!fn || !fn.endsWith('.ppk')) {
|
if (!fn || !fn.endsWith('.ppk')) {
|
||||||
throw new Error('Usage: pushy publish <ppkFile> --platform ios|android');
|
throw new Error(
|
||||||
|
'使用方法: pushy publish ppk后缀文件 --platform ios|android',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
const platform = checkPlatform(
|
||||||
|
options.platform || (await question('平台(ios/android):')),
|
||||||
|
);
|
||||||
const { appId } = await getSelectedApp(platform);
|
const { appId } = await getSelectedApp(platform);
|
||||||
|
|
||||||
const { hash } = await uploadFile(fn, `v/${uidSync(19)}`);
|
const { hash } = await uploadFile(fn);
|
||||||
|
|
||||||
const { id } = await post(`/app/${appId}/version/create`, {
|
const { id } = await post(`/app/${appId}/version/create`, {
|
||||||
name: name || await question('Enter version name:') || '(未命名)',
|
name: name || (await question('输入版本名称: ')) || '(未命名)',
|
||||||
hash,
|
hash,
|
||||||
description: description || await question('Enter description:'),
|
description: description || (await question('输入版本描述:')),
|
||||||
metaInfo: metaInfo || await question('Enter meta info:'),
|
metaInfo: metaInfo || (await question('输入自定义的 meta info:')),
|
||||||
});
|
});
|
||||||
// TODO local diff
|
// TODO local diff
|
||||||
saveToLocal(fn, `${appId}/ppk/${id}.ppk`);
|
saveToLocal(fn, `${appId}/ppk/${id}.ppk`);
|
||||||
console.log(`Version published: ${id}`);
|
console.log(`已成功上传新热更包(id: ${id})`);
|
||||||
|
|
||||||
const v = await question('Would you like to bind packages to this version?(Y/N)');
|
const v = await question('是否现在将此热更应用到原生包上?(Y/N)');
|
||||||
if (v.toLowerCase() === 'y') {
|
if (v.toLowerCase() === 'y') {
|
||||||
await this.update({ args: [], options: { versionId: id, platform } });
|
await this.update({ args: [], options: { versionId: id, platform } });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
versions: async function ({ options }) {
|
versions: async function ({ options }) {
|
||||||
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
const platform = checkPlatform(
|
||||||
|
options.platform || (await question('平台(ios/android):')),
|
||||||
|
);
|
||||||
const { appId } = await getSelectedApp(platform);
|
const { appId } = await getSelectedApp(platform);
|
||||||
await listVersions(appId);
|
await listVersions(appId);
|
||||||
},
|
},
|
||||||
update: async function ({ args, options }) {
|
update: async function ({ args, options }) {
|
||||||
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
const platform = checkPlatform(
|
||||||
|
options.platform || (await question('平台(ios/android):')),
|
||||||
|
);
|
||||||
const { appId } = await getSelectedApp(platform);
|
const { appId } = await getSelectedApp(platform);
|
||||||
const versionId = options.versionId || (await chooseVersion(appId)).id;
|
const versionId = options.versionId || (await chooseVersion(appId)).id;
|
||||||
const pkgId = options.packageId || (await choosePackage(appId)).id;
|
|
||||||
|
let pkgId;
|
||||||
|
let pkgVersion = options.packageVersion;
|
||||||
|
if (pkgVersion) {
|
||||||
|
pkgVersion = pkgVersion.trim();
|
||||||
|
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
||||||
|
const pkg = data.find((d) => d.name === pkgVersion);
|
||||||
|
if (pkg) {
|
||||||
|
pkgId = pkg.id;
|
||||||
|
} else {
|
||||||
|
throw new Error(`未查询到匹配原生版本:${pkgVersion}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!pkgId) {
|
||||||
|
pkgId = options.packageId || (await choosePackage(appId)).id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pkgId) {
|
||||||
|
throw new Error('请提供 packageId 或 packageVersion 参数');
|
||||||
|
}
|
||||||
await put(`/app/${appId}/package/${pkgId}`, {
|
await put(`/app/${appId}/package/${pkgId}`, {
|
||||||
versionId,
|
versionId,
|
||||||
});
|
});
|
||||||
console.log('Ok.');
|
console.log('操作成功');
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user