mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-17 18:06:10 +08:00
Compare commits
1 Commits
v1.7.0-bet
...
v1.2.1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
34d4c35ca3 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -104,4 +104,3 @@ dist
|
|||||||
.tern-port
|
.tern-port
|
||||||
|
|
||||||
lib/
|
lib/
|
||||||
.DS_Store
|
|
||||||
|
29
LICENSE
Normal file
29
LICENSE
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
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.
|
37
cli.json
37
cli.json
@@ -106,11 +106,11 @@
|
|||||||
"hasValue": true
|
"hasValue": true
|
||||||
},
|
},
|
||||||
"intermediaDir": {
|
"intermediaDir": {
|
||||||
"default": ".pushy/intermedia/${platform}",
|
"default": "build/intermedia/${platform}",
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"default": ".pushy/output/${platform}.${time}.ppk",
|
"default": "build/output/${platform}.${time}.ppk",
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
},
|
},
|
||||||
"verbose": {}
|
"verbose": {}
|
||||||
@@ -123,7 +123,7 @@
|
|||||||
"description": "Create diff patch",
|
"description": "Create diff patch",
|
||||||
"options": {
|
"options": {
|
||||||
"output": {
|
"output": {
|
||||||
"default": ".pushy/output/diff",
|
"default": "build/output/diff",
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@
|
|||||||
"description": "Create diff patch from a Android package(.apk)",
|
"description": "Create diff patch from a Android package(.apk)",
|
||||||
"options": {
|
"options": {
|
||||||
"output": {
|
"output": {
|
||||||
"default": ".pushy/output/diff-${time}.apk-patch",
|
"default": "build/output/diff-${time}.apk-patch",
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,34 +141,7 @@
|
|||||||
"description": "Create diff patch from a iOS package(.ipa)",
|
"description": "Create diff patch from a iOS package(.ipa)",
|
||||||
"options": {
|
"options": {
|
||||||
"output": {
|
"output": {
|
||||||
"default": ".pushy/output/diff-${time}.ipa-patch",
|
"default": "build/output/diff-${time}.ipa-patch",
|
||||||
"hasValue": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"hdiff": {
|
|
||||||
"description": "Create hdiff patch",
|
|
||||||
"options": {
|
|
||||||
"output": {
|
|
||||||
"default": ".pushy/output/hdiff",
|
|
||||||
"hasValue": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"hdiffFromApk": {
|
|
||||||
"description": "Create hdiff patch from a Android package(.apk)",
|
|
||||||
"options": {
|
|
||||||
"output": {
|
|
||||||
"default": ".pushy/output/hdiff-${time}.apk-patch",
|
|
||||||
"hasValue": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"hdiffFromIpa": {
|
|
||||||
"description": "Create hdiff patch from a iOS package(.ipa)",
|
|
||||||
"options": {
|
|
||||||
"output": {
|
|
||||||
"default": ".pushy/output/hdiff-${time}.ipa-patch",
|
|
||||||
"hasValue": true
|
"hasValue": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update-cli",
|
"name": "react-native-update-cli",
|
||||||
"version": "1.7.0-beta.0",
|
"version": "1.2.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,7 +32,7 @@
|
|||||||
},
|
},
|
||||||
"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": "^1.0.0",
|
"app-info-parser": "^0.3.13",
|
||||||
"cli-arguments": "^0.2.1",
|
"cli-arguments": "^0.2.1",
|
||||||
"filesize-parser": "^1.5.0",
|
"filesize-parser": "^1.5.0",
|
||||||
"fs-extra": "8",
|
"fs-extra": "8",
|
||||||
|
70
src/api.js
70
src/api.js
@@ -1,6 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* Created by tdzl2003 on 2/13/16.
|
||||||
|
*/
|
||||||
|
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const defaultEndpoint = 'http://u.reactnative.cn/api';
|
let host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn/api';
|
||||||
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
import request from 'request';
|
import request from 'request';
|
||||||
import ProgressBar from 'progress';
|
import ProgressBar from 'progress';
|
||||||
@@ -18,7 +21,7 @@ let savedSession = undefined;
|
|||||||
|
|
||||||
const userAgent = `react-native-update-cli/${packageJson.version}`;
|
const userAgent = `react-native-update-cli/${packageJson.version}`;
|
||||||
|
|
||||||
exports.loadSession = async function () {
|
exports.loadSession = async function() {
|
||||||
if (fs.existsSync('.update')) {
|
if (fs.existsSync('.update')) {
|
||||||
try {
|
try {
|
||||||
exports.replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
|
exports.replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
|
||||||
@@ -32,15 +35,15 @@ exports.loadSession = async function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getSession = function () {
|
exports.getSession = function() {
|
||||||
return session;
|
return session;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.replaceSession = function (newSession) {
|
exports.replaceSession = function(newSession) {
|
||||||
session = newSession;
|
session = newSession;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.saveSession = function () {
|
exports.saveSession = function() {
|
||||||
// Only save on change.
|
// Only save on change.
|
||||||
if (session !== savedSession) {
|
if (session !== savedSession) {
|
||||||
const current = session;
|
const current = session;
|
||||||
@@ -50,25 +53,18 @@ exports.saveSession = function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.closeSession = function () {
|
exports.closeSession = function() {
|
||||||
if (fs.existsSync('.update')) {
|
if (fs.existsSync('.update')) {
|
||||||
fs.unlinkSync('.update');
|
fs.unlinkSync('.update');
|
||||||
savedSession = undefined;
|
savedSession = undefined;
|
||||||
}
|
}
|
||||||
session = undefined;
|
session = undefined;
|
||||||
host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn/api';
|
||||||
};
|
};
|
||||||
|
|
||||||
async function query(url, options) {
|
async function query(url, options) {
|
||||||
const resp = await fetch(url, options);
|
const resp = await fetch(url, options);
|
||||||
const text = await resp.text();
|
const json = await resp.json();
|
||||||
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,
|
||||||
@@ -78,7 +74,7 @@ async function query(url, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function queryWithoutBody(method) {
|
function queryWithoutBody(method) {
|
||||||
return function (api) {
|
return function(api) {
|
||||||
return query(host + api, {
|
return query(host + api, {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -90,7 +86,7 @@ function queryWithoutBody(method) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function queryWithBody(method) {
|
function queryWithBody(method) {
|
||||||
return function (api, body) {
|
return function(api, body) {
|
||||||
return query(host + api, {
|
return query(host + api, {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -110,37 +106,29 @@ exports.doDelete = queryWithBody('DELETE');
|
|||||||
|
|
||||||
async function uploadFile(fn, key) {
|
async function uploadFile(fn, key) {
|
||||||
const { url, backupUrl, formData, maxSize } = await exports.post('/upload', {
|
const { url, backupUrl, formData, maxSize } = await exports.post('/upload', {
|
||||||
ext: path.extname(fn),
|
ext: path.extname(fn)
|
||||||
});
|
});
|
||||||
let realUrl = url;
|
let realUrl = url;
|
||||||
|
|
||||||
if (backupUrl) {
|
if (backupUrl) {
|
||||||
if (global.USE_ACC_OSS) {
|
const pingResult = await tcpPing({
|
||||||
|
address: url.replace('https://', ''),
|
||||||
|
attempts: 4,
|
||||||
|
timeout: 1000,
|
||||||
|
});
|
||||||
|
// console.log({pingResult});
|
||||||
|
if (isNaN(pingResult.avg) || pingResult.avg > 150) {
|
||||||
realUrl = backupUrl;
|
realUrl = backupUrl;
|
||||||
} else {
|
|
||||||
const pingResult = await tcpPing({
|
|
||||||
address: url.replace('https://', ''),
|
|
||||||
attempts: 4,
|
|
||||||
timeout: 1000,
|
|
||||||
});
|
|
||||||
// console.log({pingResult});
|
|
||||||
if (isNaN(pingResult.avg) || pingResult.avg > 150) {
|
|
||||||
realUrl = backupUrl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// console.log({realUrl});
|
// console.log({realUrl});
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileSize = fs.statSync(fn).size;
|
const fileSize = fs.statSync(fn).size;
|
||||||
if (maxSize && fileSize > filesizeParser(maxSize)) {
|
if (maxSize && fileSize > filesizeParser(maxSize)) {
|
||||||
throw new Error(
|
throw new Error(`此文件大小超出上限${maxSize}。您可以考虑升级付费业务以提升此限制。详情请访问:${pricingPageUrl}`)
|
||||||
`此文件大小${(fileSize / 1048576).toFixed(
|
|
||||||
1,
|
|
||||||
)}m, 超出当前额度${maxSize}。您可以考虑升级付费业务以提升此额度。详情请访问: ${pricingPageUrl}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bar = new ProgressBar(' 上传中 [:bar] :percent :etas', {
|
const bar = new ProgressBar(' Uploading [:bar] :percent :etas', {
|
||||||
complete: '=',
|
complete: '=',
|
||||||
incomplete: ' ',
|
incomplete: ' ',
|
||||||
total: fileSize,
|
total: fileSize,
|
||||||
@@ -152,7 +140,7 @@ async function uploadFile(fn, key) {
|
|||||||
}
|
}
|
||||||
formData.file = fs.createReadStream(fn);
|
formData.file = fs.createReadStream(fn);
|
||||||
|
|
||||||
formData.file.on('data', function (data) {
|
formData.file.on('data', function(data) {
|
||||||
bar.tick(data.length);
|
bar.tick(data.length);
|
||||||
});
|
});
|
||||||
request.post(
|
request.post(
|
||||||
@@ -173,7 +161,13 @@ async function uploadFile(fn, key) {
|
|||||||
Object.assign(new Error(body), { status: resp.statusCode }),
|
Object.assign(new Error(body), { status: resp.statusCode }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
resolve({ hash: formData.key });
|
resolve(
|
||||||
|
body
|
||||||
|
? // qiniu
|
||||||
|
JSON.parse(body)
|
||||||
|
: // aliyun oss
|
||||||
|
{ hash: formData.key },
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
103
src/app.js
103
src/app.js
@@ -1,8 +1,15 @@
|
|||||||
import { question } from './utils';
|
/**
|
||||||
import fs from 'fs';
|
* Created by tdzl2003 on 2/13/16.
|
||||||
const Table = require('tty-table');
|
*/
|
||||||
|
|
||||||
const { post, get, doDelete } = require('./api');
|
import {question} from './utils';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
|
const {
|
||||||
|
post,
|
||||||
|
get,
|
||||||
|
doDelete,
|
||||||
|
} = require('./api');
|
||||||
|
|
||||||
const validPlatforms = {
|
const validPlatforms = {
|
||||||
ios: 1,
|
ios: 1,
|
||||||
@@ -11,48 +18,34 @@ const validPlatforms = {
|
|||||||
|
|
||||||
export function checkPlatform(platform) {
|
export function checkPlatform(platform) {
|
||||||
if (!validPlatforms[platform]) {
|
if (!validPlatforms[platform]) {
|
||||||
throw new Error(`无法识别的平台 '${platform}'`);
|
throw new Error(`Invalid platform '${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(
|
throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
|
||||||
`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(
|
throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
|
||||||
`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) {
|
||||||
rows.push([app.id, app.name, app.platform]);
|
console.log(`${app.id}) ${app.name}(${app.platform})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(Table(header, rows).render());
|
|
||||||
|
|
||||||
if (platform) {
|
if (platform) {
|
||||||
console.log(`\共 ${list.length} ${platform} 个应用`);
|
console.log(`\nTotal ${list.length} ${platform} apps`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`\共 ${list.length} 个应用`);
|
console.log(`\nTotal ${list.length} apps`);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -61,8 +54,8 @@ export async function chooseApp(platform) {
|
|||||||
const list = await listApp(platform);
|
const list = await listApp(platform);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const id = await question('输入应用 id:');
|
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) {
|
if (app) {
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
@@ -70,36 +63,32 @@ 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('应用名称:'));
|
const name = options.name || await question('App Name:');
|
||||||
const { downloadUrl } = options;
|
const {downloadUrl} = options;
|
||||||
const platform = checkPlatform(
|
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
||||||
options.platform || (await question('平台(ios/android):')),
|
const {id} = await post('/app/create', {name, platform});
|
||||||
);
|
console.log(`Created app ${id}`);
|
||||||
const { id } = await post('/app/create', { name, platform });
|
|
||||||
console.log(`已成功创建应用(id: ${id})`);
|
|
||||||
await this.selectApp({
|
await this.selectApp({
|
||||||
args: [id],
|
args: [id],
|
||||||
options: { platform, downloadUrl },
|
options: {platform, downloadUrl},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
deleteApp: async function ({ args, options }) {
|
deleteApp: async function ({args, options}) {
|
||||||
const { platform } = options;
|
const {platform} = options;
|
||||||
const id = args[0] || chooseApp(platform);
|
const id = args[0] || chooseApp(platform);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
console.log('已取消');
|
console.log('Canceled');
|
||||||
}
|
}
|
||||||
await doDelete(`/app/${id}`);
|
await doDelete(`/app/${id}`);
|
||||||
console.log('操作成功');
|
console.log('Ok.');
|
||||||
},
|
},
|
||||||
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(
|
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
||||||
options.platform || (await question('平台(ios/android):')),
|
|
||||||
);
|
|
||||||
const id = args[0] || (await chooseApp(platform)).id;
|
const id = args[0] || (await chooseApp(platform)).id;
|
||||||
|
|
||||||
let updateInfo = {};
|
let updateInfo = {};
|
||||||
@@ -107,21 +96,15 @@ export const commands = {
|
|||||||
try {
|
try {
|
||||||
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(
|
console.error('Failed to parse file `update.json`. Try to remove it manually.');
|
||||||
'Failed to parse file `update.json`. Try to remove it manually.',
|
|
||||||
);
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { appKey } = await get(`/app/${id}`);
|
const {appKey} = await get(`/app/${id}`);
|
||||||
updateInfo[platform] = {
|
updateInfo[platform] = {
|
||||||
appId: id,
|
appId: id,
|
||||||
appKey,
|
appKey,
|
||||||
};
|
};
|
||||||
fs.writeFileSync(
|
fs.writeFileSync('update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
|
||||||
'update.json',
|
|
||||||
JSON.stringify(updateInfo, null, 4),
|
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
|
140
src/bundle.js
140
src/bundle.js
@@ -1,3 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* 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';
|
||||||
@@ -9,14 +13,20 @@ 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 bsdiff, hdiff, diff;
|
var diff;
|
||||||
try {
|
try {
|
||||||
bsdiff = require('node-bsdiff').diff;
|
var bsdiff = require('node-bsdiff');
|
||||||
} catch (e) {}
|
diff = typeof bsdiff != 'function' ? bsdiff.diff : bsdiff;
|
||||||
|
} catch (e) {
|
||||||
try {
|
diff = function () {
|
||||||
hdiff = require('node-hdiffpatch').diff;
|
console.warn(
|
||||||
} catch (e) {}
|
'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.',
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async function runReactNativeBundleCommand(
|
async function runReactNativeBundleCommand(
|
||||||
bundleName,
|
bundleName,
|
||||||
@@ -30,9 +40,9 @@ async function runReactNativeBundleCommand(
|
|||||||
let gradleConfig = {};
|
let gradleConfig = {};
|
||||||
if (platform === 'android') {
|
if (platform === 'android') {
|
||||||
gradleConfig = await checkGradleConfig();
|
gradleConfig = await checkGradleConfig();
|
||||||
// if (gradleConfig.crunchPngs !== false) {
|
if (gradleConfig.crunchPngs !== false) {
|
||||||
// throw new Error('请先禁用android的crunchPngs优化,具体请参考 https://pushy.reactnative.cn/docs/getting-started.html#%E7%A6%81%E7%94%A8android%E7%9A%84crunch%E4%BC%98%E5%8C%96')
|
throw new Error('请先禁用android的crunchPngs优化,具体请参考 https://pushy.reactnative.cn/docs/getting-started.html#%E7%A6%81%E7%94%A8android%E7%9A%84crunch%E4%BC%98%E5%8C%96')
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let reactNativeBundleArgs = [];
|
let reactNativeBundleArgs = [];
|
||||||
@@ -115,6 +125,7 @@ async function checkGradleConfig() {
|
|||||||
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'];
|
||||||
|
crunchPngs = gradleConfig.android.buildTypes.release.crunchPngs;
|
||||||
for (const packagerConfig of projectConfig) {
|
for (const packagerConfig of projectConfig) {
|
||||||
if (
|
if (
|
||||||
packagerConfig.includes('enableHermes') &&
|
packagerConfig.includes('enableHermes') &&
|
||||||
@@ -124,12 +135,11 @@ async function checkGradleConfig() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
crunchPngs = gradleConfig.android.buildTypes.release.crunchPngs;
|
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
return {
|
return {
|
||||||
enableHermes,
|
enableHermes,
|
||||||
crunchPngs,
|
crunchPngs,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compileHermesByteCode(bundleName, outputFolder) {
|
async function compileHermesByteCode(bundleName, outputFolder) {
|
||||||
@@ -193,7 +203,7 @@ async function pack(dir, output) {
|
|||||||
});
|
});
|
||||||
zipfile.end();
|
zipfile.end();
|
||||||
});
|
});
|
||||||
console.log('ppk热更包已生成并保存到: ' + output);
|
console.log('Bundled saved to: ' + output);
|
||||||
}
|
}
|
||||||
|
|
||||||
function readEntire(entry, zipFile) {
|
function readEntire(entry, zipFile) {
|
||||||
@@ -472,46 +482,10 @@ function enumZipEntries(zipFn, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function diffArgsCheck(args, options, diffFn) {
|
|
||||||
const [origin, next] = args;
|
|
||||||
|
|
||||||
if (!origin || !next) {
|
|
||||||
console.error(`Usage: pushy ${diffFn} <origin> <next>`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (diffFn.startsWith('hdiff')) {
|
|
||||||
if (!hdiff) {
|
|
||||||
console.error(
|
|
||||||
`This function needs "node-hdiffpatch".
|
|
||||||
Please run "npm i node-hdiffpatch" to install`,
|
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
diff = hdiff;
|
|
||||||
} else {
|
|
||||||
if (!bsdiff) {
|
|
||||||
console.error(
|
|
||||||
`This function needs "node-bsdiff".
|
|
||||||
Please run "npm i node-bsdiff" to install`,
|
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
diff = bsdiff;
|
|
||||||
}
|
|
||||||
const { output } = options;
|
|
||||||
|
|
||||||
return {
|
|
||||||
origin,
|
|
||||||
next,
|
|
||||||
realOutput: output.replace(/\$\{time\}/g, '' + Date.now()),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const commands = {
|
export const commands = {
|
||||||
bundle: async function ({ options }) {
|
bundle: async function ({ options }) {
|
||||||
const platform = checkPlatform(
|
const platform = checkPlatform(
|
||||||
options.platform || (await question('平台(ios/android):')),
|
options.platform || (await question('Platform(ios/android):')),
|
||||||
);
|
);
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -549,7 +523,7 @@ export const commands = {
|
|||||||
|
|
||||||
await pack(path.resolve(intermediaDir), realOutput);
|
await pack(path.resolve(intermediaDir), realOutput);
|
||||||
|
|
||||||
const v = await question('是否现在上传此热更包?(Y/N)');
|
const v = await question('Would you like to publish it?(Y/N)');
|
||||||
if (v.toLowerCase() === 'y') {
|
if (v.toLowerCase() === 'y') {
|
||||||
await this.publish({
|
await this.publish({
|
||||||
args: [realOutput],
|
args: [realOutput],
|
||||||
@@ -561,41 +535,30 @@ export const commands = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async diff({ args, options }) {
|
async diff({ args, options }) {
|
||||||
const { origin, next, realOutput } = diffArgsCheck(args, options, 'diff');
|
const [origin, next] = args;
|
||||||
|
const { output } = options;
|
||||||
|
|
||||||
await diffFromPPK(origin, next, realOutput, 'index.bundlejs');
|
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
|
||||||
console.log(`${realOutput} generated.`);
|
|
||||||
},
|
|
||||||
|
|
||||||
async hdiff({ args, options }) {
|
if (!origin || !next) {
|
||||||
const { origin, next, realOutput } = diffArgsCheck(args, options, 'hdiff');
|
console.error('pushy diff <origin> <next>');
|
||||||
|
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, realOutput } = diffArgsCheck(
|
const [origin, next] = args;
|
||||||
args,
|
const { output } = options;
|
||||||
options,
|
|
||||||
'diffFromApk',
|
|
||||||
);
|
|
||||||
|
|
||||||
await diffFromPackage(
|
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
|
||||||
origin,
|
|
||||||
next,
|
|
||||||
realOutput,
|
|
||||||
'assets/index.android.bundle',
|
|
||||||
);
|
|
||||||
console.log(`${realOutput} generated.`);
|
|
||||||
},
|
|
||||||
|
|
||||||
async hdiffFromApk({ args, options }) {
|
if (!origin || !next) {
|
||||||
const { origin, next, realOutput } = diffArgsCheck(
|
console.error('pushy diffFromApk <origin> <next>');
|
||||||
args,
|
process.exit(1);
|
||||||
options,
|
}
|
||||||
'hdiffFromApk',
|
|
||||||
);
|
|
||||||
|
|
||||||
await diffFromPackage(
|
await diffFromPackage(
|
||||||
origin,
|
origin,
|
||||||
@@ -607,26 +570,15 @@ export const commands = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async diffFromIpa({ args, options }) {
|
async diffFromIpa({ args, options }) {
|
||||||
const { origin, next, realOutput } = diffArgsCheck(
|
const [origin, next] = args;
|
||||||
args,
|
const { output } = options;
|
||||||
options,
|
|
||||||
'diffFromIpa',
|
|
||||||
);
|
|
||||||
|
|
||||||
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', (v) => {
|
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
|
||||||
const m = /^Payload\/[^/]+\/(.+)$/.exec(v);
|
|
||||||
return m && m[1];
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`${realOutput} generated.`);
|
if (!origin || !next) {
|
||||||
},
|
console.error('pushy diffFromIpa <origin> <next>');
|
||||||
|
process.exit(1);
|
||||||
async hdiffFromIpa({ args, options }) {
|
}
|
||||||
const { origin, next, realOutput } = diffArgsCheck(
|
|
||||||
args,
|
|
||||||
options,
|
|
||||||
'hdiffFromIpa',
|
|
||||||
);
|
|
||||||
|
|
||||||
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', (v) => {
|
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', (v) => {
|
||||||
const m = /^Payload\/[^/]+\/(.+)$/.exec(v);
|
const m = /^Payload\/[^/]+\/(.+)$/.exec(v);
|
||||||
|
28
src/index.js
28
src/index.js
@@ -1,20 +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';
|
import { printVersionCommand } from './utils/index.js';
|
||||||
const pkg = require('../package.json');
|
const pkg = require('../package.json');
|
||||||
|
|
||||||
updateNotifier({ pkg }).notify({ isGlobal: true });
|
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(
|
console.log('Visit `https://github.com/reactnativecn/react-native-pushy` for early document.');
|
||||||
'Visit `https://github.com/reactnativecn/react-native-pushy` for early document.',
|
|
||||||
);
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,21 +33,20 @@ function run() {
|
|||||||
printVersionCommand();
|
printVersionCommand();
|
||||||
process.exit();
|
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('尚未登录。\n请在项目目录中运行`pushy login`命令来登录');
|
console.log('Not loggined.\nRun `pushy login` at your project directory to login.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
run();
|
run();
|
@@ -30,7 +30,7 @@ export async function listPackage(appId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(Table(header, rows).render());
|
console.log(Table(header, rows).render());
|
||||||
console.log(`\n共 ${data.length} 个包`);
|
console.log(`\nTotal ${data.length} package(s).`);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ export async function choosePackage(appId) {
|
|||||||
const list = await listPackage(appId);
|
const list = await listPackage(appId);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const id = await question('输入原生包 id:');
|
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) {
|
if (app) {
|
||||||
return app;
|
return app;
|
||||||
@@ -50,27 +50,10 @@ 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('使用方法: pushy uploadIpa ipa后缀文件');
|
throw new Error('Usage: pushy uploadIpa <ipaFile>');
|
||||||
}
|
|
||||||
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 { versionName, buildTime } = await getIpaInfo(fn);
|
||||||
|
const { appId } = await getSelectedApp('ios');
|
||||||
|
|
||||||
const { hash } = await uploadFile(fn);
|
const { hash } = await uploadFile(fn);
|
||||||
|
|
||||||
@@ -80,32 +63,15 @@ export const commands = {
|
|||||||
buildTime,
|
buildTime,
|
||||||
});
|
});
|
||||||
saveToLocal(fn, `${appId}/package/${id}.ipa`);
|
saveToLocal(fn, `${appId}/package/${id}.ipa`);
|
||||||
console.log(`已成功上传ipa原生包(id: ${id})`);
|
console.log(`Ipa uploaded: ${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('使用方法: pushy uploadApk apk后缀文件');
|
throw new Error('Usage: pushy uploadApk <apkFile>');
|
||||||
}
|
|
||||||
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 { versionName, buildTime } = await getApkInfo(fn);
|
||||||
|
const { appId } = await getSelectedApp('android');
|
||||||
|
|
||||||
const { hash } = await uploadFile(fn);
|
const { hash } = await uploadFile(fn);
|
||||||
|
|
||||||
@@ -115,25 +81,25 @@ export const commands = {
|
|||||||
buildTime,
|
buildTime,
|
||||||
});
|
});
|
||||||
saveToLocal(fn, `${appId}/package/${id}.apk`);
|
saveToLocal(fn, `${appId}/package/${id}.apk`);
|
||||||
console.log(`已成功上传apk原生包(id: ${id})`);
|
console.log(`Apk uploaded: ${id}`);
|
||||||
},
|
},
|
||||||
parseIpa: async function ({ args }) {
|
parseIpa: async function ({ args }) {
|
||||||
const fn = args[0];
|
const fn = args[0];
|
||||||
if (!fn || !fn.endsWith('.ipa')) {
|
if (!fn || !fn.endsWith('.ipa')) {
|
||||||
throw new Error('使用方法: pushy parseIpa ipa后缀文件');
|
throw new Error('Usage: pushy parseIpa <ipaFile>');
|
||||||
}
|
}
|
||||||
console.log(await getIpaInfo(fn));
|
console.log(await getIpaInfo(fn));
|
||||||
},
|
},
|
||||||
parseApk: async function ({ args }) {
|
parseApk: async function ({ args }) {
|
||||||
const fn = args[0];
|
const fn = args[0];
|
||||||
if (!fn || !fn.endsWith('.apk')) {
|
if (!fn || !fn.endsWith('.apk')) {
|
||||||
throw new Error('使用方法: pushy parseApk apk后缀文件');
|
throw new Error('Usage: pushy parseApk <apkFile>');
|
||||||
}
|
}
|
||||||
console.log(await getApkInfo(fn));
|
console.log(await getApkInfo(fn));
|
||||||
},
|
},
|
||||||
packages: async function ({ options }) {
|
packages: async function ({ options }) {
|
||||||
const platform = checkPlatform(
|
const platform = checkPlatform(
|
||||||
options.platform || (await question('平台(ios/android):')),
|
options.platform || (await question('Platform(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(`欢迎使用 pushy 热更新服务, ${info.name}.`);
|
console.log(`Welcome, ${info.name}.`);
|
||||||
},
|
},
|
||||||
logout: async function (){
|
logout: async function (){
|
||||||
await closeSession();
|
await closeSession();
|
||||||
console.log('已退出登录');
|
console.log('Logged out.');
|
||||||
},
|
},
|
||||||
me: async function (){
|
me: async function (){
|
||||||
const me = await get('/user/me');
|
const me = await get('/user/me');
|
||||||
|
100
src/versions.js
100
src/versions.js
@@ -1,4 +1,13 @@
|
|||||||
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';
|
||||||
@@ -8,24 +17,17 @@ 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
|
let packageInfo = version.packages.slice(0, 3).map(v=>v.name).join(', ');
|
||||||
.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`;
|
||||||
}
|
}
|
||||||
if (count === 0) {
|
if (count === 0) {
|
||||||
packageInfo = `(no package)`;
|
packageInfo = `(no package)`;
|
||||||
} else {
|
} else {
|
||||||
packageInfo = `[${packageInfo}]`;
|
packageInfo = `[${packageInfo}]`;
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(`${version.id}) ${version.hash.slice(0, 8)} ${version.name} ${packageInfo}`);
|
||||||
`${version.id}) ${version.hash.slice(0, 8)} ${
|
|
||||||
version.name
|
|
||||||
} ${packageInfo}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -36,17 +38,10 @@ 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':
|
case 'u': offset = Math.max(0, offset - 10); break;
|
||||||
offset = Math.max(0, offset - 10);
|
case 'd': offset += 10; break;
|
||||||
break;
|
case 'b': offset = 0; break;
|
||||||
case 'd':
|
case 'q': return;
|
||||||
offset += 10;
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
offset = 0;
|
|
||||||
break;
|
|
||||||
case 'q':
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,21 +50,14 @@ 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(
|
const cmd = await question('Enter versionId or page Up/page Down/Begin(U/D/B)');
|
||||||
'Enter versionId or page Up/page Down/Begin(U/D/B)',
|
|
||||||
);
|
|
||||||
switch (cmd.toLowerCase()) {
|
switch (cmd.toLowerCase()) {
|
||||||
case 'U':
|
case 'U': offset = Math.max(0, offset - 10); break;
|
||||||
offset = Math.max(0, offset - 10);
|
case 'D': offset += 10; break;
|
||||||
break;
|
case 'B': offset = 0; break;
|
||||||
case 'D':
|
default:
|
||||||
offset += 10;
|
{
|
||||||
break;
|
const v = data.find(v=>v.id === (cmd | 0));
|
||||||
case 'B':
|
|
||||||
offset = 0;
|
|
||||||
break;
|
|
||||||
default: {
|
|
||||||
const v = data.find((v) => v.id === (cmd | 0));
|
|
||||||
if (v) {
|
if (v) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@@ -79,55 +67,47 @@ async function chooseVersion(appId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const commands = {
|
export const commands = {
|
||||||
publish: async function ({ args, options }) {
|
publish: async function({args, options}) {
|
||||||
const fn = args[0];
|
const fn = args[0];
|
||||||
const { name, description, metaInfo } = options;
|
const {name, description, metaInfo } = options;
|
||||||
|
|
||||||
if (!fn || !fn.endsWith('.ppk')) {
|
if (!fn || !fn.endsWith('.ppk')) {
|
||||||
throw new Error(
|
throw new Error('Usage: pushy publish <ppkFile> --platform ios|android');
|
||||||
'使用方法: pushy publish ppk后缀文件 --platform ios|android',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const platform = checkPlatform(
|
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
||||||
options.platform || (await question('平台(ios/android):')),
|
|
||||||
);
|
|
||||||
const { appId } = await getSelectedApp(platform);
|
const { appId } = await getSelectedApp(platform);
|
||||||
|
|
||||||
const { hash } = await uploadFile(fn);
|
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('输入版本名称: ')) || '(未命名)',
|
name: name || await question('Enter version name:') || '(未命名)',
|
||||||
hash,
|
hash,
|
||||||
description: description || (await question('输入版本描述:')),
|
description: description || await question('Enter description:'),
|
||||||
metaInfo: metaInfo || (await question('输入自定义的 meta info:')),
|
metaInfo: metaInfo || await question('Enter meta info:'),
|
||||||
});
|
});
|
||||||
// TODO local diff
|
// TODO local diff
|
||||||
saveToLocal(fn, `${appId}/ppk/${id}.ppk`);
|
saveToLocal(fn, `${appId}/ppk/${id}.ppk`);
|
||||||
console.log(`已成功上传新热更包(id: ${id})`);
|
console.log(`Version published: ${id}`);
|
||||||
|
|
||||||
const v = await question('是否现在将此热更应用到原生包上?(Y/N)');
|
const v = await question('Would you like to bind packages to this version?(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(
|
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
||||||
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(
|
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
||||||
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;
|
const pkgId = options.packageId || (await choosePackage(appId)).id;
|
||||||
await put(`/app/${appId}/package/${pkgId}`, {
|
await put(`/app/${appId}/package/${pkgId}`, {
|
||||||
versionId,
|
versionId,
|
||||||
});
|
});
|
||||||
console.log('操作成功');
|
console.log('Ok.');
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
36
yarn.lock
36
yarn.lock
@@ -72,10 +72,10 @@ anymatch@^1.3.0:
|
|||||||
micromatch "^2.1.5"
|
micromatch "^2.1.5"
|
||||||
normalize-path "^2.0.0"
|
normalize-path "^2.0.0"
|
||||||
|
|
||||||
app-info-parser@^1.0.0:
|
app-info-parser@^0.3.9:
|
||||||
version "1.0.0"
|
version "0.3.9"
|
||||||
resolved "https://registry.yarnpkg.com/app-info-parser/-/app-info-parser-1.0.0.tgz#38da83c167b436b485246a2c81ab28833ac12b6e"
|
resolved "https://registry.yarnpkg.com/app-info-parser/-/app-info-parser-0.3.9.tgz#adc60c9d4d4aca4e529f21a6da1279b74ddaf62b"
|
||||||
integrity sha512-l8fNzGZFTNCloUm5imfOQYjlBLQfu3DB9rkKgi7TWAjtCU2s0NMLetOw0TFmHye65NcdenAQawvLNLtyo1L//w==
|
integrity sha512-vIzO1OZSMnEz+OdGkhmSTS0y4PaQmXdF1YmzUBb7wsKR21JF1eXMnciARkUj6T+CLb9caoDSN+w5eSoGatRbcA==
|
||||||
dependencies:
|
dependencies:
|
||||||
bplist-parser "^0.2.0"
|
bplist-parser "^0.2.0"
|
||||||
bytebuffer "^5.0.1"
|
bytebuffer "^5.0.1"
|
||||||
@@ -1476,9 +1476,9 @@ is-glob@^2.0.0, is-glob@^2.0.1:
|
|||||||
is-extglob "^1.0.0"
|
is-extglob "^1.0.0"
|
||||||
|
|
||||||
is-installed-globally@^0.3.1:
|
is-installed-globally@^0.3.1:
|
||||||
version "0.3.2"
|
version "0.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/is-installed-globally/-/is-installed-globally-0.3.2.tgz#fd3efa79ee670d1187233182d5b0a1dd00313141"
|
resolved "https://registry.yarnpkg.com/is-installed-globally/-/is-installed-globally-0.3.1.tgz#679afef819347a72584617fd19497f010b8ed35f"
|
||||||
integrity sha512-wZ8x1js7Ia0kecP/CHM/3ABkAmujX7WPvQk6uu3Fly/Mk44pySulQpnHG46OMjHGXApINnV4QhY3SWnECO2z5g==
|
integrity sha512-oiEcGoQbGc+3/iijAijrK2qFpkNoNjsHOm/5V5iaeydyrS/hnwaRCEgH5cpW0P3T1lSjV5piB7S5b5lEugNLhg==
|
||||||
dependencies:
|
dependencies:
|
||||||
global-dirs "^2.0.1"
|
global-dirs "^2.0.1"
|
||||||
is-path-inside "^3.0.1"
|
is-path-inside "^3.0.1"
|
||||||
@@ -1885,10 +1885,10 @@ nanomatch@^1.2.9:
|
|||||||
snapdragon "^0.8.1"
|
snapdragon "^0.8.1"
|
||||||
to-regex "^3.0.1"
|
to-regex "^3.0.1"
|
||||||
|
|
||||||
node-fetch@^2.6.1:
|
node-fetch@^2.6.0:
|
||||||
version "2.6.1"
|
version "2.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
|
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
|
||||||
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
|
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
|
||||||
|
|
||||||
normalize-path@^2.0.0, normalize-path@^2.0.1:
|
normalize-path@^2.0.0, normalize-path@^2.0.1:
|
||||||
version "2.1.1"
|
version "2.1.1"
|
||||||
@@ -2116,9 +2116,9 @@ punycode@^2.1.0, punycode@^2.1.1:
|
|||||||
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
|
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
|
||||||
|
|
||||||
pupa@^2.0.1:
|
pupa@^2.0.1:
|
||||||
version "2.1.1"
|
version "2.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/pupa/-/pupa-2.1.1.tgz#f5e8fd4afc2c5d97828faa523549ed8744a20d62"
|
resolved "https://registry.yarnpkg.com/pupa/-/pupa-2.0.1.tgz#dbdc9ff48ffbea4a26a069b6f9f7abb051008726"
|
||||||
integrity sha512-l1jNAspIBSFqbT+y+5FosojNpVpF94nlI+wDUpqP9enwOTfHx9f0gh5nB96vl+6yTpsJsypeNrwfzPrKuHB41A==
|
integrity sha512-hEJH0s8PXLY/cdXh66tNEQGndDrIKNqNC5xmrysZy3i5C3oEoLna7YAOad+7u125+zH1HNXUmGEkrhb3c2VriA==
|
||||||
dependencies:
|
dependencies:
|
||||||
escape-goat "^2.0.0"
|
escape-goat "^2.0.0"
|
||||||
|
|
||||||
@@ -2694,10 +2694,10 @@ unset-value@^1.0.0:
|
|||||||
has-value "^0.3.1"
|
has-value "^0.3.1"
|
||||||
isobject "^3.0.0"
|
isobject "^3.0.0"
|
||||||
|
|
||||||
update-notifier@^4.1.1:
|
update-notifier@^4.1.0:
|
||||||
version "4.1.3"
|
version "4.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-4.1.3.tgz#be86ee13e8ce48fb50043ff72057b5bd598e1ea3"
|
resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-4.1.0.tgz#4866b98c3bc5b5473c020b1250583628f9a328f3"
|
||||||
integrity sha512-Yld6Z0RyCYGB6ckIjffGOSOmHXj1gMeE7aROz4MG+XMkmixBX4jUngrGXNYz7wPKBmtoD4MnBa2Anu7RSKht/A==
|
integrity sha512-w3doE1qtI0/ZmgeoDoARmI5fjDoT93IfKgEGqm26dGUOh8oNpaSTsGNdYRN/SjOuo10jcJGwkEL3mroKzktkew==
|
||||||
dependencies:
|
dependencies:
|
||||||
boxen "^4.2.0"
|
boxen "^4.2.0"
|
||||||
chalk "^3.0.0"
|
chalk "^3.0.0"
|
||||||
|
Reference in New Issue
Block a user