-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from edjafarov/custom-names
Custom app names, exec paths, etc.
- Loading branch information
Showing
7 changed files
with
335 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,92 @@ | ||
node-webkit-updater [![NPM version][npm-image]][npm-url] | ||
======= | ||
This is [node-webkit](https://github.com/rogerwang/node-webkit)-updater. | ||
|
||
``` | ||
npm install node-webkit-updater | ||
``` | ||
|
||
It gives you low-level API to: | ||
|
||
1. Check the manifest for version (from your running "old" app). | ||
2. If the version is different from the running one, download new package to a temp directory. | ||
3. Unpack the package in temp. | ||
4. Run new app from temp and kill the old one (i.e. still all from the running app). | ||
5. The new app (in temp) will copy itself to the original folder, overriding the old app. | ||
6. The new app will run itself from original folder and exit the process. | ||
|
||
You should build this logic by yourself though. As a reference you can use [example](app/index.html). | ||
|
||
Covered by tests and works for [linux](http://screencast.com/t/Je2ptbHhP), [windows](http://screencast.com/t/MSTKqVS3) and [mac](http://screencast.com/t/OXyC5xoA). | ||
### How to run the tests | ||
``` | ||
git clone [email protected]:edjafarov/updater.git | ||
npm run deps | ||
npm test | ||
``` | ||
|
||
## Quick Start | ||
```javascript | ||
var gui = require('nw.gui'); | ||
var pkg = require('../package.json'); // Insert your app's manifest here | ||
var updater = require('node-webkit-updater'); | ||
var upd = new updater(pkg); | ||
|
||
/* Checks the remote manifest for latest available version and calls the autoupgrading function */ | ||
upd.checkNewVersion(function(error, newVersionExists, manifest) { | ||
if (!error && newVersionExists) { | ||
upgradeNow(manifest); | ||
} | ||
}); | ||
|
||
/* Downloads the new version, unpacks it, replaces the existing files, runs the new version, and exits the old app */ | ||
function upgradeNow(newManifest) { | ||
var newVersion = upd.download(function(error, filename) { | ||
if (!error) { | ||
upd.unpack(filename, function(error, newAppPath) { | ||
if (!error) { | ||
upd.runInstaller(newAppPath, [upd.getAppPath(), upd.getAppExec()],{}); | ||
gui.App.quit(); | ||
} | ||
}); | ||
} | ||
}, newManifest); | ||
} | ||
``` | ||
|
||
|
||
## API | ||
|
||
As a reference you can use the [example](https://github.com/edjafarov/updater/blob/master/app/index.html). | ||
|
||
node-webkit-updater [![NPM version][npm-image]][npm-url] | ||
======= | ||
This is [node-webkit](https://github.com/rogerwang/node-webkit)-updater. | ||
|
||
``` | ||
npm install node-webkit-updater | ||
``` | ||
|
||
It gives you low-level API to: | ||
|
||
1. Check the manifest for version (from your running "old" app). | ||
2. If the version is different from the running one, download new package to a temp directory. | ||
3. Unpack the package in temp. | ||
4. Run new app from temp and kill the old one (i.e. still all from the running app). | ||
5. The new app (in temp) will copy itself to the original folder, overriding the old app. | ||
6. The new app will run itself from original folder and exit the process. | ||
|
||
You should build this logic by yourself though. As a reference you can use [example](app/index.html). | ||
|
||
Covered by tests and works for [linux](http://screencast.com/t/Je2ptbHhP), [windows](http://screencast.com/t/MSTKqVS3) and [mac](http://screencast.com/t/OXyC5xoA). | ||
### How to run the tests | ||
``` | ||
git clone [email protected]:edjafarov/updater.git | ||
npm run deps | ||
npm test | ||
``` | ||
|
||
## Quick Start | ||
```javascript | ||
var gui = require('nw.gui'); | ||
var pkg = require('../package.json'); // Insert your app's manifest here | ||
var updater = require('node-webkit-updater'); | ||
var upd = new updater(pkg); | ||
|
||
/* Checks the remote manifest for latest available version and calls the autoupgrading function */ | ||
upd.checkNewVersion(function(error, newVersionExists, manifest) { | ||
if (!error && newVersionExists) { | ||
upgradeNow(manifest); | ||
} | ||
}); | ||
|
||
/* Downloads the new version, unpacks it, replaces the existing files, runs the new version, and exits the old app */ | ||
function upgradeNow(newManifest) { | ||
var newVersion = upd.download(function(error, filename) { | ||
if (!error) { | ||
upd.unpack(filename, function(error, newAppPath) { | ||
if (!error) { | ||
upd.runInstaller(newAppPath, [upd.getAppPath(), upd.getAppExec()],{}); | ||
gui.App.quit(); | ||
} | ||
}, newManifest); | ||
} | ||
}, newManifest); | ||
} | ||
``` | ||
|
||
|
||
## API | ||
|
||
As a reference you can use the [example](https://github.com/edjafarov/updater/blob/master/app/index.html). | ||
|
||
<a name="new_updater"></a> | ||
###new updater(manifest) | ||
Creates new instance of updater. Manifest could be a `package.json` of project.```json{ "name": "updapp", "version": "0.0.2", "author": "Eldar Djafarov <[email protected]>", "manifestUrl": "http://localhost:3000/package.json", "packages": { "mac": "http://localhost:3000/releases/updapp/mac/updapp.zip", "win": "http://localhost:3000/releases/updapp/win/updapp.zip", "linux32": "http://localhost:3000/releases/updapp/linux32/updapp.tar.gz" }}```Inside the app manifest, you need to specify where to download packages from for all supported OS'es, a manifest url where this manifest can be found and the current version of the app.Note that compressed apps are assumed to be downloaded in the format produced by [node-webkit-builder](https://github.com/mllrsohn/node-webkit-builder) (or [grunt-node-webkit-builder](https://github.com/mllrsohn/grunt-node-webkit-builder)). | ||
Creates new instance of updater. Manifest could be a `package.json` of project. | ||
|
||
Note that compressed apps are assumed to be downloaded in the format produced by [node-webkit-builder](https://github.com/mllrsohn/node-webkit-builder) (or [grunt-node-webkit-builder](https://github.com/mllrsohn/grunt-node-webkit-builder)). | ||
|
||
**Params** | ||
|
||
- manifest `object` | ||
- manifest `object` - See the [manifest schema](#manifest-schema) below. | ||
|
||
<a name="updater#checkNewVersion"></a> | ||
###updater.checkNewVersion(cb) | ||
Will check the latest available version of the application by requesting the manifest specified in `manufestUrl`.The callback will always be called; the second paramter indicates whether or not there's a newer version.This function assumes you use [Semantic Versioning](http://semver.org) and enforces it; if your local version is `0.2.0` and the remote one is `0.1.23456` then the callback will be called with `false` as the second paramter. If on the off chance you don't use semantic versioning, you could manually download the remote manifest and call `download` if you're happy that the remote version is newer. | ||
Will check the latest available version of the application by requesting the manifest specified in `manifestUrl`. | ||
|
||
The callback will always be called; the second parameter indicates whether or not there's a newer version. | ||
This function assumes you use [Semantic Versioning](http://semver.org) and enforces it; if your local version is `0.2.0` and the remote one is `0.1.23456` then the callback will be called with `false` as the second paramter. If on the off chance you don't use semantic versioning, you could manually download the remote manifest and call `download` if you're happy that the remote version is newer. | ||
|
||
**Params** | ||
|
||
- cb `function` - Callback arguments: error, newerVersionExists (`Boolean`), remoteManfiest | ||
- cb `function` - Callback arguments: error, newerVersionExists (`Boolean`), remoteManifest | ||
|
||
<a name="updater#clean"></a> | ||
###updater.clean(cb) | ||
Cleans previous app from temp folder. Do it before downloading stuff. | ||
|
||
**Params** | ||
|
||
- cb `function` - called when download completes. Callback arguments: error, downloaded filepath | ||
|
||
<a name="updater#download"></a> | ||
###updater.download(cb, newManifest) | ||
|
@@ -82,7 +95,7 @@ Downloads the new app to a template folder | |
**Params** | ||
|
||
- cb `function` - called when download completes. Callback arguments: error, downloaded filepath | ||
- newManifest `Object` - package.json manifest where are defined remote url | ||
- newManifest `Object` - see [manifest schema](#manifest-schema) below | ||
|
||
**Returns**: `Request` - Request - stream, the stream contains `manifest` property with new manifest | ||
<a name="updater#getAppPath"></a> | ||
|
@@ -96,13 +109,15 @@ Returns current application executable | |
|
||
**Returns**: `string` | ||
<a name="updater#unpack"></a> | ||
###updater.unpack(filename, cb) | ||
Will unpack the `filename` in temporary folder.For Windows, [unzip](https://www.mkssoftware.com/docs/man1/unzip.1.asp) is used. | ||
###updater.unpack(filename, cb, manifest) | ||
Will unpack the `filename` in temporary folder. | ||
For Windows, [unzip](https://www.mkssoftware.com/docs/man1/unzip.1.asp) is used. | ||
|
||
**Params** | ||
|
||
- filename `string` | ||
- cb `function` - Callback arguments: error, unpacked directory | ||
- manifest `object` | ||
|
||
<a name="updater#runInstaller"></a> | ||
###updater.runInstaller(appPath, args, options) | ||
|
@@ -131,18 +146,67 @@ Runs the app from original path. | |
**Params** | ||
|
||
- execPath `string` | ||
- args `array` - Arguments based to the app being ran | ||
- options `object` - Optional | ||
- args `array` - Arguments based to the app being ran. Ignored on Windows & Mac | ||
- options `object` - Optional. Ignored on Windows & Mac | ||
|
||
--- | ||
|
||
## Manifest Schema | ||
|
||
An example manifest: | ||
|
||
```json | ||
{ | ||
"name": "updapp", | ||
"version": "0.0.2", | ||
"author": "Eldar Djafarov <[email protected]>", | ||
"manifestUrl": "http://localhost:3000/package.json", | ||
"packages": { | ||
"mac": { | ||
"url": "http://localhost:3000/releases/updapp/mac/updapp.zip" | ||
}, | ||
"win": { | ||
"url": "http://localhost:3000/releases/updapp/win/updapp.zip" | ||
}, | ||
"linux32": { | ||
"url": "http://localhost:3000/releases/updapp/linux32/updapp.tar.gz" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
The manifest could be a `package.json` of project, but doesn't have to be. | ||
|
||
### manifest.name | ||
|
||
The name of your app. From time, it is assumed your Mac app is called `<manifest.name>.app`, your Windows executable is `<manifest.name>.exe`, etc. | ||
|
||
### manifest.version | ||
[semver](http://semver.org) version of your app. | ||
|
||
### manifest.manifestUrl | ||
The URL where your latest manifest is hosted; where node-webkit-updater looks to check if there is a newer version of your app available. | ||
|
||
### manifest.packages | ||
An "object" containing an object for each OS your app (at least this version of your app) supports; `mac`, `win`, `linux32`, `linux64`. | ||
|
||
### manifest.packages.{mac, win, linux32, linux64}.url | ||
Each package has to contain a `url` property pointing to where the app (for the version & OS in question) can be downloaded. | ||
|
||
### manifest.packages.{mac, win, linux32, linux64}.execPath (Optional) | ||
It's assumed your app is stored at the root of your package, use this to override that and specify a path (relative to the root of your package). | ||
|
||
This can also be used to override `manifest.name`; e.g. if your `manifest.name` is `helloWorld` (therefore `helloWorld.app` on Mac) but your Windows executable is named `nw.exe`. Then you'd set `execPath` to `nw.exe` | ||
|
||
--- | ||
|
||
## Troubleshooting | ||
|
||
If you get an error on Mac about too many files being open, run `ulimit -n 10240` | ||
|
||
## Contributing | ||
|
||
See [CONTRIBUTING.md](CONTRIBUTING.md) | ||
|
||
--- | ||
|
||
## Troubleshooting | ||
|
||
If you get an error on Mac about too many files being open, run `ulimit -n 10240` | ||
|
||
## Contributing | ||
|
||
See [CONTRIBUTING.md](CONTRIBUTING.md) | ||
|
||
[npm-url]: https://npmjs.org/package/node-webkit-updater | ||
[npm-url]: https://npmjs.org/package/node-webkit-updater | ||
[npm-image]: https://badge.fury.io/js/node-webkit-updater.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.