mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 12:51:44 +08:00
Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
437eb4f10f | ||
![]() |
5053a89cfa | ||
![]() |
6a031f598f | ||
![]() |
7ecf879ac9 | ||
![]() |
c779befa86 | ||
![]() |
19f060abf5 | ||
![]() |
b9c655312e | ||
![]() |
2ad4635bc6 | ||
![]() |
0d3f95d2bd | ||
![]() |
36568356dc | ||
![]() |
1a3681f308 | ||
![]() |
81f6e57413 | ||
![]() |
46c7aa88dd | ||
![]() |
22a2902f71 | ||
![]() |
e9755392ec | ||
![]() |
c28eec436d | ||
![]() |
c46fb1be3a | ||
![]() |
1d0fb7d260 | ||
![]() |
bdd97ac6ac | ||
![]() |
ba3e92e3b8 | ||
![]() |
3939607f49 | ||
![]() |
8d06235ea3 | ||
![]() |
fa754ef8a2 | ||
![]() |
5a5884c8fa | ||
![]() |
8bd92f2c0e | ||
![]() |
3ac2e3ef05 | ||
![]() |
523cbdd7e1 | ||
![]() |
dece044a54 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,8 +1,5 @@
|
||||
/.idea
|
||||
/node_modules
|
||||
/local-cli/lib
|
||||
/react-native-pushy-cli/node_modules
|
||||
/react-native-pushy-cli/lib
|
||||
/android/build
|
||||
/android/obj
|
||||
*.iml
|
||||
|
@@ -4,8 +4,6 @@
|
||||
/.eslintrc
|
||||
/.nvmrc
|
||||
/.travis.yml
|
||||
/local-cli/src
|
||||
/react-native-pushy-cli
|
||||
/Example
|
||||
/android/build
|
||||
|
||||
@@ -45,4 +43,6 @@ node_modules/
|
||||
npm-debug.log
|
||||
Example
|
||||
yarn.lock
|
||||
android/jni
|
||||
android/jni
|
||||
|
||||
domains.json
|
@@ -1,5 +1,4 @@
|
||||
module.exports = {
|
||||
printWidth: 120,
|
||||
trailingComma: 'all',
|
||||
singleQuote: true,
|
||||
};
|
||||
|
@@ -4,6 +4,7 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:usesCleartextTraffic="true"
|
||||
android:name=".MainApplication"
|
||||
android:label="@string/app_name"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
49
README.md
49
README.md
@@ -1,31 +1,10 @@
|
||||
# react-native-update [](http://badge.fury.io/js/react-native-update)
|
||||
|
||||
本组件是面向 React Native 提供热更新功能的组件,建议结合[Update 服务](https://update.reactnative.cn/)使用。
|
||||
本组件是面向 React Native 提供热更新功能的组件,请结合[Update 服务](https://update.reactnative.cn/)使用。
|
||||
|
||||
注意,在 iOS 上使用热更新有被拒的可能。被拒之后可以按以下步骤单独屏蔽 iOS 端(`react-native-update`版本需 >= 5.3.2):
|
||||
### 快速开始
|
||||
|
||||
1. 如果 RN 版本>=0.60,在项目根目录下编辑或创建 react-native.config.js,添加如下内容
|
||||
|
||||
```js
|
||||
// react-native.config.js
|
||||
module.exports = {
|
||||
dependencies: {
|
||||
'react-native-update': {
|
||||
platforms: {
|
||||
ios: null, // 阻止ios模块自动链接
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
2. 如果在原生代码端尚未配置,则跳过下面文档中的 ios 端的配置。如果已经配置,则按文档的步骤反向操作(添加的 ios 代码删去)。
|
||||
3. 如果是 0.60 以上版本或使用了 cocoapods,在 ios 目录中再次运行 pod install,确保 Podfile 和 Podfile.lock 中都没有'react-native-update'。如果 RN 版本<0.60,则运行`react-native unlink react-native-update`。
|
||||
4. 在 js 代码里调用 checkUpdate()方法前,判断 Platform.OS,如果是 ios 平台则直接 return 跳过。
|
||||
|
||||
### 最近更新
|
||||
|
||||
请查阅[最近更新文档](CHANGELOG.md)。
|
||||
请查看[文档](https://reactnativecn.github.io/react-native-pushy)
|
||||
|
||||
### 优势
|
||||
|
||||
@@ -35,26 +14,6 @@ module.exports = {
|
||||
4. meta 信息及开放 API,提供更高扩展性。
|
||||
5. 跨越多个版本进行更新时,只需要下载**一个更新包**,不需要逐版本依次更新。
|
||||
|
||||
### 安装与快速入门
|
||||
|
||||
请查阅
|
||||
|
||||
- [文档-快速入门-准备工作](docs/guide.md)。
|
||||
|
||||
- [文档-快速入门-添加热更新功能](docs/guide2.md)。
|
||||
|
||||
- [文档-快速入门-发布版本](docs/guide3.md)。
|
||||
|
||||
- [文档-常见问题与高级指南](docs/faq_advance.md)。
|
||||
|
||||
### 命令行工具
|
||||
|
||||
请查阅[文档-命令行工具](docs/cli.md)。
|
||||
|
||||
### API 接口
|
||||
|
||||
请查阅[文档-API 接口](docs/api.md)。
|
||||
|
||||
### 本地开发
|
||||
|
||||
```
|
||||
@@ -70,4 +29,4 @@ $ yarn start
|
||||
|
||||
本组件由[React Native 中文网](https://reactnative.cn/)独家发布,如有定制需求可以[联系我们](https://reactnative.cn/about.html#content)。
|
||||
|
||||
关于此插件发现任何问题,可以前往[Issues](https://github.com/reactnativecn/react-native-pushy/issues)或者[中文社区](http://bbs.reactnative.cn/category/7)发帖提问。
|
||||
关于此插件发现任何问题,可以前往[Issues](https://github.com/reactnativecn/react-native-pushy/issues)发帖提问。
|
||||
|
@@ -96,6 +96,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||
double lastProgressValue=0;
|
||||
while ((bytesRead = source.read(sink.buffer(), DOWNLOAD_CHUNK_SIZE)) != -1) {
|
||||
totalRead += bytesRead;
|
||||
sink.emit();
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.d("RNUpdate", "Progress " + totalRead + "/" + contentLength);
|
||||
}
|
||||
|
@@ -4,6 +4,8 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@@ -18,7 +20,8 @@ public class UpdateContext {
|
||||
private File rootDir;
|
||||
private Executor executor;
|
||||
|
||||
public static boolean DEBUG = false;
|
||||
public static boolean DEBUG = true;
|
||||
private static ReactInstanceManager mReactInstanceManager;
|
||||
|
||||
public UpdateContext(Context context) {
|
||||
this.context = context;
|
||||
@@ -106,8 +109,8 @@ public class UpdateContext {
|
||||
private SharedPreferences sp;
|
||||
|
||||
public void switchVersion(String hashName) {
|
||||
if (!new File(rootDir, hashName).exists()) {
|
||||
throw new Error("Hash name not found, must download first.");
|
||||
if (!new File(rootDir, hashName+"/index.bundlejs").exists()) {
|
||||
throw new Error("Bundle version " + hashName + " not found.");
|
||||
}
|
||||
String lastVersion = getCurrentVersion();
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
@@ -158,6 +161,15 @@ public class UpdateContext {
|
||||
this.clearUp();
|
||||
}
|
||||
|
||||
|
||||
public static void setCustomInstanceManager(ReactInstanceManager instanceManager) {
|
||||
mReactInstanceManager = instanceManager;
|
||||
}
|
||||
|
||||
public ReactInstanceManager getCustomReactInstanceManager() {
|
||||
return mReactInstanceManager;
|
||||
}
|
||||
|
||||
public static String getBundleUrl(Context context) {
|
||||
return new UpdateContext(context.getApplicationContext()).getBundleUrl();
|
||||
}
|
||||
@@ -182,10 +194,18 @@ public class UpdateContext {
|
||||
currentVersion = this.rollBack();
|
||||
}
|
||||
}
|
||||
if (currentVersion == null) {
|
||||
return defaultAssetsUrl;
|
||||
|
||||
while (currentVersion != null) {
|
||||
File bundleFile = new File(rootDir, currentVersion+"/index.bundlejs");
|
||||
if (!bundleFile.exists()) {
|
||||
Log.e("getBundleUrl", "Bundle version " + currentVersion + " not found.");
|
||||
currentVersion = this.rollBack();
|
||||
continue;
|
||||
}
|
||||
return bundleFile.toString();
|
||||
}
|
||||
return (new File(rootDir, currentVersion+"/index.bundlejs").toString());
|
||||
|
||||
return defaultAssetsUrl;
|
||||
}
|
||||
|
||||
private String rollBack() {
|
||||
|
@@ -123,11 +123,15 @@ public class UpdateModule extends ReactContextBaseJavaModule{
|
||||
UiThreadUtil.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateContext.switchVersion(hash);
|
||||
try {
|
||||
updateContext.switchVersion(hash);
|
||||
Activity activity = getCurrentActivity();
|
||||
Application application = activity.getApplication();
|
||||
ReactInstanceManager instanceManager = ((ReactApplication) application).getReactNativeHost().getReactInstanceManager();
|
||||
ReactInstanceManager instanceManager = updateContext.getCustomReactInstanceManager();
|
||||
|
||||
if (instanceManager == null) {
|
||||
instanceManager = ((ReactApplication) application).getReactNativeHost().getReactInstanceManager();
|
||||
}
|
||||
|
||||
try {
|
||||
Field jsBundleField = instanceManager.getClass().getDeclaredField("mJSBundleFile");
|
||||
@@ -147,7 +151,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{
|
||||
}
|
||||
|
||||
} catch (Throwable err) {
|
||||
Log.e("pushy", "Failed to restart application", err);
|
||||
Log.e("pushy", "switchVersion failed", err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -160,7 +164,11 @@ public class UpdateModule extends ReactContextBaseJavaModule{
|
||||
UiThreadUtil.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateContext.switchVersion(hash);
|
||||
try {
|
||||
updateContext.switchVersion(hash);
|
||||
} catch (Throwable err) {
|
||||
Log.e("pushy", "switchVersionLater failed", err);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
0
docs/.nojekyll
Normal file
0
docs/.nojekyll
Normal file
53
docs/README.md
Normal file
53
docs/README.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# react-native-update [](http://badge.fury.io/js/react-native-update)
|
||||
|
||||
本组件是面向 React Native 提供热更新功能的组件,请结合[Update 服务](https://update.reactnative.cn/)使用。
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
注意,在 iOS 上使用热更新有被拒的可能。被拒之后可以按此步骤单独屏蔽 iOS 端(`react-native-update`版本需 >= 5.3.2):
|
||||
</summary>
|
||||
|
||||
1. 如果 RN 版本>=0.60,在项目根目录下编辑或创建 react-native.config.js,添加如下内容
|
||||
|
||||
```js
|
||||
// react-native.config.js
|
||||
module.exports = {
|
||||
dependencies: {
|
||||
'react-native-update': {
|
||||
platforms: {
|
||||
ios: null, // 阻止ios模块自动链接
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
2. 如果在原生代码端尚未配置,则跳过下面文档中的 ios 端的配置。如果已经配置,则按文档的步骤反向操作(添加的 ios 代码删去)。
|
||||
3. 如果是 0.60 以上版本或使用了 cocoapods,在 ios 目录中再次运行 pod install,确保 Podfile 和 Podfile.lock 中都没有'react-native-update'。如果 RN 版本<0.60,则运行`react-native unlink react-native-update`。
|
||||
4. 在 js 代码里调用 checkUpdate()方法前,判断 Platform.OS,如果是 ios 平台则直接 return 跳过。
|
||||
</details>
|
||||
|
||||
### 优势
|
||||
|
||||
1. 命令行工具&网页双端管理,版本发布过程简单便捷,完全可以集成 CI。
|
||||
2. 基于 bsdiff 算法创建的**超小更新包**,通常版本迭代后在 1-10KB 之间,避免数百 KB 的流量消耗。
|
||||
3. 支持崩溃回滚,安全可靠。
|
||||
4. meta 信息及开放 API,提供更高扩展性。
|
||||
5. 跨越多个版本进行更新时,只需要下载**一个更新包**,不需要逐版本依次更新。
|
||||
|
||||
### 本地开发
|
||||
|
||||
```
|
||||
$ git clone git@github.com:reactnativecn/react-native-pushy.git
|
||||
$ cd react-native-pushy/Example/testHotUpdate
|
||||
$ yarn
|
||||
$ yarn start
|
||||
```
|
||||
|
||||
本地库文件使用 yarn link 链接,因此可直接在源文件中修改,在 testHotUpdate 项目中调试。
|
||||
|
||||
### 关于我们
|
||||
|
||||
本组件由[React Native 中文网](https://reactnative.cn/)独家发布,如有定制需求可以[联系我们](https://reactnative.cn/about.html#content)。
|
||||
|
||||
关于此插件发现任何问题,可以前往[Issues](https://github.com/reactnativecn/react-native-pushy/issues)或者[中文社区](http://bbs.reactnative.cn/category/7)发帖提问。
|
10
docs/_sidebar.md
Normal file
10
docs/_sidebar.md
Normal file
@@ -0,0 +1,10 @@
|
||||
- 安装与快速入门
|
||||
|
||||
- [准备工作](guide.md)
|
||||
- [添加热更新功能](guide2.md)
|
||||
- [发布版本](guide3.md)
|
||||
- [常见问题与高级指南](faq_advance.md)
|
||||
|
||||
- [API接口](api.md)
|
||||
- [命令行工具](cli.md)
|
||||
- [最近更新](changelog.md)
|
@@ -6,11 +6,11 @@
|
||||
|
||||
### packageVersion
|
||||
|
||||
当前应用包的版本名。
|
||||
当前应用原生包的版本。其中android取自`versionName`字段(位于`android/build.gralde`中)。ios取自`CFBundleShortVersionString`字段(位于`ios/项目名/Info.plist`中)。
|
||||
|
||||
### currentVersion
|
||||
|
||||
当前版本的Hash号。
|
||||
当前热更新版本(jsbundle文件)的Hash号。
|
||||
|
||||
### isFirstTime
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
检查更新,返回值有三种情形:
|
||||
|
||||
1. `{expired: true}`:该应用包(原生部分)已过期,需要前往应用市场下载新的版本。
|
||||
1. `{expired: true}`:该应用原生包已过期,需要前往应用市场下载新的版本。
|
||||
```
|
||||
{
|
||||
expired: true,
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
3. `{update: true}`:当前有新版本可以更新。info的`name`、`description`字段可
|
||||
以用于提示用户,而`metaInfo`字段则可以根据你的需求自定义其它属性(如是否静默更新、
|
||||
是否强制更新等等)。另外还有几个字段,包含了完整更新包或补丁包的下载地址,
|
||||
是否强制更新等等)。另外还有几个字段,包含了热更新文件的下载地址,
|
||||
```
|
||||
{
|
||||
update: true,
|
||||
@@ -43,7 +43,6 @@
|
||||
hash: 'hash',
|
||||
description: '添加聊天功能\n修复商城页面BUG',
|
||||
metaInfo: '{"silent":true}',
|
||||
updateUrl: 'http://update-packages.reactnative.cn/hash',
|
||||
pdiffUrl: 'http://update-packages.reactnative.cn/hash',
|
||||
diffUrl: 'http://update-packages.reactnative.cn/hash',
|
||||
}
|
||||
|
@@ -1,5 +1,23 @@
|
||||
### 最近更新
|
||||
|
||||
## 5.5.6 (2020-02-11)
|
||||
|
||||
1. bundle时清除缓存
|
||||
2. 修复更新包过大时可能出现的崩溃
|
||||
3. publish时检查文件格式
|
||||
|
||||
## 5.5.5 (2020-01-18)
|
||||
|
||||
1. 提升服务健壮性
|
||||
|
||||
## 5.5.4 (2020-01-13)
|
||||
|
||||
1. 防止某些情况下安卓找不到bundle文件引起的崩溃
|
||||
|
||||
## 5.5.3 (2019-12-18)
|
||||
|
||||
1. 忽略hermes的输出避免buffer溢出
|
||||
|
||||
## 5.5.2 (2019-12-06)
|
||||
|
||||
1. 修复使用use_frameworks时无法读取时间戳的问题
|
18
docs/cli.md
18
docs/cli.md
@@ -4,7 +4,7 @@
|
||||
|
||||
```
|
||||
$ npm install -g react-native-update-cli
|
||||
$ npm install --save react-native-update
|
||||
$ npm install react-native-update
|
||||
```
|
||||
|
||||
## 使用
|
||||
@@ -90,18 +90,18 @@ $ npm install --save react-native-update
|
||||
|
||||
#### pushy packages
|
||||
|
||||
查看已经上传的包。这项操作也可以在网页管理端进行。
|
||||
查看已经上传的原生包。这项操作也可以在网页管理端进行。
|
||||
|
||||
- platform: ios|android 对应的平台
|
||||
|
||||
#### pushy publish <ppkFile>
|
||||
|
||||
发布新的更新版本。
|
||||
发布新的热更新版本(ppk文件)。
|
||||
|
||||
- platform: ios|android 对应的平台
|
||||
- name: 当前版本的名字(版本号)
|
||||
- description: 当前版本的描述信息,可以对用户进行展示
|
||||
- metaInfo: 当前版本的元信息,可以用来保存一些额外信息
|
||||
- name: 当前热更新版本的名字(版本号)
|
||||
- description: 当前热更新版本的描述信息,可以对用户进行展示
|
||||
- metaInfo: 当前热更新版本的元信息,可以用来保存一些额外信息
|
||||
|
||||
#### pushy versions
|
||||
|
||||
@@ -111,8 +111,8 @@ $ npm install --save react-native-update
|
||||
|
||||
#### pushy update
|
||||
|
||||
为一个包版本绑定一个更新版本。这项操作也可以在网页管理端进行。
|
||||
为一个原生包版本绑定一个热更新版本。这项操作也可以在网页管理端进行。
|
||||
|
||||
- platform: ios|android 对应的平台
|
||||
- versionId: 要绑定的版本 ID
|
||||
- packageId: 要绑定的包 ID
|
||||
- versionId: 要绑定的热更新版本 ID
|
||||
- packageId: 要绑定的原生包 ID
|
||||
|
@@ -57,7 +57,7 @@
|
||||
|
||||
目前我们的热更新服务完全免费,但限制每个账号不超过3个应用;每个应用不超过10个活跃的包和100个活跃的热更新版本;每个应用每个月不超过10000次下载。iOS和Android版本记做不同的应用。
|
||||
|
||||
已经移除的应用、包版本、热更新版本不在统计之列,所以你可以移除测试时产生的和已过期版本来更有效的利用空间。
|
||||
已经移除的应用、原生包版本、热更新版本不在统计之列,所以你可以移除测试时产生的和已过期版本来更有效的利用空间。
|
||||
|
||||
我们会在将来推出付费的升级版本,针对用户量较大、版本迭代较快的用户提供扩容方案。如果您有急迫的需求,可以[联系我们](https://reactnative.cn/about.html#content)。
|
||||
|
||||
|
@@ -52,7 +52,7 @@ npm i react-native-update@4.x
|
||||
请记得一定要重新编译(react-native run-ios或run-android命令编译,或在Xcode/Android Studio中重新编译)。
|
||||
|
||||
|
||||
## 一、手动link
|
||||
## 手动link
|
||||
|
||||
如果RN版本 >= 0.60则可以跳过此步骤
|
||||
|
||||
@@ -112,7 +112,7 @@ date +%s > "$DEST/pushy_build_time.txt"
|
||||
- 在`getPackages()` 方法中增加 `new UpdatePackage()`(注意上一行可能要增加一个逗号)
|
||||
</details>
|
||||
|
||||
## 二、配置Bundle URL
|
||||
## 配置Bundle URL
|
||||
|
||||
注意此步骤无论任何版本,目前都需要手动配置。
|
||||
|
||||
@@ -174,7 +174,7 @@ public class MainApplication extends Application implements ReactApplication {
|
||||
}
|
||||
```
|
||||
|
||||
## 三、登录与创建应用
|
||||
## 登录与创建应用
|
||||
|
||||
首先请在<https://update.reactnative.cn>注册帐号,然后在你的项目根目录下运行以下命令:
|
||||
|
||||
|
@@ -25,7 +25,7 @@ const info = await checkUpdate(appKey)
|
||||
|
||||
返回的info有三种情况:
|
||||
|
||||
1. `{expired: true}`:该应用包(原生部分)已过期,需要前往应用市场下载新的版本。
|
||||
1. `{expired: true}`:该应用原生包已过期(已从pushy服务器中删除),开发者应该在pushy控制台添加一个更新下载链接,并自行提示用户下载。
|
||||
|
||||
2. `{upToDate: true}`:当前已经更新到最新,无需进行更新。
|
||||
|
||||
@@ -36,7 +36,7 @@ react-native-update会首先尝试耗费流量更少的更新方式。将info对
|
||||
|
||||
## 切换版本
|
||||
|
||||
downloadUpdate的返回值是一个hash字符串,它是当前版本的唯一标识。
|
||||
downloadUpdate的返回值是一个hash字符串,它是当前热更新版本的唯一标识。
|
||||
|
||||
你可以使用`switchVersion`函数立即切换版本(此时应用会立即重新加载),或者选择调用
|
||||
`switchVersionLater`,让应用在下一次启动的时候再加载新的版本。
|
||||
@@ -139,8 +139,8 @@ class MyProject extends Component {
|
||||
</Text>
|
||||
<Text style={styles.instructions}>
|
||||
这是版本一 {'\n'}
|
||||
当前包版本号: {packageVersion}{'\n'}
|
||||
当前版本Hash: {currentVersion||'(空)'}{'\n'}
|
||||
当前原生包版本号: {packageVersion}{'\n'}
|
||||
当前热更新版本Hash: {currentVersion||'(空)'}{'\n'}
|
||||
</Text>
|
||||
<TouchableOpacity onPress={this.checkUpdate}>
|
||||
<Text style={styles.instructions}>
|
||||
|
@@ -16,7 +16,7 @@
|
||||
$ pushy uploadIpa <your-package.ipa>
|
||||
```
|
||||
|
||||
即可上传ipa以供后续版本比对之用。
|
||||
即可上传ipa以供后续版本比对之用。此ipa的`CFBundleShortVersionString`字段(位于`ios/项目名/Info.plist`中)会被记录为原生版本号`packageVersion`。
|
||||
|
||||
随后你可以选择往AppStore发布这个版本,也可以先通过Test flight等方法进行测试。
|
||||
|
||||
@@ -31,7 +31,7 @@ $ pushy uploadIpa <your-package.ipa>
|
||||
$ pushy uploadApk android/app/build/outputs/apk/release/app-release.apk
|
||||
```
|
||||
|
||||
即可上传apk以供后续版本比对之用。
|
||||
即可上传apk以供后续版本比对之用。此apk的`versionName`字段(位于`android/build.gralde`中)会被记录为原生版本号`packageVersion`。
|
||||
|
||||
随后你可以选择往应用市场发布这个版本,也可以先往设备上直接安装这个apk文件以进行测试。
|
||||
|
||||
@@ -51,17 +51,17 @@ Would you like to publish it?(Y/N)
|
||||
|
||||
```
|
||||
Uploading [========================================================] 100% 0.0s
|
||||
Enter version name: <输入版本名字,如1.0.0-rc>
|
||||
Enter description: <输入版本描述>
|
||||
Enter version name: <输入热更新版本名字,如1.0.0-rc>
|
||||
Enter description: <输入热更新版本描述>
|
||||
Enter meta info: {"ok":1}
|
||||
Ok.
|
||||
Would you like to bind packages to this version?(Y/N)
|
||||
```
|
||||
|
||||
此时版本已经提交到update服务,但用户暂时看不到此更新,你需要先将特定的包版本绑定到此热更新版本上。
|
||||
此时版本已经提交到update服务,但用户暂时看不到此更新,你需要先将特定的原生包版本绑定到此热更新版本上。
|
||||
|
||||
此时输入Y立即绑定,你也可以在将来使用`pushy update --platform <ios|android>`来使得对应包版本的用户更新。
|
||||
除此以外,你还可以在网页端操作,简单的将对应的包版本拖到此版本下即可。
|
||||
此时输入Y立即绑定,你也可以在将来使用`pushy update --platform <ios|android>`来使得对应原生包版本的用户更新。
|
||||
除此以外,你还可以在网页端操作,简单的将对应的原生包版本拖到此热更新版本下即可。
|
||||
|
||||
```
|
||||
Offset 0
|
||||
@@ -72,7 +72,7 @@ Enter versionId or page Up/page Down/Begin(U/D/B) <输入序号,U/D翻页,B回
|
||||
1) 1.0(normal) - 3 FiWYm9lB (未命名)
|
||||
|
||||
Total 1 packages.
|
||||
Enter packageId: <输入包版本序号,序号就是上面列表中)前面的数字>
|
||||
Enter packageId: <输入原生包版本序号,序号就是上面列表中)前面的数字>
|
||||
```
|
||||
|
||||
版本绑定完毕后,客户端就应当可以检查到更新并进行更新了。
|
||||
|
25
docs/index.html
Normal file
25
docs/index.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>react-native-update - react-native hot update</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<meta name="description" content="react-native hot update">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/lib/themes/vue.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
window.$docsify = {
|
||||
name: 'react-native-update',
|
||||
repo: 'https://github.com/reactnativecn/react-native-pushy',
|
||||
formatUpdated: '{MM}/{DD} {HH}:{mm}',
|
||||
loadSidebar: true,
|
||||
subMaxLevel: 2,
|
||||
auto2top: true
|
||||
}
|
||||
</script>
|
||||
<script src="//cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js"></script>
|
||||
</body>
|
||||
</html>
|
1
domains.json
Normal file
1
domains.json
Normal file
@@ -0,0 +1 @@
|
||||
["update.reactnative.cn"]
|
@@ -424,7 +424,7 @@ RCT_EXPORT_METHOD(markSuccess)
|
||||
case PushyTypeFullDownload:
|
||||
return @".ppk";
|
||||
case PushyTypePatchFromPackage:
|
||||
return @".apk.patch";
|
||||
return @".ipa.patch";
|
||||
case PushyTypePatchFromPpk:
|
||||
return @".ppk.patch";
|
||||
default:
|
||||
|
57
lib/getHost.js
Normal file
57
lib/getHost.js
Normal file
@@ -0,0 +1,57 @@
|
||||
let availableDomain = 'update.react-native.cn';
|
||||
|
||||
function ping(domain, rejectImmediate) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = e => {
|
||||
if (xhr.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
if (xhr.status === 200) {
|
||||
resolve(domain);
|
||||
} else {
|
||||
rejectImmediate ? reject() : setTimeout(reject, 5000);
|
||||
}
|
||||
};
|
||||
xhr.open('HEAD', `https://${domain}`);
|
||||
xhr.send();
|
||||
xhr.timeout = 5000;
|
||||
xhr.ontimeout = reject;
|
||||
});
|
||||
}
|
||||
|
||||
function logger(...args) {
|
||||
// console.warn('pushy', ...args);
|
||||
}
|
||||
|
||||
export async function tryBackupDomains() {
|
||||
try {
|
||||
await ping(availableDomain, true);
|
||||
logger('main domain ok');
|
||||
return;
|
||||
} catch (e) {
|
||||
logger('main domain failed');
|
||||
}
|
||||
let backupDomains = [];
|
||||
try {
|
||||
const resp = await fetch(
|
||||
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/domains.json',
|
||||
);
|
||||
backupDomains = await resp.json();
|
||||
logger('get remote domains:', backupDomains);
|
||||
} catch (e) {
|
||||
logger('get remote domains failed');
|
||||
return;
|
||||
}
|
||||
const fastestDomain = await Promise.race(backupDomains.map(ping));
|
||||
if (typeof fastestDomain === 'string') {
|
||||
logger(`pick domain: ${fastestDomain}`);
|
||||
availableDomain = fastestDomain;
|
||||
} else {
|
||||
logger('all remote domains failed');
|
||||
}
|
||||
}
|
||||
|
||||
export default function getHost() {
|
||||
return `https://${availableDomain}/api`;
|
||||
}
|
1
lib/index.d.ts
vendored
1
lib/index.d.ts
vendored
@@ -19,7 +19,6 @@ export interface UpdateAvailableResult {
|
||||
hash: string;
|
||||
description: string;
|
||||
metaInfo: string;
|
||||
updateUrl: string;
|
||||
pdiffUrl: string;
|
||||
diffUrl: string;
|
||||
}
|
||||
|
40
lib/index.js
40
lib/index.js
@@ -1,7 +1,7 @@
|
||||
import getHost, { tryBackupDomains } from './getHost';
|
||||
import { NativeAppEventEmitter, NativeModules } from 'react-native';
|
||||
const Pushy = NativeModules.Pushy || {};
|
||||
|
||||
const host = 'https://update.reactnative.cn/api';
|
||||
const Pushy = NativeModules.Pushy || {};
|
||||
|
||||
export const downloadRootDir = Pushy.downloadRootDir;
|
||||
export const packageVersion = Pushy.packageVersion;
|
||||
@@ -28,7 +28,6 @@ There is available update:
|
||||
hash: 'hash',
|
||||
description: '添加聊天功能\n修复商城页面BUG',
|
||||
metaInfo: '{"silent":true}',
|
||||
updateUrl: 'http://update-packages.reactnative.cn/hash',
|
||||
pdiffUrl: 'http://update-packages.reactnative.cn/hash',
|
||||
diffUrl: 'http://update-packages.reactnative.cn/hash',
|
||||
}
|
||||
@@ -40,20 +39,29 @@ function assertRelease() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkUpdate(APPKEY) {
|
||||
export async function checkUpdate(APPKEY, isRetry) {
|
||||
assertRelease();
|
||||
const resp = await fetch(`${host}/checkUpdate/${APPKEY}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
packageVersion,
|
||||
hash: currentVersion,
|
||||
buildTime,
|
||||
}),
|
||||
});
|
||||
let resp;
|
||||
try {
|
||||
resp = await fetch(`${getHost()}/checkUpdate/${APPKEY}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
packageVersion,
|
||||
hash: currentVersion,
|
||||
buildTime,
|
||||
}),
|
||||
});
|
||||
} catch (e) {
|
||||
if (isRetry) {
|
||||
throw new Error('Could not connect to pushy server');
|
||||
}
|
||||
await tryBackupDomains();
|
||||
return checkUpdate(APPKEY, true);
|
||||
}
|
||||
|
||||
if (resp.status !== 200) {
|
||||
throw new Error((await resp.json()).message);
|
||||
|
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"plugins": [
|
||||
"syntax-object-rest-spread",
|
||||
"syntax-async-functions",
|
||||
"transform-es2015-arrow-functions",
|
||||
"transform-async-to-generator",
|
||||
"transform-es2015-modules-commonjs",
|
||||
"transform-es2015-destructuring",
|
||||
"transform-es2015-spread",
|
||||
"transform-object-rest-spread",
|
||||
"transform-es2015-parameters",
|
||||
"transform-strict-mode"
|
||||
]
|
||||
}
|
@@ -1,162 +0,0 @@
|
||||
{
|
||||
"useCommand": true,
|
||||
"defaultCommand": "help",
|
||||
"commands": {
|
||||
"help": {
|
||||
},
|
||||
|
||||
"login":{
|
||||
},
|
||||
"logout": {
|
||||
},
|
||||
"me": {
|
||||
},
|
||||
|
||||
"createApp": {
|
||||
"options": {
|
||||
"name": {
|
||||
"hasValue": true
|
||||
},
|
||||
"platform": {
|
||||
"hasValue": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"apps": {
|
||||
"options": {
|
||||
"platform": {
|
||||
"hasValue": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"deleteApp": {
|
||||
},
|
||||
"selectApp": {
|
||||
"options": {
|
||||
"platform": {
|
||||
"hasValue": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"uploadIpa": {
|
||||
},
|
||||
"uploadApk": {
|
||||
},
|
||||
"packages": {
|
||||
"options": {
|
||||
"platform": {
|
||||
"hasValue": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"publish": {
|
||||
"options": {
|
||||
"platform": {
|
||||
"hasValue": true
|
||||
},
|
||||
"name": {
|
||||
"hasValue": true
|
||||
},
|
||||
"description": {
|
||||
"hasValue": true
|
||||
},
|
||||
"metaInfo": {
|
||||
"hasValue": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"versions": {
|
||||
"options": {
|
||||
"platform": {
|
||||
"hasValue": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"update": {
|
||||
"options": {
|
||||
"platform": {
|
||||
"hasValue": true
|
||||
},
|
||||
"versionId": {
|
||||
"hasValue": true
|
||||
},
|
||||
"packageId": {
|
||||
"hasValue": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"build": {
|
||||
"description": "Bundle javascript and copy assets."
|
||||
},
|
||||
"bundle": {
|
||||
"description": "Bundle javascript code only.",
|
||||
"options": {
|
||||
"dev": {
|
||||
"default": "false",
|
||||
"hasValue": true
|
||||
},
|
||||
"platform": {
|
||||
"hasValue": true
|
||||
},
|
||||
"bundleName":{
|
||||
"default": "index.bundlejs",
|
||||
"hasValue": true
|
||||
},
|
||||
"entryFile": {
|
||||
"default": "index.js",
|
||||
"hasValue": true
|
||||
},
|
||||
"intermediaDir": {
|
||||
"default": "build/intermedia/${platform}",
|
||||
"hasValue": true
|
||||
},
|
||||
"output": {
|
||||
"default": "build/output/${platform}.${time}.ppk",
|
||||
"hasValue": true
|
||||
},
|
||||
"verbose": {
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
"release": {
|
||||
"description": "Push builded file to server."
|
||||
},
|
||||
"diff": {
|
||||
"description": "Create diff patch",
|
||||
"options": {
|
||||
"output": {
|
||||
"default": "build/output/diff",
|
||||
"hasValue": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"diffFromApk": {
|
||||
"description": "Create diff patch from a Android package(.apk)",
|
||||
"options": {
|
||||
"output": {
|
||||
"default": "build/output/diff-${time}.apk-patch",
|
||||
"hasValue": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"diffFromIpa": {
|
||||
"description": "Create diff patch from a iOS package(.ipa)",
|
||||
"options": {
|
||||
"output": {
|
||||
"default": "build/output/diff-${time}.ipa-patch",
|
||||
"hasValue": true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"globalOptions":{
|
||||
"no-interactive": {
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 2/22/16.
|
||||
*/
|
||||
module.exports = require('./lib');
|
@@ -1,132 +0,0 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
const fetch = require('isomorphic-fetch');
|
||||
let host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn/api';
|
||||
const fs = require('fs-extra');
|
||||
import request from 'request';
|
||||
import ProgressBar from 'progress';
|
||||
|
||||
let session = undefined;
|
||||
let savedSession = undefined;
|
||||
|
||||
exports.loadSession = async function() {
|
||||
if (fs.existsSync('.update')) {
|
||||
try {
|
||||
exports.replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
|
||||
savedSession = session;
|
||||
} catch (e) {
|
||||
console.error('Failed to parse file `.update`. Try to remove it manually.');
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.getSession = function() {
|
||||
return session;
|
||||
};
|
||||
|
||||
exports.replaceSession = function(newSession) {
|
||||
session = newSession;
|
||||
};
|
||||
|
||||
exports.saveSession = function() {
|
||||
// Only save on change.
|
||||
if (session !== savedSession) {
|
||||
const current = session;
|
||||
const data = JSON.stringify(current, null, 4);
|
||||
fs.writeFileSync('.update', data, 'utf8');
|
||||
savedSession = current;
|
||||
}
|
||||
};
|
||||
|
||||
exports.closeSession = function() {
|
||||
if (fs.existsSync('.update')) {
|
||||
fs.unlinkSync('.update');
|
||||
savedSession = undefined;
|
||||
}
|
||||
session = undefined;
|
||||
host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn';
|
||||
};
|
||||
|
||||
async function query(url, options) {
|
||||
const resp = await fetch(url, options);
|
||||
const json = await resp.json();
|
||||
if (resp.status !== 200) {
|
||||
throw Object.assign(new Error(json.message || json.error), { status: resp.status });
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
function queryWithoutBody(method) {
|
||||
return function(api) {
|
||||
return query(host + api, {
|
||||
method,
|
||||
headers: {
|
||||
'X-AccessToken': session ? session.token : '',
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function queryWithBody(method) {
|
||||
return function(api, body) {
|
||||
return query(host + api, {
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-AccessToken': session ? session.token : '',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.get = queryWithoutBody('GET');
|
||||
exports.post = queryWithBody('POST');
|
||||
exports.put = queryWithBody('PUT');
|
||||
exports.doDelete = queryWithBody('DELETE');
|
||||
|
||||
async function uploadFile(fn) {
|
||||
const { url, fieldName, formData } = await exports.post('/upload', {});
|
||||
let realUrl = url;
|
||||
|
||||
if (!/^https?\:\/\//.test(url)) {
|
||||
realUrl = host + url;
|
||||
}
|
||||
|
||||
const fileSize = fs.statSync(fn).size;
|
||||
|
||||
const bar = new ProgressBar(' Uploading [:bar] :percent :etas', {
|
||||
complete: '=',
|
||||
incomplete: ' ',
|
||||
total: fileSize,
|
||||
});
|
||||
|
||||
const info = await new Promise((resolve, reject) => {
|
||||
formData.file = fs.createReadStream(fn);
|
||||
|
||||
formData.file.on('data', function(data) {
|
||||
bar.tick(data.length);
|
||||
});
|
||||
request.post(
|
||||
realUrl,
|
||||
{
|
||||
formData,
|
||||
},
|
||||
(err, resp, body) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
if (resp.statusCode > 299) {
|
||||
return reject(Object.assign(new Error(body), { status: resp.statusCode }));
|
||||
}
|
||||
resolve(JSON.parse(body));
|
||||
},
|
||||
);
|
||||
});
|
||||
return info;
|
||||
}
|
||||
|
||||
exports.uploadFile = uploadFile;
|
@@ -1,110 +0,0 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
import {question} from './utils';
|
||||
import * as fs from 'fs-extra';
|
||||
|
||||
const {
|
||||
post,
|
||||
get,
|
||||
doDelete,
|
||||
} = require('./api');
|
||||
|
||||
const validPlatforms = {
|
||||
ios: 1,
|
||||
android: 1,
|
||||
};
|
||||
|
||||
export function checkPlatform(platform) {
|
||||
if (!validPlatforms[platform]) {
|
||||
throw new Error(`Invalid platform '${platform}'`);
|
||||
}
|
||||
return platform
|
||||
}
|
||||
|
||||
export function getSelectedApp(platform) {
|
||||
checkPlatform(platform);
|
||||
|
||||
if (!fs.existsSync('update.json')){
|
||||
throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
|
||||
}
|
||||
const updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
||||
if (!updateInfo[platform]) {
|
||||
throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
|
||||
}
|
||||
return updateInfo[platform];
|
||||
}
|
||||
|
||||
export async function listApp(platform){
|
||||
const {data} = await get('/app/list');
|
||||
const list = platform?data.filter(v=>v.platform===platform):data;
|
||||
for (const app of list) {
|
||||
console.log(`${app.id}) ${app.name}(${app.platform})`);
|
||||
}
|
||||
if (platform) {
|
||||
console.log(`\nTotal ${list.length} ${platform} apps`);
|
||||
} else {
|
||||
console.log(`\nTotal ${list.length} apps`);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
export async function chooseApp(platform) {
|
||||
const list = await listApp(platform);
|
||||
|
||||
while (true) {
|
||||
const id = await question('Enter appId:');
|
||||
const app = list.find(v=>v.id === (id|0));
|
||||
if (app) {
|
||||
return app;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const commands = {
|
||||
createApp: async function ({options}) {
|
||||
const name = options.name || await question('App Name:');
|
||||
const {downloadUrl} = options;
|
||||
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
||||
const {id} = await post('/app/create', {name, platform});
|
||||
console.log(`Created app ${id}`);
|
||||
await this.selectApp({
|
||||
args: [id],
|
||||
options: {platform, downloadUrl},
|
||||
});
|
||||
},
|
||||
deleteApp: async function ({args, options}) {
|
||||
const {platform} = options;
|
||||
const id = args[0] || chooseApp(platform);
|
||||
if (!id) {
|
||||
console.log('Canceled');
|
||||
}
|
||||
await doDelete(`/app/${id}`);
|
||||
console.log('Ok.');
|
||||
},
|
||||
apps: async function ({options}){
|
||||
const {platform} = options;
|
||||
listApp(platform);
|
||||
},
|
||||
selectApp: async function({args, options}) {
|
||||
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
||||
const id = args[0] || (await chooseApp(platform)).id;
|
||||
|
||||
let updateInfo = {};
|
||||
if (fs.existsSync('update.json')) {
|
||||
try {
|
||||
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
||||
} catch (e) {
|
||||
console.error('Failed to parse file `update.json`. Try to remove it manually.');
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
const {appKey} = await get(`/app/${id}`);
|
||||
updateInfo[platform] = {
|
||||
appId: id,
|
||||
appKey,
|
||||
};
|
||||
fs.writeFileSync('update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
|
||||
},
|
||||
}
|
@@ -1,507 +0,0 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 2/22/16.
|
||||
*/
|
||||
|
||||
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 { question } from './utils';
|
||||
import { checkPlatform } from './app';
|
||||
const { spawn, spawnSync, execSync } = require('child_process');
|
||||
const g2js = require('gradle-to-js/lib/parser');
|
||||
const os = require('os');
|
||||
|
||||
var diff;
|
||||
try {
|
||||
var bsdiff = require('node-bsdiff');
|
||||
diff = typeof bsdiff != 'function' ? bsdiff.diff : bsdiff;
|
||||
} catch (e) {
|
||||
diff = function() {
|
||||
console.warn(
|
||||
'This function needs "node-bsdiff". Please run "npm i node-bsdiff" from your project directory first!',
|
||||
);
|
||||
throw new Error('This function needs module "node-bsdiff". Please install it first.');
|
||||
};
|
||||
}
|
||||
|
||||
function exec(command) {
|
||||
const commandResult = spawnSync(command, {
|
||||
shell: true,
|
||||
stdio: 'inherit',
|
||||
});
|
||||
if (commandResult.error) {
|
||||
throw commandResult.error;
|
||||
}
|
||||
}
|
||||
|
||||
async function runReactNativeBundleCommand(
|
||||
bundleName,
|
||||
development,
|
||||
entryFile,
|
||||
outputFolder,
|
||||
platform,
|
||||
sourcemapOutput,
|
||||
config,
|
||||
) {
|
||||
let reactNativeBundleArgs = [];
|
||||
|
||||
let envArgs = process.env.PUSHY_ENV_ARGS;
|
||||
|
||||
if (envArgs) {
|
||||
Array.prototype.push.apply(reactNativeBundleArgs, envArgs.trim().split(/\s+/));
|
||||
}
|
||||
|
||||
fs.emptyDirSync(outputFolder);
|
||||
|
||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||
path.join("node_modules", "react-native", "local-cli", "cli.js"),
|
||||
"bundle",
|
||||
'--assets-dest',
|
||||
outputFolder,
|
||||
'--bundle-output',
|
||||
path.join(outputFolder, bundleName),
|
||||
'--dev',
|
||||
development,
|
||||
'--entry-file',
|
||||
entryFile,
|
||||
'--platform',
|
||||
platform,
|
||||
]);
|
||||
|
||||
if (sourcemapOutput) {
|
||||
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
||||
}
|
||||
|
||||
if (config) {
|
||||
reactNativeBundleArgs.push('--config', config);
|
||||
}
|
||||
|
||||
const reactNativeBundleProcess = spawn('node', reactNativeBundleArgs);
|
||||
console.log(`Running bundle command: node ${reactNativeBundleArgs.join(' ')}`);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
reactNativeBundleProcess.stdout.on('data', data => {
|
||||
console.log(data.toString().trim());
|
||||
});
|
||||
|
||||
reactNativeBundleProcess.stderr.on('data', data => {
|
||||
console.error(data.toString().trim());
|
||||
});
|
||||
|
||||
reactNativeBundleProcess.on('close', async exitCode => {
|
||||
if (exitCode) {
|
||||
reject(new Error(`"react-native bundle" command exited with code ${exitCode}.`));
|
||||
} else {
|
||||
if (platform === 'android') {
|
||||
await compileHermesByteCode(bundleName, outputFolder);
|
||||
}
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getHermesOSBin() {
|
||||
if (os.platform() === 'win32') return 'win64-bin';
|
||||
if (os.platform() === 'darwin') return 'osx-bin';
|
||||
if (os.platform() === 'linux') return 'linux64-bin';
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
if (enableHermes) {
|
||||
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
|
||||
const hermesPath = fs.existsSync('node_modules/hermes-engine')
|
||||
? 'node_modules/hermes-engine'
|
||||
: 'node_modules/hermesvm';
|
||||
execSync(
|
||||
`${hermesPath}/${getHermesOSBin()}/hermes -emit-binary -out ${outputFolder}/${bundleName} ${outputFolder}/${bundleName} -O`,
|
||||
{ stdio: 'ignore' },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function pack(dir, output) {
|
||||
console.log('Packing');
|
||||
fs.ensureDirSync(path.dirname(output));
|
||||
await new Promise((resolve, reject) => {
|
||||
var zipfile = new ZipFile();
|
||||
|
||||
function addDirectory(root, rel) {
|
||||
if (rel) {
|
||||
zipfile.addEmptyDirectory(rel);
|
||||
}
|
||||
const childs = fs.readdirSync(root);
|
||||
for (const name of childs) {
|
||||
if (name === '.' || name === '..') {
|
||||
continue;
|
||||
}
|
||||
const fullPath = path.join(root, name);
|
||||
const stat = fs.statSync(fullPath);
|
||||
if (stat.isFile()) {
|
||||
//console.log('adding: ' + rel+name);
|
||||
zipfile.addFile(fullPath, rel + name);
|
||||
} else if (stat.isDirectory()) {
|
||||
//console.log('adding: ' + rel+name+'/');
|
||||
addDirectory(fullPath, rel + name + '/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addDirectory(dir, '');
|
||||
|
||||
zipfile.outputStream.on('error', err => reject(err));
|
||||
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', function() {
|
||||
resolve();
|
||||
});
|
||||
zipfile.end();
|
||||
});
|
||||
console.log('Bundled saved to: ' + output);
|
||||
}
|
||||
|
||||
function readEntire(entry, zipFile) {
|
||||
const buffers = [];
|
||||
return new Promise((resolve, reject) => {
|
||||
zipFile.openReadStream(entry, (err, stream) => {
|
||||
stream.pipe({
|
||||
write(chunk) {
|
||||
buffers.push(chunk);
|
||||
},
|
||||
end() {
|
||||
resolve(Buffer.concat(buffers));
|
||||
},
|
||||
prependListener() {},
|
||||
on() {},
|
||||
once() {},
|
||||
emit() {},
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function basename(fn) {
|
||||
const m = /^(.+\/)[^\/]+\/?$/.exec(fn);
|
||||
return m && m[1];
|
||||
}
|
||||
|
||||
async function diffFromPPK(origin, next, output) {
|
||||
fs.ensureDirSync(path.dirname(output));
|
||||
|
||||
const originEntries = {};
|
||||
const originMap = {};
|
||||
|
||||
let originSource;
|
||||
|
||||
await enumZipEntries(origin, (entry, zipFile) => {
|
||||
originEntries[entry.fileName] = entry;
|
||||
if (!/\/$/.test(entry.fileName)) {
|
||||
// isFile
|
||||
originMap[entry.crc32] = entry.fileName;
|
||||
|
||||
if (entry.fileName === 'index.bundlejs') {
|
||||
// This is source.
|
||||
return readEntire(entry, zipFile).then(v => (originSource = v));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
originSource = originSource || new Buffer(0);
|
||||
|
||||
const copies = {};
|
||||
|
||||
var zipfile = new ZipFile();
|
||||
|
||||
const writePromise = new Promise((resolve, reject) => {
|
||||
zipfile.outputStream.on('error', err => {
|
||||
throw err;
|
||||
});
|
||||
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', function() {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
const addedEntry = {};
|
||||
|
||||
function addEntry(fn) {
|
||||
//console.log(fn);
|
||||
if (!fn || addedEntry[fn]) {
|
||||
return;
|
||||
}
|
||||
const base = basename(fn);
|
||||
if (base) {
|
||||
addEntry(base);
|
||||
}
|
||||
zipfile.addEmptyDirectory(fn);
|
||||
}
|
||||
|
||||
const newEntries = {};
|
||||
|
||||
await enumZipEntries(next, (entry, nextZipfile) => {
|
||||
newEntries[entry.fileName] = entry;
|
||||
|
||||
if (/\/$/.test(entry.fileName)) {
|
||||
// Directory
|
||||
if (!originEntries[entry.fileName]) {
|
||||
addEntry(entry.fileName);
|
||||
}
|
||||
} else if (entry.fileName === 'index.bundlejs') {
|
||||
//console.log('Found bundle');
|
||||
return readEntire(entry, nextZipfile).then(newSource => {
|
||||
//console.log('Begin diff');
|
||||
zipfile.addBuffer(diff(originSource, newSource), 'index.bundlejs.patch');
|
||||
//console.log('End diff');
|
||||
});
|
||||
} else {
|
||||
// If same file.
|
||||
const originEntry = originEntries[entry.fileName];
|
||||
if (originEntry && originEntry.crc32 === entry.crc32) {
|
||||
// ignore
|
||||
return;
|
||||
}
|
||||
|
||||
// If moved from other place
|
||||
if (originMap[entry.crc32]) {
|
||||
const base = basename(entry.fileName);
|
||||
if (!originEntries[base]) {
|
||||
addEntry(base);
|
||||
}
|
||||
copies[entry.fileName] = originMap[entry.crc32];
|
||||
return;
|
||||
}
|
||||
|
||||
// New file.
|
||||
addEntry(basename(entry.fileName));
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
nextZipfile.openReadStream(entry, function(err, readStream) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
zipfile.addReadStream(readStream, entry.fileName);
|
||||
readStream.on('end', () => {
|
||||
//console.log('add finished');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const deletes = {};
|
||||
|
||||
for (var k in originEntries) {
|
||||
if (!newEntries[k]) {
|
||||
console.log('Delete ' + k);
|
||||
deletes[k] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//console.log({copies, deletes});
|
||||
zipfile.addBuffer(new Buffer(JSON.stringify({ copies, deletes })), '__diff.json');
|
||||
zipfile.end();
|
||||
await writePromise;
|
||||
}
|
||||
|
||||
async function diffFromPackage(origin, next, output, originBundleName, transformPackagePath = v => v) {
|
||||
fs.ensureDirSync(path.dirname(output));
|
||||
|
||||
const originEntries = {};
|
||||
const originMap = {};
|
||||
|
||||
let originSource;
|
||||
|
||||
await enumZipEntries(origin, (entry, zipFile) => {
|
||||
if (!/\/$/.test(entry.fileName)) {
|
||||
const fn = transformPackagePath(entry.fileName);
|
||||
if (!fn) {
|
||||
return;
|
||||
}
|
||||
|
||||
//console.log(fn);
|
||||
// isFile
|
||||
originEntries[fn] = entry.crc32;
|
||||
originMap[entry.crc32] = fn;
|
||||
|
||||
if (fn === originBundleName) {
|
||||
// This is source.
|
||||
return readEntire(entry, zipFile).then(v => (originSource = v));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
originSource = originSource || new Buffer(0);
|
||||
|
||||
const copies = {};
|
||||
|
||||
var zipfile = new ZipFile();
|
||||
|
||||
const writePromise = new Promise((resolve, reject) => {
|
||||
zipfile.outputStream.on('error', err => {
|
||||
throw err;
|
||||
});
|
||||
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', function() {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
await enumZipEntries(next, (entry, nextZipfile) => {
|
||||
if (/\/$/.test(entry.fileName)) {
|
||||
// Directory
|
||||
zipfile.addEmptyDirectory(entry.fileName);
|
||||
} else if (entry.fileName === 'index.bundlejs') {
|
||||
//console.log('Found bundle');
|
||||
return readEntire(entry, nextZipfile).then(newSource => {
|
||||
//console.log('Begin diff');
|
||||
zipfile.addBuffer(diff(originSource, newSource), 'index.bundlejs.patch');
|
||||
//console.log('End diff');
|
||||
});
|
||||
} else {
|
||||
// If same file.
|
||||
if (originEntries[entry.fileName] === entry.crc32) {
|
||||
copies[entry.fileName] = '';
|
||||
return;
|
||||
}
|
||||
// If moved from other place
|
||||
if (originMap[entry.crc32]) {
|
||||
copies[entry.fileName] = originMap[entry.crc32];
|
||||
return;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
nextZipfile.openReadStream(entry, function(err, readStream) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
zipfile.addReadStream(readStream, entry.fileName);
|
||||
readStream.on('end', () => {
|
||||
//console.log('add finished');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
zipfile.addBuffer(new Buffer(JSON.stringify({ copies })), '__diff.json');
|
||||
zipfile.end();
|
||||
await writePromise;
|
||||
}
|
||||
|
||||
function enumZipEntries(zipFn, callback) {
|
||||
return new Promise((resolve, reject) => {
|
||||
openZipFile(zipFn, { lazyEntries: true }, (err, zipfile) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
zipfile.on('end', resolve);
|
||||
zipfile.on('error', reject);
|
||||
zipfile.on('entry', entry => {
|
||||
const result = callback(entry, zipfile);
|
||||
if (result && typeof result.then === 'function') {
|
||||
result.then(() => zipfile.readEntry());
|
||||
} else {
|
||||
zipfile.readEntry();
|
||||
}
|
||||
});
|
||||
zipfile.readEntry();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const commands = {
|
||||
bundle: async function({ options }) {
|
||||
const platform = checkPlatform(options.platform || (await question('Platform(ios/android):')));
|
||||
|
||||
let { bundleName, entryFile, intermediaDir, output, dev, verbose } = translateOptions({
|
||||
...options,
|
||||
platform,
|
||||
});
|
||||
|
||||
// const sourcemapOutput = path.join(intermediaDir, bundleName + ".map");
|
||||
|
||||
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
|
||||
|
||||
if (!platform) {
|
||||
throw new Error('Platform must be specified.');
|
||||
}
|
||||
|
||||
const { version, major, minor } = getRNVersion();
|
||||
|
||||
console.log('Bundling with React Native version: ', version);
|
||||
|
||||
await runReactNativeBundleCommand(bundleName, dev, entryFile, intermediaDir, platform);
|
||||
|
||||
await pack(path.resolve(intermediaDir), realOutput);
|
||||
|
||||
const v = await question('Would you like to publish it?(Y/N)');
|
||||
if (v.toLowerCase() === 'y') {
|
||||
await this.publish({
|
||||
args: [realOutput],
|
||||
options: {
|
||||
platform,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async diff({ args, options }) {
|
||||
const [origin, next] = args;
|
||||
const { output } = options;
|
||||
|
||||
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
|
||||
|
||||
if (!origin || !next) {
|
||||
console.error('pushy diff <origin> <next>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await diffFromPPK(origin, next, realOutput, 'index.bundlejs');
|
||||
console.log(`${realOutput} generated.`);
|
||||
},
|
||||
|
||||
async diffFromApk({ args, options }) {
|
||||
const [origin, next] = args;
|
||||
const { output } = options;
|
||||
|
||||
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
|
||||
|
||||
if (!origin || !next) {
|
||||
console.error('pushy diffFromApk <origin> <next>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await diffFromPackage(origin, next, realOutput, 'assets/index.android.bundle');
|
||||
console.log(`${realOutput} generated.`);
|
||||
},
|
||||
|
||||
async diffFromIpa({ args, options }) {
|
||||
const [origin, next] = args;
|
||||
const { output } = options;
|
||||
|
||||
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
|
||||
|
||||
if (!origin || !next) {
|
||||
console.error('pushy diffFromIpa <origin> <next>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', v => {
|
||||
const m = /^Payload\/[^/]+\/(.+)$/.exec(v);
|
||||
return m && m[1];
|
||||
});
|
||||
|
||||
console.log(`${realOutput} generated.`);
|
||||
},
|
||||
};
|
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
const {loadSession} = require('./api');
|
||||
|
||||
function printUsage({args}) {
|
||||
// const commandName = args[0];
|
||||
// TODO: print usage of commandName, or print global usage.
|
||||
|
||||
console.log('Usage is under development now.')
|
||||
console.log('Visit `https://github.com/reactnativecn/react-native-pushy` for early document.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const commands = {
|
||||
...require('./user').commands,
|
||||
...require('./bundle').commands,
|
||||
...require('./app').commands,
|
||||
...require('./package').commands,
|
||||
...require('./versions').commands,
|
||||
help: printUsage,
|
||||
};
|
||||
|
||||
exports.run = function () {
|
||||
const argv = require('cli-arguments').parse(require('../cli.json'));
|
||||
global.NO_INTERACTIVE = argv.options['no-interactive'];
|
||||
|
||||
loadSession()
|
||||
.then(()=>commands[argv.command](argv))
|
||||
.catch(err=>{
|
||||
if (err.status === 401) {
|
||||
console.log('Not loggined.\nRun `pushy login` at your project directory to login.');
|
||||
return;
|
||||
}
|
||||
console.error(err.stack);
|
||||
process.exit(-1);
|
||||
});
|
||||
};
|
@@ -1,87 +0,0 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 4/2/16.
|
||||
*/
|
||||
|
||||
const { get, post, uploadFile } = require('./api');
|
||||
import { question } from './utils';
|
||||
|
||||
import { checkPlatform, getSelectedApp } from './app';
|
||||
|
||||
import { getApkInfo, getIpaInfo } from './utils';
|
||||
const Table = require('tty-table');
|
||||
|
||||
export async function listPackage(appId) {
|
||||
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
||||
|
||||
const header = [{ value: 'Package Id' }, { value: 'Version' }];
|
||||
const rows = [];
|
||||
for (const pkg of data) {
|
||||
const { version } = pkg;
|
||||
let versionInfo = '';
|
||||
if (version) {
|
||||
versionInfo = ` - ${version.id} ${version.hash.slice(0, 8)} ${version.name}`;
|
||||
} else {
|
||||
versionInfo = ' (newest)';
|
||||
}
|
||||
|
||||
rows.push([pkg.id, `${pkg.name}(${pkg.status})${versionInfo}`]);
|
||||
}
|
||||
|
||||
console.log(Table(header, rows).render());
|
||||
console.log(`\nTotal ${data.length} package(s).`);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function choosePackage(appId) {
|
||||
const list = await listPackage(appId);
|
||||
|
||||
while (true) {
|
||||
const id = await question('Enter Package Id:');
|
||||
const app = list.find(v => v.id === (id | 0));
|
||||
if (app) {
|
||||
return app;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const commands = {
|
||||
uploadIpa: async function({ args }) {
|
||||
const fn = args[0];
|
||||
if (!fn) {
|
||||
throw new Error('Usage: pushy uploadIpa <ipaFile>');
|
||||
}
|
||||
const { versionName, buildTime } = await getIpaInfo(fn);
|
||||
const { appId } = await getSelectedApp('ios');
|
||||
|
||||
const { hash } = await uploadFile(fn);
|
||||
|
||||
const { id } = await post(`/app/${appId}/package/create`, {
|
||||
name: versionName,
|
||||
hash,
|
||||
buildTime,
|
||||
});
|
||||
console.log(`Ipa uploaded: ${id}`);
|
||||
},
|
||||
uploadApk: async function({ args }) {
|
||||
const fn = args[0];
|
||||
if (!fn) {
|
||||
throw new Error('Usage: pushy uploadApk <apkFile>');
|
||||
}
|
||||
const { versionName, buildTime } = await getApkInfo(fn);
|
||||
const { appId } = await getSelectedApp('android');
|
||||
|
||||
const { hash } = await uploadFile(fn);
|
||||
|
||||
const { id } = await post(`/app/${appId}/package/create`, {
|
||||
name: versionName,
|
||||
hash,
|
||||
buildTime,
|
||||
});
|
||||
console.log(`Apk uploaded: ${id}`);
|
||||
},
|
||||
packages: async function({ options }) {
|
||||
const platform = checkPlatform(options.platform || (await question('Platform(ios/android):')));
|
||||
const { appId } = await getSelectedApp(platform);
|
||||
await listPackage(appId);
|
||||
},
|
||||
};
|
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
import {question} from './utils';
|
||||
const {
|
||||
post,
|
||||
get,
|
||||
replaceSession,
|
||||
saveSession,
|
||||
closeSession,
|
||||
} = require('./api');
|
||||
const crypto = require('crypto');
|
||||
|
||||
function md5(str) {
|
||||
return crypto.createHash('md5').update(str).digest('hex');
|
||||
}
|
||||
|
||||
exports.commands = {
|
||||
login: async function ({args}){
|
||||
const email = args[0] || await question('email:');
|
||||
const pwd = args[1] || await question('password:', true);
|
||||
const {token, info} = await post('/user/login', {
|
||||
email,
|
||||
pwd: md5(pwd),
|
||||
});
|
||||
replaceSession({token});
|
||||
await saveSession();
|
||||
console.log(`Welcome, ${info.name}.`);
|
||||
},
|
||||
logout: async function (){
|
||||
await closeSession();
|
||||
console.log('Logged out.');
|
||||
},
|
||||
me: async function (){
|
||||
const me = await get('/user/me');
|
||||
for (const k in me) {
|
||||
if (k !== 'ok') {
|
||||
console.log(`${k}: ${me[k]}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
@@ -1,84 +0,0 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs-extra';
|
||||
const AppInfoParser = require('app-info-parser');
|
||||
|
||||
var read = require('read');
|
||||
|
||||
export function question(query, password) {
|
||||
if (NO_INTERACTIVE) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
return new Promise((resolve, reject) =>
|
||||
read(
|
||||
{
|
||||
prompt: query,
|
||||
silent: password,
|
||||
replace: password ? '*' : undefined,
|
||||
},
|
||||
(err, result) => (err ? reject(err) : resolve(result)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function translateOptions(options) {
|
||||
const ret = {};
|
||||
for (let key in options) {
|
||||
const v = options[key];
|
||||
if (typeof v === 'string') {
|
||||
ret[key] = v.replace(/\$\{(\w+)\}/g, function(v, n) {
|
||||
return options[n] || process.env[n] || v;
|
||||
});
|
||||
} else {
|
||||
ret[key] = v;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
export function getRNVersion() {
|
||||
const version = JSON.parse(fs.readFileSync(path.resolve('node_modules/react-native/package.json'))).version;
|
||||
|
||||
// We only care about major and minor version.
|
||||
const match = /^(\d+)\.(\d+)\./.exec(version);
|
||||
return {
|
||||
version,
|
||||
major: match[1] | 0,
|
||||
minor: match[2] | 0,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getApkInfo(fn) {
|
||||
const appInfoParser = new AppInfoParser(fn);
|
||||
const { versionName, application } = await appInfoParser.parse();
|
||||
let buildTime = 0;
|
||||
if (Array.isArray(application.metaData)) {
|
||||
for (const meta of application.metaData) {
|
||||
if (meta.name === 'pushy_build_time') {
|
||||
buildTime = meta.value[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (buildTime == 0) {
|
||||
throw new Error('Can not get build time for this app.');
|
||||
}
|
||||
return { versionName, buildTime };
|
||||
}
|
||||
|
||||
export async function getIpaInfo(fn) {
|
||||
const appInfoParser = new AppInfoParser(fn);
|
||||
const { CFBundleShortVersionString: versionName } = await appInfoParser.parse();
|
||||
let buildTimeTxtBuffer = await appInfoParser.parser.getEntry(/payload\/.+?\.app\/pushy_build_time.txt/);
|
||||
if (!buildTimeTxtBuffer) {
|
||||
// Not in root bundle when use `use_frameworks`
|
||||
buildTimeTxtBuffer = await appInfoParser.parser.getEntry(/payload\/.+?\.app\/frameworks\/react_native_update.framework\/pushy_build_time.txt/);
|
||||
}
|
||||
if (!buildTimeTxtBuffer) {
|
||||
throw new Error('Can not get build time for this app.');
|
||||
}
|
||||
const buildTime = buildTimeTxtBuffer.toString().replace('\n', '');
|
||||
return { versionName, buildTime };
|
||||
}
|
@@ -1,111 +0,0 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 4/2/16.
|
||||
*/
|
||||
|
||||
const {
|
||||
get,
|
||||
post,
|
||||
put,
|
||||
uploadFile,
|
||||
} = require('./api');
|
||||
import { question } from './utils';
|
||||
|
||||
import { checkPlatform, getSelectedApp } from './app';
|
||||
import { choosePackage } from './package';
|
||||
|
||||
async function showVersion(appId, offset) {
|
||||
const { data, count } = await get(`/app/${appId}/version/list`);
|
||||
console.log(`Offset ${offset}`);
|
||||
for (const version of data) {
|
||||
let packageInfo = version.packages.slice(0, 3).map(v=>v.name).join(', ');
|
||||
const count = version.packages.length;
|
||||
if (count > 3) {
|
||||
packageInfo += `...and ${count-3} more`;
|
||||
}
|
||||
if (count === 0) {
|
||||
packageInfo = `(no package)`;
|
||||
} else {
|
||||
packageInfo = `[${packageInfo}]`;
|
||||
}
|
||||
console.log(`${version.id}) ${version.hash.slice(0, 8)} ${version.name} ${packageInfo}`);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
async function listVersions(appId) {
|
||||
let offset = 0;
|
||||
while (true) {
|
||||
await showVersion(appId, offset);
|
||||
const cmd = await question('page Up/page Down/Begin/Quit(U/D/B/Q)');
|
||||
switch (cmd.toLowerCase()) {
|
||||
case 'u': offset = Math.max(0, offset - 10); break;
|
||||
case 'd': offset += 10; break;
|
||||
case 'b': offset = 0; break;
|
||||
case 'q': return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function chooseVersion(appId) {
|
||||
let offset = 0;
|
||||
while (true) {
|
||||
const data = await showVersion(appId, offset);
|
||||
const cmd = await question('Enter versionId or page Up/page Down/Begin(U/D/B)');
|
||||
switch (cmd.toLowerCase()) {
|
||||
case 'U': offset = Math.max(0, offset - 10); break;
|
||||
case 'D': offset += 10; break;
|
||||
case 'B': offset = 0; break;
|
||||
default:
|
||||
{
|
||||
const v = data.find(v=>v.id === (cmd | 0));
|
||||
if (v) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const commands = {
|
||||
publish: async function({args, options}) {
|
||||
const fn = args[0];
|
||||
const {name, description, metaInfo } = options;
|
||||
|
||||
if (!fn) {
|
||||
throw new Error('Usage: pushy publish <ppkFile> --platform ios|android');
|
||||
}
|
||||
|
||||
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
||||
const { appId } = await getSelectedApp(platform);
|
||||
|
||||
const { hash } = await uploadFile(fn);
|
||||
|
||||
const { id } = await post(`/app/${appId}/version/create`, {
|
||||
name: name || await question('Enter version name:') || '(未命名)',
|
||||
hash,
|
||||
description: description || await question('Enter description:'),
|
||||
metaInfo: metaInfo || await question('Enter meta info:'),
|
||||
});
|
||||
console.log(`Version published: ${id}`);
|
||||
|
||||
const v = await question('Would you like to bind packages to this version?(Y/N)');
|
||||
if (v.toLowerCase() === 'y') {
|
||||
await this.update({args:[], options:{versionId: id, platform}});
|
||||
}
|
||||
},
|
||||
versions: async function({options}) {
|
||||
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
||||
const { appId } = await getSelectedApp(platform);
|
||||
await listVersions(appId);
|
||||
},
|
||||
update: async function({args, options}) {
|
||||
const platform = checkPlatform(options.platform || await question('Platform(ios/android):'));
|
||||
const { appId } = await getSelectedApp(platform);
|
||||
const versionId = options.versionId || (await chooseVersion(appId)).id;
|
||||
const pkgId = options.packageId || (await choosePackage(appId)).id;
|
||||
await put(`/app/${appId}/package/${pkgId}`, {
|
||||
versionId,
|
||||
});
|
||||
console.log('Ok.');
|
||||
}
|
||||
};
|
33
package.json
33
package.json
@@ -1,12 +1,11 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "5.5.3",
|
||||
"version": "5.5.7",
|
||||
"description": "react-native hot update",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build-lib": "$ANDROID_HOME/ndk-bundle/ndk-build NDK_PROJECT_PATH=android APP_BUILD_SCRIPT=android/jni/Android.mk NDK_LIBS_OUT=android/lib",
|
||||
"prepare": "node_modules/.bin/babel local-cli/src --out-dir local-cli/lib"
|
||||
"build-lib": "$ANDROID_HOME/ndk-bundle/ndk-build NDK_PROJECT_PATH=android APP_BUILD_SCRIPT=android/jni/Android.mk NDK_LIBS_OUT=android/lib"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -27,31 +26,5 @@
|
||||
"react-native": ">=0.27.0"
|
||||
},
|
||||
"homepage": "https://github.com/reactnativecn/react-native-pushy#readme",
|
||||
"dependencies": {
|
||||
"app-info-parser": "^0.3.5",
|
||||
"cli-arguments": "^0.2.1",
|
||||
"fs-extra": "^8.1.0",
|
||||
"gradle-to-js": "^2.0.0",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"progress": "^1.1.8",
|
||||
"read": "^1.0.7",
|
||||
"request": "^2.69.0",
|
||||
"tty-table": "^2.7.0",
|
||||
"yauzl": "^2.10.0",
|
||||
"yazl": "2.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.5.1",
|
||||
"babel-eslint": "^4.1.6",
|
||||
"babel-plugin-syntax-async-functions": "^6.5.0",
|
||||
"babel-plugin-syntax-object-rest-spread": "^6.5.0",
|
||||
"babel-plugin-transform-async-to-generator": "^6.3.13",
|
||||
"babel-plugin-transform-es2015-arrow-functions": "^6.5.2",
|
||||
"babel-plugin-transform-es2015-destructuring": "^6.3.15",
|
||||
"babel-plugin-transform-es2015-modules-commonjs": "^6.3.16",
|
||||
"babel-plugin-transform-es2015-parameters": "^6.5.0",
|
||||
"babel-plugin-transform-es2015-spread": "^6.5.2",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.5.0",
|
||||
"babel-plugin-transform-strict-mode": "^6.5.2"
|
||||
}
|
||||
"dependencies": {}
|
||||
}
|
||||
|
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"plugins": [
|
||||
"transform-es2015-modules-commonjs",
|
||||
"transform-strict-mode"
|
||||
]
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
/.idea
|
||||
/src
|
||||
/.babelrc
|
||||
/.npmignore
|
||||
/.eslintrc
|
||||
/.nvmrc
|
||||
/.travis.yml
|
@@ -1,34 +0,0 @@
|
||||
{
|
||||
"name": "react-native-update-cli",
|
||||
"version": "0.1.0",
|
||||
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
"pushy": "lib/cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"prepublish": "node_modules/.bin/babel src --out-dir lib"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/reactnativecn/react-native-pushy.git"
|
||||
},
|
||||
"keywords": [
|
||||
"react-native",
|
||||
"ios",
|
||||
"android",
|
||||
"update"
|
||||
],
|
||||
"author": "reactnativecn",
|
||||
"license": "BSD-3-Clause",
|
||||
"bugs": {
|
||||
"url": "https://github.com/reactnativecn/react-native-pushy/issues"
|
||||
},
|
||||
"homepage": "https://github.com/reactnativecn/react-native-pushy/tree/master/react-native-pushy-cli",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.5.1",
|
||||
"babel-plugin-transform-es2015-modules-commonjs": "^6.5.2",
|
||||
"babel-plugin-transform-strict-mode": "^6.5.2"
|
||||
}
|
||||
}
|
53
react-native-pushy-cli/src/cli.js
vendored
53
react-native-pushy-cli/src/cli.js
vendored
@@ -1,53 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs-extra';
|
||||
|
||||
const CLI_MODULE_PATH = function() {
|
||||
return path.resolve(
|
||||
process.cwd(),
|
||||
'node_modules',
|
||||
'react-native-update',
|
||||
'local-cli'
|
||||
);
|
||||
};
|
||||
|
||||
const PACKAGE_JSON_PATH = function() {
|
||||
return path.resolve(
|
||||
process.cwd(),
|
||||
'node_modules',
|
||||
'react-native-update',
|
||||
'package.json'
|
||||
);
|
||||
};
|
||||
|
||||
checkForVersionCommand();
|
||||
|
||||
let cli;
|
||||
const cliPath = CLI_MODULE_PATH();
|
||||
if (fs.existsSync(cliPath)) {
|
||||
cli = require(cliPath);
|
||||
}
|
||||
|
||||
if (cli) {
|
||||
cli.run();
|
||||
} else {
|
||||
console.error('Are you at home directory of a react-native project?');
|
||||
console.error('`pushy install` is under development, please run `npm install react-native-update` to install pushy manually.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function checkForVersionCommand() {
|
||||
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
|
||||
console.log('react-native-update-cli: ' + require('../package.json').version);
|
||||
try {
|
||||
console.log('react-native-update: ' + require(PACKAGE_JSON_PATH()).version);
|
||||
} catch (e) {
|
||||
console.log('react-native-update: n/a - not inside a React Native project directory')
|
||||
}
|
||||
process.exit();
|
||||
}
|
||||
}
|
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
|
||||
s.vendored_libraries = 'RCTPushy/libRCTPushy.a'
|
||||
s.pod_target_xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '"$(SRCROOT)/../node_modules/react-native-update/ios"' }
|
||||
s.resource = 'ios/pushy_build_time.txt'
|
||||
s.script_phase = { :name => 'Generate build time', :script => '../../node_modules/react-native-update/scripts/generateiOSBuildTime.sh', :execution_position => :before_compile }
|
||||
s.script_phase = { :name => 'Generate build time', :script => '"$(SRCROOT)/../node_modules/react-native-update/scripts/generateiOSBuildTime.sh"', :execution_position => :before_compile }
|
||||
|
||||
s.dependency 'React'
|
||||
s.dependency 'SSZipArchive'
|
||||
|
Reference in New Issue
Block a user