1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-16 12:51:44 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Compare commits

...

10 Commits
5.1.9 ... 5.2.1

Author SHA1 Message Date
sunnylqm
976cc5f218 - npmrc 2019-07-22 22:53:16 +08:00
sunnylqm
6fd04a1cc3 Bump 5.2.1 2019-07-22 22:52:02 +08:00
sunnylqm
31a0eadbbf Support hermes bytecode 2019-07-22 22:48:39 +08:00
sunnylqm
6f0755e571 最近更新移到单独的文档 2019-07-06 22:58:31 +08:00
sunnylqm
4099986a9c 0.60的文档说明 2019-07-06 22:44:09 +08:00
sunnylqm
48101bbd51 Bump version 2019-07-06 22:29:13 +08:00
sunnylqm
1c2507e631 改进类型声明 2019-07-06 22:26:50 +08:00
sunnylqm
b5e273deef 添加podspec 2019-07-06 21:53:08 +08:00
sunnylqm
b55a40c92c 添加ts声明 2019-07-06 21:52:34 +08:00
sunnylqm
d23178a851 更新0.60相关的说明文档 2019-07-05 00:52:00 +08:00
8 changed files with 198 additions and 71 deletions

31
CHANGELOG.MD Normal file
View File

@@ -0,0 +1,31 @@
### 最新更新
## 5.2.1
1. 检测如果开启了hermes则自动编译为hermes字节码格式
## 5.2.0
1. 添加typescript声明
2. 支持cocoapods
## 5.1.9
1. 重写bundle命令以提升版本兼容性
2. 改进命令行的输出样式
## 5.1.8
1. 服务器迁移到https
2. android支持64位
## 5.1.6
解决 Android 热更新后部分图片丢失问题:
同一个项目中放置了多个完全相同的文件,在 5.1.0 至 5.1.5 之间的版本中,更新后有时会出现其中的部分无法显示。此问题在 5.1.6 版本修复。
修复此问题涉及原生部分,需要重新打包。

View File

@@ -2,20 +2,6 @@
本组件是面向 React Native 提供热更新功能的组件,建议结合[Update 服务](https://update.reactnative.cn/)使用。
### 最新更新
5.1.6: 解决 Android 热更新后部分图片丢失问题:
同一个项目中放置了多个完全相同的文件,在 5.1.0 至 5.1.5 之间的版本中,更新后有时会出现其中的部分无法显示。此问题在 5.1.6 版本修复。
修复此问题涉及原生部分,需要重新打包。
5.1.0 以上的版本增加了如下的优化:
1. 在项目中图片较多时Android 更新速度大幅提升,达到和 iOS 基本一致的更新速度。
2. Android 的更新移到了单独的线程,避免更新过程对 AsyncStorage 等原生异步模块的影响。
3. Android 的.so 文件长时间没有任何改动,因而加入了预编译好的文件,避免对 ndk 的依赖。
### 版本
因为 React Native 不同版本代码结构不同,因而请按下面表格对号入座:

View File

@@ -15,10 +15,13 @@
```bash
npm i -g react-native-update-cli
npm i react-native-update@具体版本请看下面的表格
react-native link react-native-update
```
`npm install -g react-native-update-cli`这一句在每一台电脑上仅需运行一次。
如果你的RN版本 < 0.60,那么还需要运行
```bash
react-native link react-native-update
```
* 注意 *
@@ -41,7 +44,6 @@ nrm use taobao
| 0.46及以上 | 5.x |
安装命令示例:
```
npm i react-native-update@5.x
@@ -49,7 +51,7 @@ npm i react-native-update@5.x
## 一、手动link
如果第一步的`react-native link`成功(iOS工程和安卓工程均能看到依赖),可以跳过此步骤
如果RN版本 >= 0.60,或是`react-native link`执行成功(iOS工程和安卓工程均能看到依赖)可以跳过此步骤
### iOS
@@ -69,43 +71,57 @@ npm i react-native-update@5.x
2. 在`android/app/build.gradle`的 dependencies 部分增加如下代码:
```
compile project(':react-native-update')
implementation project(':react-native-update')
```
3. 检查你的RN版本,如果是0.29及以上, 打开`android/app/src/main/java/[...]/MainApplication.java`,否则打开`android/app/src/main/java/[...]/MainActivity.java`
3. 打开`android/app/src/main/java/[...]/MainApplication.java`,
- 在文件开头增加 `import cn.reactnative.modules.update.UpdatePackage;`
- 在`getPackages()` 方法中增加 `new UpdatePackage()`(注意上一行可能要增加一个逗号)
## 二、配置Bundle URL
注意此步骤无论任何版本,目前都需要手动配置。
### iOS
首先在工程target的Build Phases->Link Binary with Libraries中加入`libz.tbd`、`libbz2.1.0.tbd`
1. (RN >= 0.60或者使用CocoaPods集成此步可跳过)在工程target的Build Phases->Link Binary with Libraries中加入`libz.tbd`、`libbz2.1.0.tbd`
然后在你的AppDelegate.m文件中增加如下代码
2. 在你的AppDelegate.m文件中增加如下代码
```objective-c
// ... 其它代码
#import "RCTHotUpdate.h"
// 如果RN版本 >= 0.59修改sourceURLForBridge
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
 // 非DEBUG情况下替换为热更新bundle
return [RCTHotUpdate bundleURL];
#endif
}
// 如果RN版本 < 0.59修改didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#if DEBUG
 // 原来的jsCodeLocation保留在这里
 jsCodeLocation = ..........
#else
 // 非DEBUG情况下启用热更新
 jsCodeLocation=[RCTHotUpdate bundleURL];
 // 非DEBUG情况下替换为热更新bundle
 jsCodeLocation = [RCTHotUpdate bundleURL];
#endif
// ... 其它代码
}
```
### Android
`0.29及以后版本`:在你的MainApplication中增加如下代码
MainApplication中增加如下代码
```java
// ... 其它代码
@@ -124,24 +140,6 @@ public class MainApplication extends Application implements ReactApplication {
}
```
`0.28及以前版本`在你的MainActivity中增加如下代码
```java
// ... 其它代码
// 请注意不要少了这句import
import cn.reactnative.modules.update.UpdateContext;
public class MainActivity extends ReactActivity {
@Override
protected String getJSBundleFile() {
return UpdateContext.getBundleUrl(this);
}
// ... 其它代码
}
```
## 三、登录与创建应用
首先请在<https://update.reactnative.cn>注册帐号,然后在你的项目根目录下运行以下命令:
@@ -170,7 +168,7 @@ App Name: <输入应用名字>
```bash
$ pushy selectApp --platform ios
1) 鱼多多(ios)
3) 招财旺(ios)
2) 招财旺(ios)
Total 2 ios apps
Enter appId: <输入应用前面的编号>

37
index.d.ts vendored Normal file
View File

@@ -0,0 +1,37 @@
export const downloadRootDir: string;
export const packageVersion: string;
export const currentVersion: string;
export const isFirstTime: boolean;
export const isRolledBack: boolean;
export interface ExpiredResult {
expired: true;
downloadUrl: string;
}
export interface UpTodateResult {
upToDate: true;
}
export interface UpdateAvailableResult {
update: true;
name: string; // version name
hash: string;
description: string;
metaInfo: string;
updateUrl: string;
pdiffUrl: string;
diffUrl: string;
}
export type CheckResult = Partial<ExpiredResult & UpTodateResult & UpdateAvailableResult>;
export function checkUpdate(appkey: string): Promise<CheckResult>;
export function downloadUpdate(options: UpdateAvailableResult): Promise<undefined | string>;
export function switchVersion(hash: string): void;
export function switchVersionLater(hash: string): void;
export function markSuccess(): void;

View File

@@ -2,15 +2,16 @@
* Created by tdzl2003 on 2/22/16.
*/
import * as path from 'path';
const path = require('path');
import { getRNVersion, translateOptions } from './utils';
import * as fs from 'fs-extra';
import { ZipFile } from 'yazl';
import { open as openZipFile } from 'yauzl';
// import {diff} from 'node-bsdiff';
import { question } from './utils';
import { checkPlatform } from './app';
const { spawn } = require('child_process');
const { spawn, spawnSync } = require('child_process');
const g2js = require('gradle-to-js/lib/parser');
const os = require('os');
var diff;
try {
@@ -19,12 +20,22 @@ try {
} catch (e) {
diff = function() {
console.warn(
'This function needs "node-bsdiff". Please run "npm i node-bsdiff -S" from your project directory first!',
'This function needs "node-bsdiff". Please run "npm i node-bsdiff" from your project directory first!',
);
throw new Error('This function needs module "node-bsdiff". Please install it first.');
};
}
function exec(command) {
const commandResult = spawnSync(command, {
shell: true,
stdio: 'inherit',
});
if (commandResult.error) {
throw commandResult.error;
}
}
async function runReactNativeBundleCommand(
bundleName,
development,
@@ -45,8 +56,6 @@ async function runReactNativeBundleCommand(
fs.emptyDirSync(outputFolder);
Array.prototype.push.apply(reactNativeBundleArgs, [
path.join('node_modules', 'react-native', 'local-cli', 'cli.js'),
'bundle',
'--assets-dest',
outputFolder,
'--bundle-output',
@@ -67,27 +76,45 @@ async function runReactNativeBundleCommand(
reactNativeBundleArgs.push('--config', config);
}
console.log(`Running "react-native bundle" command:\n`);
const reactNativeBundleProcess = spawn('node', reactNativeBundleArgs);
console.log(`node ${reactNativeBundleArgs.join(' ')}`);
try {
exec(`
echo Running "react-native bundle" command:
react-native bundle ${reactNativeBundleArgs.join(' ')}
`);
if (platform === 'android') {
await compileHermesByteCode(bundleName, outputFolder);
}
} catch (e) {
console.log(e);
process.exit(1);
}
}
return new Promise((resolve, reject, notify) => {
reactNativeBundleProcess.stdout.on('data', data => {
console.log(data.toString().trim());
});
function getHermesOSBin() {
if (os.platform() === 'win32') return 'win64-bin';
if (os.platform() === 'darwin') return 'osx-bin';
if (os.platform() === 'linux') return 'linux64-bin';
}
reactNativeBundleProcess.stderr.on('data', data => {
console.error(data.toString().trim());
});
reactNativeBundleProcess.on('close', exitCode => {
if (exitCode) {
reject(new Error(`"react-native bundle" command exited with code ${exitCode}.`));
async function compileHermesByteCode(bundleName, outputFolder) {
let enableHermes = false;
try {
const gradleConfig = await g2js.parseFile('android/app/build.gradle');
const projectConfig = gradleConfig['project.ext.react'];
for (const packagerConfig of projectConfig) {
if (packagerConfig.includes('enableHermes') && packagerConfig.includes('true')) {
enableHermes = true;
break;
}
resolve(null);
});
});
}
} catch (e) {}
if (enableHermes) {
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
exec(`
node_modules/hermesvm/${getHermesOSBin()}/hermes -emit-binary -out ${outputFolder}/${bundleName} ${outputFolder}/${bundleName} -O
echo Compiling done.
`);
}
}
async function pack(dir, output) {
@@ -398,7 +425,6 @@ export const commands = {
// console.log('Bundling with React Native version: ', version);
await runReactNativeBundleCommand(bundleName, dev, entryFile, intermediaDir, platform);
await pack(path.resolve(intermediaDir), realOutput);

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "5.1.9",
"version": "5.2.1",
"description": "react-native hot update",
"main": "lib/index.js",
"scripts": {
@@ -32,6 +32,7 @@
"decompress-zip": "^0.3.1",
"fs-extra": "^8.1.0",
"glob": "^7.1.2",
"gradle-to-js": "^2.0.0",
"isomorphic-fetch": "^2.2.1",
"node-apk-parser": "^0.2.3",
"progress": "^1.1.8",

View File

@@ -0,0 +1,36 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
Pod::Spec.new do |s|
s.name = package['name']
s.version = package['version']
s.summary = package['description']
s.license = package['license']
s.authors = package['author']
s.homepage = package['homepage']
s.platform = :ios, "7.0"
s.source = { :git => 'https://github.com/reactnativecn/react-native-pushy.git', :tag => '#{s.version}' }
s.libraries = 'bz2', 'z'
s.vendored_libraries = 'RCTHotUpdate/libRCTHotUpdate.a'
s.pod_target_xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '"$(SRCROOT)/../node_modules/react-native-update/ios"' }
s.dependency 'React'
s.subspec 'RCTHotUpdate' do |ss|
ss.source_files = 'ios/RCTHotUpdate/*.{h,m}'
ss.public_header_files = ['ios/RCTHotUpdate/RCTHotUpdate.h']
end
s.subspec 'SSZipArchive' do |ss|
ss.source_files = 'ios/RCTHotUpdate/SSZipArchive/**/*.{h,m,c}'
ss.private_header_files = 'ios/RCTHotUpdate/SSZipArchive/**/*.h'
end
s.subspec 'BSDiff' do |ss|
ss.source_files = 'ios/RCTHotUpdate/BSDiff/**/*.{h,m,c}'
ss.private_header_files = 'ios/RCTHotUpdate/BSDiff/**/*.h'
end
end

View File

@@ -1201,6 +1201,13 @@ graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "1.0.1"
resolved "http://registry.npm.taobao.org/graceful-readlink/download/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
gradle-to-js@^2.0.0:
version "2.0.0"
resolved "https://registry.npm.taobao.org/gradle-to-js/download/gradle-to-js-2.0.0.tgz#b790a97376d3d713105a086590e569610f7e6bc4"
integrity sha1-t5Cpc3bT1xMQWghlkOVpYQ9+a8Q=
dependencies:
lodash.merge "4.6.2"
har-validator@~2.0.6:
version "2.0.6"
resolved "http://registry.npm.taobao.org/har-validator/download/har-validator-2.0.6.tgz#cdcbc08188265ad119b6a5a7c8ab70eecfb5d27d"
@@ -1601,6 +1608,11 @@ lodash.keysin@^3.0.0:
lodash.isarguments "^3.0.0"
lodash.isarray "^3.0.0"
lodash.merge@4.6.2:
version "4.6.2"
resolved "https://registry.npm.taobao.org/lodash.merge/download/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
integrity sha1-VYqlO0O2YeGSWgr9+japoQhf5Xo=
lodash.pick@^3.1.0:
version "3.1.0"
resolved "http://registry.npm.taobao.org/lodash.pick/download/lodash.pick-3.1.0.tgz#f252a855b2046b61bcd3904b26f76bd2efc65550"