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

Compare commits

..

38 Commits

Author SHA1 Message Date
sunnylqm
efc8b69bbc v1.20.5 2024-03-06 20:45:56 +08:00
sunnylqm
b1fda5ab9c v1.20.3 2024-03-06 20:36:25 +08:00
sunnylqm
385b974aff v1.20.2 2024-03-06 10:20:00 +08:00
sunnylqm
2a02deb015 v1.20.1 2024-03-06 09:55:48 +08:00
sunnylqm
8b7cb809f6 v1.20.0 2024-03-05 23:29:31 +08:00
sunnylqm
070991d08b fix: hermes path 2024-03-05 23:29:05 +08:00
sunnylqm
0d03e18c58 fix: version name 2024-03-05 23:03:10 +08:00
sunnylqm
a0dfcb5c4b v1.19.0 2024-02-18 20:04:05 +08:00
sunnylqm
587da8aaf9 Fix android crunchPngs option and add support for expo-router 2024-02-18 20:03:43 +08:00
sunnylqm
724088a810 v1.18.0 2024-02-03 21:28:38 +08:00
sunnylqm
7c20b30c85 feat: support expo 2024-02-03 21:27:47 +08:00
sunnylqm
6a053c6428 v1.17.0 2024-01-30 19:15:15 +08:00
sunnylqm
f202fc590d fix: rndir path 2024-01-30 19:15:00 +08:00
sunnylqm
0f8cf3c399 v1.16.0 2024-01-30 17:50:32 +08:00
sunnylqm
6a0d82c7a5 fix: rndir path 2024-01-30 17:50:09 +08:00
sunnylqm
eed19992d8 v1.15.0 2024-01-30 12:43:48 +08:00
sunnylqm
1b5078831c fix: require path 2024-01-30 12:43:31 +08:00
sunnylqm
bc9aff343a v1.14.0 2024-01-29 19:11:06 +08:00
sunnylqm
7aaa32a5a2 v1.14.0-beta.0 2024-01-29 19:02:01 +08:00
sunnylqm
ab7920fe38 feat: support symlink 2024-01-29 19:01:11 +08:00
sunnylqm
d912ace4a7 v1.13.0 2023-09-19 18:40:12 +08:00
sunnylqm
8af4d314ce fix appid equal 2023-09-19 18:36:26 +08:00
sunnylqm
f2d5269512 feat: support rn0.71 android hermes 2023-07-20 18:27:14 +08:00
sunnylqm
fe24c4ca36 v1.12.0 2023-07-20 18:25:47 +08:00
sunnylqm
cf61c297a6 update endpoint 2023-01-29 10:35:44 +08:00
sunnylqm
f9adc700ed v1.11.0 2023-01-11 23:36:13 +08:00
sunnylqm
dcff16cbb5 support source-map 2023-01-11 23:35:39 +08:00
sunnylqm
2bb8e83010 v1.10.0 2022-07-01 23:08:16 +08:00
sunnylqm
0cfc6e4f0d support rn 69 hermes 2022-07-01 23:02:20 +08:00
sunnylqm
da7bdbfdd2 v1.9.0 2022-06-29 09:42:05 +08:00
sunnylqm
07ee28ba3b add updateVersionInfo 2022-06-29 09:41:44 +08:00
sunnylqm
dae3e4024f v1.8.1 2021-12-24 17:55:15 +08:00
sunnylqm
d673b5736a Fix selectApp id 2021-12-24 17:53:14 +08:00
sunnylqm
732845faad Cleanup headers 2021-10-28 18:01:12 +08:00
sunnylqm
bcfdd67ea8 v1.8.0 2021-10-18 18:24:15 +08:00
sunnylqm
27ea54c1ec Update package output 2021-10-18 18:22:56 +08:00
sunnylqm
ba0fa836d1 v1.7.2 2021-10-18 18:02:43 +08:00
sunnylqm
bde76094fc v1.7.1 2021-10-18 18:00:21 +08:00
11 changed files with 1021 additions and 712 deletions

View File

@@ -88,6 +88,29 @@
} }
}, },
"updateVersionInfo": {
"options": {
"platform": {
"hasValue": true
},
"versionId": {
"hasValue": true
},
"name": {
"default": false,
"hasValue": true
},
"description": {
"default": false,
"hasValue": true
},
"metaInfo": {
"default": false,
"hasValue": true
}
}
},
"build": { "build": {
"description": "Bundle javascript and copy assets." "description": "Bundle javascript and copy assets."
}, },
@@ -117,7 +140,9 @@
"default": ".pushy/output/${platform}.${time}.ppk", "default": ".pushy/output/${platform}.${time}.ppk",
"hasValue": true "hasValue": true
}, },
"verbose": {} "sourcemap": {
"default": false
}
} }
}, },
"release": { "release": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-native-update-cli", "name": "react-native-update-cli",
"version": "1.7.0", "version": "1.20.5",
"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": {
@@ -12,7 +12,6 @@
"cli.json" "cli.json"
], ],
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepublish": "babel src --out-dir lib" "prepublish": "babel src --out-dir lib"
}, },
"repository": { "repository": {
@@ -32,18 +31,19 @@
}, },
"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": "github:sunnylqm/app-info-parser#fix/support-ascii-versionname",
"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",
"gradle-to-js": "^2.0.0", "gradle-to-js": "^2.0.1",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"progress": "^2.0.3", "progress": "^2.0.3",
"properties": "^1.2.1",
"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": "4.1", "tty-table": "4.2",
"update-notifier": "^4.1.1", "update-notifier": "^5.1.0",
"yauzl": "^2.10.0", "yauzl": "^2.10.0",
"yazl": "2.5.1" "yazl": "2.5.1"
}, },
@@ -55,6 +55,6 @@
"babel-plugin-transform-object-rest-spread": "^6.26.0" "babel-plugin-transform-object-rest-spread": "^6.26.0"
}, },
"engines": { "engines": {
"node": ">= 8" "node": ">= 10"
} }
} }

1322
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,13 @@
const fetch = require('node-fetch'); import fetch from 'node-fetch';
const defaultEndpoint = 'http://u.reactnative.cn/api'; const defaultEndpoint = 'https://update.reactnative.cn/api';
let host = process.env.PUSHY_REGISTRY || defaultEndpoint; let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
const fs = require('fs'); import fs from 'fs';
import request from 'request'; import request from 'request';
import ProgressBar from 'progress'; import ProgressBar from 'progress';
const packageJson = require('../package.json'); import packageJson from '../package.json';
const tcpp = require('tcp-ping'); import tcpp from 'tcp-ping';
const util = require('util'); import util from 'util';
const path = require('path'); import path from 'path';
import filesizeParser from 'filesize-parser'; import filesizeParser from 'filesize-parser';
import { pricingPageUrl } from './utils'; import { pricingPageUrl } from './utils';
@@ -18,10 +18,18 @@ let savedSession = undefined;
const userAgent = `react-native-update-cli/${packageJson.version}`; const userAgent = `react-native-update-cli/${packageJson.version}`;
exports.loadSession = async function () { export const getSession = function () {
return session;
};
export const replaceSession = function (newSession) {
session = newSession;
};
export const loadSession = async function () {
if (fs.existsSync('.update')) { if (fs.existsSync('.update')) {
try { try {
exports.replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8'))); replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
savedSession = session; savedSession = session;
} catch (e) { } catch (e) {
console.error( console.error(
@@ -32,15 +40,7 @@ exports.loadSession = async function () {
} }
}; };
exports.getSession = function () { export const saveSession = function () {
return session;
};
exports.replaceSession = function (newSession) {
session = newSession;
};
exports.saveSession = function () {
// Only save on change. // Only save on change.
if (session !== savedSession) { if (session !== savedSession) {
const current = session; const current = session;
@@ -50,7 +50,7 @@ exports.saveSession = function () {
} }
}; };
exports.closeSession = function () { export const closeSession = function () {
if (fs.existsSync('.update')) { if (fs.existsSync('.update')) {
fs.unlinkSync('.update'); fs.unlinkSync('.update');
savedSession = undefined; savedSession = undefined;
@@ -103,13 +103,13 @@ function queryWithBody(method) {
}; };
} }
exports.get = queryWithoutBody('GET'); export const get = queryWithoutBody('GET');
exports.post = queryWithBody('POST'); export const post = queryWithBody('POST');
exports.put = queryWithBody('PUT'); export const put = queryWithBody('PUT');
exports.doDelete = queryWithBody('DELETE'); export const doDelete = queryWithBody('DELETE');
async function uploadFile(fn, key) { export async function uploadFile(fn, key) {
const { url, backupUrl, formData, maxSize } = await exports.post('/upload', { const { url, backupUrl, formData, maxSize } = await post('/upload', {
ext: path.extname(fn), ext: path.extname(fn),
}); });
let realUrl = url; let realUrl = url;
@@ -159,10 +159,6 @@ async function uploadFile(fn, key) {
realUrl, realUrl,
{ {
formData, formData,
headers: {
'User-Agent': userAgent,
'X-AccessToken': session ? session.token : '',
},
}, },
(err, resp, body) => { (err, resp, body) => {
if (err) { if (err) {
@@ -179,5 +175,3 @@ async function uploadFile(fn, key) {
}); });
return info; return info;
} }
exports.uploadFile = uploadFile;

View File

@@ -1,8 +1,8 @@
import { question } from './utils'; import { question } from './utils';
import fs from 'fs'; import fs from 'fs';
const Table = require('tty-table'); import Table from 'tty-table';
const { post, get, doDelete } = require('./api'); import { post, get, doDelete } from './api';
const validPlatforms = { const validPlatforms = {
ios: 1, ios: 1,
@@ -100,7 +100,7 @@ export const commands = {
const platform = checkPlatform( const platform = checkPlatform(
options.platform || (await question('平台(ios/android):')), options.platform || (await question('平台(ios/android):')),
); );
const id = args[0] || (await chooseApp(platform)).id; 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')) {

View File

@@ -1,15 +1,16 @@
const path = require('path'); import path from '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, printVersionCommand } from './utils'; import { question, printVersionCommand } from './utils';
import { checkPlatform } from './app'; import { checkPlatform } from './app';
const { spawn, spawnSync } = require('child_process'); import { spawn, spawnSync } from 'child_process';
const g2js = require('gradle-to-js/lib/parser'); const g2js = require('gradle-to-js/lib/parser');
const os = require('os'); import os from 'os';
const properties = require('properties');
var bsdiff, hdiff, diff; let bsdiff, hdiff, diff;
try { try {
bsdiff = require('node-bsdiff').diff; bsdiff = require('node-bsdiff').diff;
} catch (e) {} } catch (e) {}
@@ -30,9 +31,11 @@ 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') console.warn(
// } 'android的crunchPngs选项似乎尚未禁用如已禁用则请忽略此提示这可能导致热更包体积异常增大具体请参考 https://pushy.reactnative.cn/docs/getting-started.html#%E7%A6%81%E7%94%A8-android-%E7%9A%84-crunch-%E4%BC%98%E5%8C%96 \n',
);
}
} }
let reactNativeBundleArgs = []; let reactNativeBundleArgs = [];
@@ -48,9 +51,27 @@ async function runReactNativeBundleCommand(
fs.emptyDirSync(outputFolder); fs.emptyDirSync(outputFolder);
let cliPath = require.resolve('react-native/local-cli/cli.js', {
paths: [process.cwd()],
});
try {
require.resolve('expo-router', {
paths: [process.cwd()],
});
console.log(`expo-router detected, will use @expo/cli to bundle.\n`);
// if using expo-router, use expo-cli
cliPath = require.resolve('@expo/cli', {
paths: [process.cwd()],
});
} catch (e) {}
const bundleCommand = cliPath.includes('@expo/cli')
? 'export:embed'
: 'bundle';
Array.prototype.push.apply(reactNativeBundleArgs, [ Array.prototype.push.apply(reactNativeBundleArgs, [
path.join('node_modules', 'react-native', 'local-cli', 'cli.js'), cliPath,
'bundle', bundleCommand,
'--assets-dest', '--assets-dest',
outputFolder, outputFolder,
'--bundle-output', '--bundle-output',
@@ -94,8 +115,39 @@ async function runReactNativeBundleCommand(
), ),
); );
} else { } else {
if (gradleConfig.enableHermes) { let hermesEnabled = false;
await compileHermesByteCode(bundleName, outputFolder);
if (platform === 'android') {
const gradlePropeties = await new Promise((resolve) => {
properties.parse(
'./android/gradle.properties',
{ path: true },
function (error, props) {
if (error) {
console.error(error);
resolve(null);
}
resolve(props);
},
);
});
hermesEnabled = gradlePropeties.hermesEnabled;
if (typeof hermesEnabled !== 'boolean')
hermesEnabled = gradleConfig.enableHermes;
} else if (
platform === 'ios' &&
fs.existsSync('ios/Pods/hermes-engine')
) {
hermesEnabled = true;
}
if (hermesEnabled) {
await compileHermesByteCode(
bundleName,
outputFolder,
sourcemapOutput,
);
} }
resolve(null); resolve(null);
} }
@@ -132,35 +184,50 @@ async function checkGradleConfig() {
}; };
} }
async function compileHermesByteCode(bundleName, outputFolder) { async function compileHermesByteCode(
bundleName,
outputFolder,
sourcemapOutput,
) {
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`); console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
const hermesPackage = fs.existsSync('node_modules/hermes-engine') // >= rn 0.69
? 'node_modules/hermes-engine' // 0.2+ const rnDir = path.dirname(
: 'node_modules/hermesvm'; // < 0.2 require.resolve('react-native', {
const hermesPath = `${hermesPackage}/${getHermesOSBin()}`; paths: [process.cwd()],
}),
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' },
); );
let hermesPath = path.join(rnDir, `/sdks/hermesc/${getHermesOSBin()}`);
// < rn 0.69
if (!fs.existsSync(hermesPath)) {
hermesPath = `node_modules/hermes-engine/${getHermesOSBin()}`;
}
const hermesCommand = `${hermesPath}/hermesc`;
const args = [
'-emit-binary',
'-out',
path.join(outputFolder, bundleName),
path.join(outputFolder, bundleName),
'-O',
];
if (sourcemapOutput) {
args.push('-output-source-map');
}
console.log(
'Running hermesc: ' + hermesCommand + ' ' + args.join(' ') + '\n',
);
spawnSync(hermesCommand, args, {
stdio: 'ignore',
});
} }
async function pack(dir, output) { async function pack(dir, output) {
console.log('Packing'); console.log('Packing');
fs.ensureDirSync(path.dirname(output)); fs.ensureDirSync(path.dirname(output));
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
var zipfile = new ZipFile(); const zipfile = new ZipFile();
function addDirectory(root, rel) { function addDirectory(root, rel) {
if (rel) { if (rel) {
@@ -250,7 +317,7 @@ async function diffFromPPK(origin, next, output) {
const copies = {}; const copies = {};
var zipfile = new ZipFile(); const 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) => {
@@ -335,7 +402,7 @@ async function diffFromPPK(origin, next, output) {
const deletes = {}; const deletes = {};
for (var k in originEntries) { for (let k in originEntries) {
if (!newEntries[k]) { if (!newEntries[k]) {
console.log('Delete ' + k); console.log('Delete ' + k);
deletes[k] = 1; deletes[k] = 1;
@@ -392,7 +459,7 @@ async function diffFromPackage(
const copies = {}; const copies = {};
var zipfile = new ZipFile(); const 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) => {
@@ -514,19 +581,13 @@ export const commands = {
options.platform || (await question('平台(ios/android):')), options.platform || (await question('平台(ios/android):')),
); );
let { let { bundleName, entryFile, intermediaDir, output, dev, sourcemap } =
bundleName, translateOptions({
entryFile, ...options,
intermediaDir, platform,
output, });
dev,
verbose,
} = translateOptions({
...options,
platform,
});
// const sourcemapOutput = path.join(intermediaDir, bundleName + ".map"); const sourcemapOutput = path.join(intermediaDir, bundleName + '.map');
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now()); const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
@@ -545,6 +606,7 @@ export const commands = {
entryFile, entryFile,
intermediaDir, intermediaDir,
platform, platform,
sourcemap ? sourcemapOutput : '',
); );
await pack(path.resolve(intermediaDir), realOutput); await pack(path.resolve(intermediaDir), realOutput);

View File

@@ -1,9 +1,9 @@
#!/usr/bin/env node #!/usr/bin/env node
const { loadSession } = require('./api'); import { loadSession } from './api';
const updateNotifier = require('update-notifier'); import updateNotifier from 'update-notifier';
import { printVersionCommand } from './utils/index.js'; import { printVersionCommand } from './utils/index.js';
const pkg = require('../package.json'); import pkg from '../package.json';
updateNotifier({ pkg }).notify({ isGlobal: true }); updateNotifier({ pkg }).notify({ isGlobal: true });

View File

@@ -1,32 +1,33 @@
/** import { get, post, uploadFile } from './api';
* Created by tdzl2003 on 4/2/16.
*/
const { get, post, uploadFile } = require('./api');
import { question, saveToLocal } from './utils'; 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';
const Table = require('tty-table'); import Table from '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)} ${ versionInfo = `, 已绑定:${version.name} (${version.id})`;
version.name
}`;
} 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());
@@ -60,7 +61,7 @@ export const commands = {
} = await getIpaInfo(fn); } = await getIpaInfo(fn);
const { appId, appKey } = await getSelectedApp('ios'); const { appId, appKey } = await getSelectedApp('ios');
if (appIdInPkg && appIdInPkg !== appId) { if (appIdInPkg && appIdInPkg != appId) {
throw new Error( throw new Error(
`appId不匹配当前ipa: ${appIdInPkg}, 当前update.json: ${appId}`, `appId不匹配当前ipa: ${appIdInPkg}, 当前update.json: ${appId}`,
); );
@@ -80,7 +81,9 @@ 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原生包id: ${id}, version: ${versionName}, buildTime: ${buildTime}`,
);
}, },
uploadApk: async function ({ args }) { uploadApk: async function ({ args }) {
const fn = args[0]; const fn = args[0];
@@ -95,7 +98,7 @@ export const commands = {
} = await getApkInfo(fn); } = await getApkInfo(fn);
const { appId, appKey } = await getSelectedApp('android'); const { appId, appKey } = await getSelectedApp('android');
if (appIdInPkg && appIdInPkg !== appId) { if (appIdInPkg && appIdInPkg != appId) {
throw new Error( throw new Error(
`appId不匹配当前apk: ${appIdInPkg}, 当前update.json: ${appId}`, `appId不匹配当前apk: ${appIdInPkg}, 当前update.json: ${appId}`,
); );
@@ -115,7 +118,9 @@ 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原生包id: ${id}, version: ${versionName}, buildTime: ${buildTime}`,
);
}, },
parseIpa: async function ({ args }) { parseIpa: async function ({ args }) {
const fn = args[0]; const fn = args[0];

View File

@@ -1,38 +1,28 @@
/** import { question } from './utils';
* Created by tdzl2003 on 2/13/16. import { post, get, replaceSession, saveSession, closeSession } from './api';
*/ import crypto from 'crypto';
import {question} from './utils';
const {
post,
get,
replaceSession,
saveSession,
closeSession,
} = require('./api');
const crypto = require('crypto');
function md5(str) { function md5(str) {
return crypto.createHash('md5').update(str).digest('hex'); return crypto.createHash('md5').update(str).digest('hex');
} }
exports.commands = { export const commands = {
login: async function ({args}){ login: async function ({ args }) {
const email = args[0] || await question('email:'); const email = args[0] || (await question('email:'));
const pwd = args[1] || await question('password:', true); const pwd = args[1] || (await question('password:', true));
const {token, info} = await post('/user/login', { const { token, info } = await post('/user/login', {
email, email,
pwd: md5(pwd), pwd: md5(pwd),
}); });
replaceSession({token}); replaceSession({ token });
await saveSession(); await saveSession();
console.log(`欢迎使用 pushy 热更新服务, ${info.name}.`); console.log(`欢迎使用 pushy 热更新服务, ${info.name}.`);
}, },
logout: async function (){ logout: async function () {
await closeSession(); await closeSession();
console.log('已退出登录'); console.log('已退出登录');
}, },
me: async function (){ me: async function () {
const me = await get('/user/me'); const me = await get('/user/me');
for (const k in me) { for (const k in me) {
if (k !== 'ok') { if (k !== 'ok') {
@@ -40,4 +30,4 @@ exports.commands = {
} }
} }
}, },
} };

View File

@@ -1,14 +1,10 @@
/**
* Created by tdzl2003 on 2/13/16.
*/
import 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'); import pkg from '../../package.json';
const AppInfoParser = require('app-info-parser'); import AppInfoParser from 'app-info-parser';
var read = require('read'); import read from 'read';
export function question(query, password) { export function question(query, password) {
if (NO_INTERACTIVE) { if (NO_INTERACTIVE) {
@@ -43,7 +39,11 @@ export function translateOptions(options) {
export function getRNVersion() { export function getRNVersion() {
const version = JSON.parse( const version = JSON.parse(
fs.readFileSync(path.resolve('node_modules/react-native/package.json')), fs.readFileSync(
require.resolve('react-native/package.json', {
paths: [process.cwd()],
}),
),
).version; ).version;
// We only care about major and minor version. // We only care about major and minor version.
@@ -106,9 +106,8 @@ export async function getIpaInfo(fn) {
if (updateJsonFile) { if (updateJsonFile) {
appCredential = JSON.parse(updateJsonFile.toString()).ios; appCredential = JSON.parse(updateJsonFile.toString()).ios;
} }
const { const { CFBundleShortVersionString: versionName } =
CFBundleShortVersionString: versionName, await appInfoParser.parse();
} = await appInfoParser.parse();
let buildTimeTxtBuffer = await appInfoParser.parser.getEntry( let buildTimeTxtBuffer = await appInfoParser.parser.getEntry(
/payload\/.+?\.app\/pushy_build_time.txt/, /payload\/.+?\.app\/pushy_build_time.txt/,
); );
@@ -139,11 +138,11 @@ export function saveToLocal(originPath, destName) {
export function printVersionCommand() { export function printVersionCommand() {
console.log('react-native-update-cli: ' + pkg.version); console.log('react-native-update-cli: ' + pkg.version);
try { try {
const PACKAGE_JSON_PATH = path.resolve( const PACKAGE_JSON_PATH = require.resolve(
process.cwd(), 'react-native-update/package.json',
'node_modules', {
'react-native-update', paths: [process.cwd()],
'package.json', },
); );
console.log('react-native-update: ' + require(PACKAGE_JSON_PATH).version); console.log('react-native-update: ' + require(PACKAGE_JSON_PATH).version);
} catch (e) { } catch (e) {

View File

@@ -1,4 +1,4 @@
const { get, post, put, uploadFile } = require('./api'); import { get, post, put, uploadFile } from './api';
import { question, saveToLocal } from './utils'; import { question, saveToLocal } from './utils';
import { checkPlatform, getSelectedApp } from './app'; import { checkPlatform, getSelectedApp } from './app';
@@ -124,20 +124,22 @@ export const commands = {
); );
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;
let pkgId = options.packageId;
if (!pkgId) { let pkgId;
let pkgVersion = options.packageVersion; let pkgVersion = options.packageVersion;
if (pkgVersion) { if (pkgVersion) {
pkgVersion = pkgVersion.trim(); pkgVersion = pkgVersion.trim();
const { data } = await get(`/app/${appId}/package/list?limit=1000`); const { data } = await get(`/app/${appId}/package/list?limit=1000`);
const pkg = data.find((d) => d.name === pkgVersion); const pkg = data.find((d) => d.name === pkgVersion);
if (pkg) { if (pkg) {
pkgId = pkg.id; pkgId = pkg.id;
} else { } else {
throw new Error(`未查询到匹配原生版本:${pkgVersion}`); throw new Error(`未查询到匹配原生版本:${pkgVersion}`);
}
} }
} }
if (!pkgId) {
pkgId = options.packageId || (await choosePackage(appId)).id;
}
if (!pkgId) { if (!pkgId) {
throw new Error('请提供 packageId 或 packageVersion 参数'); throw new Error('请提供 packageId 或 packageVersion 参数');
@@ -147,4 +149,18 @@ export const commands = {
}); });
console.log('操作成功'); console.log('操作成功');
}, },
updateVersionInfo: async function ({ args, options }) {
const platform = checkPlatform(
options.platform || (await question('平台(ios/android):')),
);
const { appId } = await getSelectedApp(platform);
const versionId = options.versionId || (await chooseVersion(appId)).id;
const updateParams = {};
options.name && (updateParams.name = options.name);
options.description && (updateParams.description = options.description);
options.metaInfo && (updateParams.metaInfo = options.metaInfo);
await put(`/app/${appId}/version/${versionId}`, updateParams);
console.log('操作成功');
},
}; };