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

hupdater

v1.5.2

Published

updater for nwjs client

Downloads

8

Readme

nw.js 客户端更新模块

安装

    npm install hupdater

主要API

restartApp(App)

  • 重启应用
  • App nw.js的App对象(require('nw.gui').App)

checkVersion(checkVersionUrl, cb)

  • checkVersionUrl 新版本检查Rest Url ,返回 x.y.x 格式版本号
  • cb 回调函数,cb(err, version), 且函数第一个参数为err, 第二个为版本号

ifNeedUpdate(localVersion, latestVersion)

  • 是否需要更新版本
  • localVersion 本地客户端版本号
  • latestVersion 最新版本号

downloadNewVersion(url, toUrl, cb)

  • 下载新版本文件
  • url ,新版本下载地址
  • toUrl, 本地保存路径
  • cb,回调函数,cb(err, dir), 且函数第一个参数为err, 第二个为文件下载后本地绝对路径

unpackNewVersion(filePath, cb)

  • 解压缩下载的新版本压缩包
  • filePath, 新版本压缩包的本地绝对路径
  • cb,解压完成后回调函数

cleanOldVersion(oldPath, cb)

  • 版本更新后,清理旧版本文件
  • oldPath, 旧版本文件夹绝对路径
  • cb,清理完成后回调函数

Demo

var gui = require('nw.gui');
var path = require('path');
var updater = require('hupdater');
var pkg = require('./../package.json');

/**
 * 更新
 */
function update(){
    console.log('--开始检查新版本');

    var serverUrl = pkg.updateServer; //更新服务地址
    var localVersion = pkg.version;  //本地版本号
    var targetPath =  path.dirname(process.execPath); //本地程序根目录

    var versionCheckApi = serverUrl + '/api/client/one/version';
  
    //开始检查版本号
    updater.checkVersion(versionCheckApi, function (err, newVersion) {
        if(err){
            console.log(err);
            console.log('--检查更新失败');
            return;
        }
        //判断是否需要更新
        var ifUpdate = updater.ifNeedUpdate(localVersion, newVersion);
        if(ifUpdate){
            console.log('--发现新版本,开始下载新版本');

            var downloadApi = serverUrl + '/api/client/one/version/'+newVersion+'.zip';
            //开始下载新版本包
            updater.downloadNewVersion(downloadApi, targetPath, function(err, filePath){
                if(err){
                    console.log(err);
                    console.log('--下载更新失败>');
                    return;
                }
                //下载完成后,开始解压缩更新包
                console.log('--下载完成,开始更新新版本');
                updater.unpackNewVersion(filePath, function() {
                    console.log('--更新完成,5秒后将重启程序');
                    updater.cleanOldVersion(filePath, function(err) {
                        
                    });
                    setTimeout(function () {
                        updater.restartApp(gui.App);
                    },5000);

                });
            });
        }else{
            console.log('--没有发现新版本');
        }
    });
}