Auto-Updater
Node.js auto-update plugin.
Compares local package.json with repository package.json and if versions don't match, it downloads the latest zip and extracts it.
Installation
With npm do:
$ npm install auto-updater
What does it do?
- Compares local version with remote version.
- If versions don't match, it downloads the repository.
- It extracts the repository, overwriting the modified files.
- Compares local dependencies with remote dependencies and tells if they don't match.
Events
git-clone
The user has a git clone. Recommend use the "git pull" commandcheck.up-to-date ( v )
versions matchcheck.out-dated ( v_old , v)
versions dont matchupdate.downloaded
Update downloaded in the machineupdate.not-installed
Update was already in the dir, so it wasnt installedupdate.extracted
The update has been extracted correctly.download.start ( name )
The download of "name of the update" has starteddownload.progress ( name , % )
The download has been updated. New percentagedownload.end ( name )
The download has endeddownload.error ( err )
Something happened to the downloadend
Called when all is over ( along with 'check-up-to-date' if there are no updates, or with 'extracted' if it was installed )
Public Methods:
use ( config )
on ( event, callback )
Sets the events (use like EventEmitter)fire ( command )
Fires a command
Config
pathToJson: ''
from repo main folder to package.json (only subfolders. Can't go backwards)autoupdate: false
if true, all stages run one after the other. Else, you need to force the stages with the force methodscheckgit: true
Checks if the .git folder exists, so its a dev and doesnt download the proyect.jsonhost: 'raw.githubusercontent.com'
URL of raw remote package.jsoncontenthost: 'codeload.github.com'
URL of full remote zipprogressDebounce: 0
Debounces the 'download.progress' event (0 = disabled)devmode: false
Developer Mode. Enhances error messages using console.log
Commands
check
Compares the two versions. Triggers: 'git-clone', 'check.up-to-date', 'check.out-dated'download-update
Downloads the update. Triggers: 'update.downloaded', 'update.not-installed','download.*'extract
Extracts (or installs) the update reeplacing old files (it doesnt delete untracked files). Triggers: 'update.extracted'diff-dependencies
Returns an array of dependencies (only the names) that dont match. Returns an empty array if there's no difference. Requires the 'check' command first.
Warning: do not run this methods in other order.
Package.json configuration
"version":"0.0.1",
"auto-updater":{
"repo":"/github-user/github-repo",
"branch":"master"
}
That segment must be added to the proyect (local). It is critical that the package.json of the app you are using has a version field (so it can be compared with the remote package.json stored on github), and the auto-updater field, so it knows where to get the remote data.
Example
var AutoUpdater = ; var autoupdater = pathToJson: '' autoupdate: false checkgit: true jsonhost: 'raw.githubusercontent.com' contenthost: 'codeload.github.com' progressDebounce: 0 devmode: false ; // State the events autoupdater; autoupdater; autoupdater; autoupdater; autoupdater; autoupdater; autoupdater; autoupdater; autoupdater; autoupdater; autoupdater; autoupdater; // Start checking autoupdater;