1.6.1 • Published 2 years ago

react-native-egenie-codepush v1.6.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

react-native-egenie-codepush

衫数科技热更新组件

Installation

yarn add react-native-egenie-codepush

Android

cd android && ./gradlew sync

iOS

cd ios && pod install

Usage

Android

MainApplication.java 添加如下代码

public class MainApplication extends Application implements ReactApplication {
    private final ReactNativeHost mReactNativeHost =
      new ReactNativeHost(this) {
       ...
        @Nullable
        @Override
        protected String getBundleAssetName() {
          return "platform.android.bundle";
        }
       ...
      };
    ...
}

MainActivity.java 继承 CPReactActivity

public class MainActivity extends CPReactActivity {

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  @Override
  protected String getMainComponentName() {
    return "CodepushExample";
  }
}

iOS

在 AppDelegate 中引入 CPReactController.h

#import "CPReactController.h"


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

#if DEBUG
  //本地调试代码
  ...
#else
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  CPReactController *rootViewController = [[CPReactController alloc]initWithLaunchOptions:launchOptions];
  rootViewController.downloadBundleBlock = ^{
    //开始下载bundle,需将覆盖顶层的试图移除,如RNSplashScreen
  };
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
#endif

return YES;
}

Extra

完成打包后 ios 需要将打包文件引入到工程
选中 Project->右键 Add Files to "Project"
将如下三个文件添加到工程
config.json
platform.ios.bundle
index.ios.bundle.zip

配置

在根目录新建 codepush.config.js 文件 配置如下

//需要调用真实接口
const getIterationList = () => {
  return ['mall-3.2.2', 'mall-3.2.1'];
};
//需要调用真实接口
const getIterationVersion = (it) => {
  return 8000;
};
module.exports = {
  /**
   * ios版本号
   */
  iosVersionName: '1.0',
  /**
   * ios构建号
   */
  iosVersionCode: 1,
  /**
   * ios工程名称
   */
  iosProjectName: 'CodepushExample',
  /**
   * android版本号
   */
  androidVersionName: '2.0',
  /**
   * android构建号
   */
  androidVersionCode: 1,
  /**
   *android和ios的发布版本号,用于区别程序版本
   */
  releaseVersion: '1.0.0',
  /**
   * 业务模块名称
   */
  moduleName: 'CodepushExample',
  /**
   * 业务模块入口
   */
  indexEntry: './index.tsx',
  /**
   * 基础模块入口
   */
  baseEntry: './base.js',
  /**
   * oss配置信息
   */
  ossOptions: {
    accessKeyId: '',
    accessKeySecret: '',
    bucket: '',
    region: '',
    timeout: 60 * 60 * 24,
  },
  /**
   * oss地址
   */
  ossUrl: 'https://test.oss-cn-hangzhou.aliyuncs.com',
  /**
   * oss热更新文件保存路径,如/app/app-test/codepush
   */
  ossPath: 'app/app-test/codepush',
  /**
   * 打包环境列表如['test','uat', 'release', 'release-reg']
   */
  envs: ['dev', 'test', 'uat', 'releasepre', 'release'],
  /**
   *获取迭代版本
   * @returns
   */
  getIterationList: getIterationList,

  /**
   *获取迭代版本号
   * @returns
   */
  getIterationVersion: getIterationVersion,

  /**
   * 加盐算法key
   */
  saltKey: '123456789',
};

配置环境文件

环境文件用于配置服务 url,随环境变化的数据等
在根目录新建环境文件
.env.dev
.env.test
.env.uat
.env.releasepre
.env.release. ...
以上环境需同 codepush.config.js 文件中的 envs 一致

内容示例如下.env.release

ENV=dev
API_URL=https://myapi.com
import { Config } from 'react-native-egenie-codepush';

console.log(Config.ENV);
console.log(Config.API_URL);

测试支持切换环境

import { CodePush } from 'react-native-egenie-codepush';
CodePush.changeEnv('uat');

打包脚本

环境切换 autoenv 命令

参数
--env 环境参数,需包含 codepush.config.js 中 envs
--allowWireShark true/false android 是否允许抓包,默认 false

yarn autoenv --env uat --allowWireShark true

打包 batch 命令

参数
--base true/false 是否需要基础包
--env dev/test/release 环境
--iteration select/mall-3.3.2 获取迭代号
--uposs true/false 是否上传到 oss
--allowWireShark true/false android 是否允许抓包,默认 false --force true/false 是否强制更新,默认 false

//uat
yarn batch --base true --env uat --iteration select --uposs true --allowWireShark true
//release
yarn batch --base false --env release --iteration select --uposs true --allowWireShark false

日志分析 log 命令

热更新插件每次热更会将 soucemap 文件一并上传到 oss
故分析脚本调整为从 oss 拉取,不用每次从 oss 手动下载
--path 异常路径,从异常日志中获取
--env release 环境,从异常日志中获取
--column 列,从异常日志中获取
--line 行,从异常日志中获取
--platform 系统 ios/android

yarn log --path app/app-pgms/codepush/release/1.3.0/10000 --env release --column 222 --line 222 --platform ios

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

1.6.1

2 years ago

1.6.0

2 years ago

1.5.8

2 years ago

1.5.10

2 years ago

1.5.7

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.2.1

2 years ago

1.5.6

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.4.9

2 years ago

1.4.11

2 years ago

1.4.8

2 years ago

1.4.10

2 years ago

1.4.7

2 years ago

1.4.12

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.14

3 years ago

1.0.12

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.20

3 years ago

0.1.19

3 years ago

0.1.18

3 years ago

0.1.17

3 years ago

0.1.16

3 years ago

0.1.15

3 years ago

0.1.14

3 years ago

0.1.13

3 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.0

3 years ago