1.0.5 • Published 4 years ago

local-updater v1.0.5

Weekly downloads
-
License
WTFPL
Repository
-
Last release
4 years ago

localUpdater

  • update your local server code from internet server
  • 局域网代码自动下载升级外网代码源

what scene need use this plugin ? 什么场景使用该插件 ?

  • Local Server of SupperMarket, when the local code needs update from Internet Server。example ThinkJS Server
  • 超市类的局域网服务端程序,当需要升级局域网服务端代码的时候。比如ThinkJS服务端。

how to run localUpdater ? 怎么使用localUpdater?

example, your internet host server is updater.test.com , and your path of lastest.json on your server is /update/json/lastest.json, and the root path of your source code on your server is /update/v2/

  • server update json: lastest.json 你外网服务器升级配置文件lastest.json
{
  "version":"1.0.2",
  "dir":"update/v2/",
  "file_list":[
	{"path":"test2.js","hash":"ad0234829205b9033196ba818f7a872b"},
	{"path":"src/test3.js","hash":""},
	{}
  ]
}
  • your local node server code: 你局域网node服务器代码:
//install and require localUpdater 安装并引入localUpdater
var localUpdater = require('localUpdater');
//create instance of localUpdater 实例化localUpdate
var updater = new localUpdater('http://updater.test.com/update/json/','1.0.0','./');
//listen update Avilable, if res==true, run function update() to download file 监听升级可用事件,若res为true则执行升级方法update()
updater.on('updateAvilable',function(res){
    if(res){
        updater.update();
    }
});
//listen update Error, when res.code>500 the file download error 监听升级错误信息,当res.code>500时为下载文件错误
updater.on('updateError',function(res){
    console.log(res);
});
//listen download file, res = {path:internet_file_path,hash:internet_file_hash,index:internet_file_list_index,counts:internet_file_counts}
//监听每个文件更新下载完成 res = {path:下载文件路径名,hash:下载文件hash值,index:下载文件列表索引,counts:下载文件列表总数}
updater.on('updateFile',function(res){
    console.log(res);
});
//listen download finish, need update your local version number,res = {ver:self.ver,newver:self.newver,file_list:self.file_list}
//监听下载更新完毕事件,这里应该更新本地服的版本号,res = {ver:更新前版本号,newver:更新后版本号,file_list:更新文件列表}
updater.on('updateFinish',function(res){
    console.log(res);
});
//run checkUpdate, auto update => run it ever 60 minutes 执行检查更新方法,建议每隔60分钟检查运行一次,达到自动更新目的
updater.checkUpdate();

how to make file list on internet server ? 外网服务端如何生成升级列表文件?

  • example, install localUpdater in your program directory and run makeList function(needs_make_dir,root_path)
  • 例如,安装localUpdater并引入后,运行如下代码即可,第二个参数为服务端代码根目录路径,第一个参数空字符串即可,若只需要更新部分文件夹代码,则第一个参数为生成列表的目录相对根目录路径
var localUpdater = require('localUpdater');
localUpdater.makeList('','src/v2/');
  • then there will be a file lastest.json