npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-hot-deployment

v1.3.7

Published

## Getting started

Downloads

7

Readme

实践过程 CSDN 有写 https://blog.csdn.net/sinat_35093406/article/details/87938040

react-native-hot-deployment

Getting started

$ npm install react-native-hot-deployment --save

Mostly automatic installation

$ react-native link react-native-hot-deployment

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.xiaomo.HotDeploymentPackage;; to the imports at the top of the file
  • Add new HotDeploymentPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:

    include ':react-native-hot-deployment'
    project(':react-native-hot-deployment').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-hot-deployment/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:

    compile project(':react-native-hot-deployment')
  3. add MainApplication

    import android.content.SharedPreferences;
    import android.content.pm.PackageInfo;
    import android.content.pm.PackageManager;
    import java.io.File;
    private SharedPreferences sharedPreferences;
    
    private String newVersion = "";
    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
      @Override
      protected String getJSBundleFile() {
        PackageManager pm = getApplicationContext().getPackageManager();
        PackageInfo pi;
        try {
            pi = pm.getPackageInfo(getApplicationContext().getPackageName(), 0);
            newVersion = pi.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        sharedPreferences=getSharedPreferences("appVersion.xml",MODE_PRIVATE);
        String oldVersion=sharedPreferences.getString("version","0.0.0");
        String jsBundleFile =  getFilesDir().getAbsolutePath()+"/index.android.bundle";
        File file = new File(jsBundleFile);
        int oldVersionBack=Integer.parseInt(oldVersion.replaceAll("\\.",""));
        int newVersionBack=Integer.parseInt(newVersion.replaceAll("\\.",""));
        if((oldVersion.equals("0.0.0")|| oldVersionBack>=newVersionBack)&& file != null && file.exists()) {
          return jsBundleFile;
        } else {
          return super.getJSBundleFile();
        }
      }
    }

Usage

// TODO: What to do with the module?
import { NativeModules } from "react-native";
const { HotPushVersion, Download, DownloadApk, RestartApp } = NativeModules;

//下载安装包,下载完成后自动跳转安装界面
DownloadApk.downloading(url, "描述");

//下载文件压缩包,地址为自己服务器上部署的地址,压缩包命名应为bundle.zip,里面包含index.android.bundle和资源文件(drawable\drawable-****)
Download.downloading(url);

//下载进度监听,下载完成后可调用RestartApp.Restart()重启app
this.listener = DeviceEventEmitter.addListener('downloadZipStatus', (e) => {
	if (e && e.status === "success") {
    //下载成功
    //需要传入最新版本号,目前插件只支持版本号格式为x.x.x
    HotPushVersion.updataVersion(version);
		RestartApp.Restart()
  } else if(e && e.status === "error") {
    //下载失败
  }else if(e && e.status === "decompressionError") {
    //解压bundle.zip文件失败
  }else if (e && e.status) {
		//下载进度
		console.log("下载进度====>" + e.status + "%")
	} else {
		//失败
	}
})

//重新启动app
RestartApp.Restart()


//一般来说,后端需要提供一个接口用来判断是否需要更新和以什么方式来更新。
//下载安装包的方式只需要调用DownloadApk.downloading(url, "描述");
//热更新方式则须使用以下命令打包资源文件。
react-native bundle --platform android --dev false --entry-file index.js  --bundle-output bundle_zip/index.android.bundle  --assets-dest bundle_zip

//然后将资源文件放置服务器以供下载Download.downloading(url);下载完成后调用RestartApp.Restart()重启APP即可完成热更新。当然打包资源文件前需要在package更改版本号。(这里我们需要改变一下版本号的获取方式,在app的build.gradle最外层加上如下行代码,这样就只需修改package.json里面的版本号。)

import com.android.build.OutputFile
import groovy.json.JsonSlurper
def getAppVersion(){
    def inputFile = new File("../package.json")
    def packageJson = new JsonSlurper().parseText(inputFile.text)
    return packageJson["version"]
}
def appVersion = getAppVersion()
android{defaultconfig{versionName appVersion}}


//会android原生的同学可以把插件拉取下来根据需求自行更改