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

files-delta-updater

v1.0.1

Published

Only use static resource servers to implement differential updates of resources

Downloads

14

Readme

files-delta-updater

你可以使用files-detla-updater在仅仅使用静态资源服务器的条件下来实现资源的差量更新

安装

You need node.js and npm.

npm install files-delta-updater --save-dev

使用

const { DeltaUpdater } = require('files-delta-updater');

const deltaUpdater = new DeltaUpdater({
	baseRootPath: "C:\\Program Files\\myapp\\dist",
	updateRootPath: "C:\\Program Files\\myapp_source\\dist",
	remoteRootUrl: "https://oss.template.com/myapp", 
	channels: ["1.0.0","stable"]
})

deltaUpdater.getLatestVersionAfterSwitch().then(({path, version}) => {
	console.log(path); // The directory where the latest version of the file is located
	console.log(version); // the latest version

	deltaUpdater.checkUpdate(); // Start checking for updates
})

new DeltaUpdater(options)

  • options DeltaUpdaterConfig
    • baseRootPath string (必填) - 更新器基础目录。当无已下载的更新资源时,则更新器使用该目录进行工作。
    • updateRootPath string (必填) - 更新器版本管理目录。新生成的目录将保存在此目录下。
    • remoteRootUrl string (必填) - 远程资源的URL。
    • channels string[] (可选) - 更新渠道。分渠道更新资源。
    • clearOldVersion boolean (可选) - 是否清理老版本资源。默认值为true,当更新器切换至最新版本后,将自动清理老版本资源文件。
    • versionAvailable function (可选) - 自定版本比较规则。默认 当本地版本与远程版本不一致时进行更新。
    • requestInstanceCreator function (可选) - 自定义在获取更新文件时使用的axios实例

实例方法

方法:getLatestVersionAfterSwitch()

返回: Promise<{ version: string; path: string; }>

  • version 本地可用的最新版本
  • path 本地可用的最新版本所在目录
方法:checkUpdate(forceCheck)

参数:forceCheck 默认值true,检查步骤中的渠道检查不通过时则继续更新流程,否则反之。

返回:

  • checkResult 枚举值
    • not-available--channels
    • not-available--version
    • not-available--staging
    • usable
    • success

实例事件

使用new DeltaUpdater创建的对象具有以下事件:

事件:not-available

无可用更新时触发; 返回:

  • result

    • reason
    • message
  • reason值的枚举:

    • not-available--channels 渠道检查不满足条件
    • not-available--version 版本检查不满足条件
    • not-available--staging 灰度更新检查不满足条件
事件:download

资源正在下载时触发; 返回:

  • result

    • total
    • process
  • total 带下载资源总数

  • process 下载进度

事件:downloaded

资源下载完成时触发; 返回:

  • result

    • currentVersion
    • nextVersion
    • nextVersionDir
  • currentVersion 当前版本号

  • nextVersion 下一个版本号

  • nextVersionDir 下一个版本所在目录

事件:usable

可用资源已下载至本地且已生成最新版本资源文件时触发; 返回:

  • result

    • currentVersion
    • nextVersion
    • nextVersionDir
  • currentVersion 当前版本号

  • nextVersion 下一个版本号

  • nextVersionDir 下一个版本所在目录

事件:error

更新器运行报错时触发; 返回:

  • Error