1.4.3 • Published 11 months ago

rn-codepush v1.4.3

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

rn-codepush

热更新组件

Installation

yarn add rn-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 ['app-3.2.2', 'app-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 'rn-codepush';

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

测试支持切换环境

import { CodePush } from 'rn-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/app-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

Contributing

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

License

MIT

1.4.3

11 months ago

1.4.2

11 months ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago