Skip to content

Commit ec9eaf2

Browse files
committed
Merge pull request #37 from edjafarov/custom-names
Custom app names, exec paths, etc.
2 parents 107517e + 0d5f7a2 commit ec9eaf2

File tree

7 files changed

+335
-153
lines changed

7 files changed

+335
-153
lines changed

README.md

Lines changed: 145 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,92 @@
1-
node-webkit-updater [![NPM version][npm-image]][npm-url]
2-
=======
3-
This is [node-webkit](https://github.com/rogerwang/node-webkit)-updater.
4-
5-
```
6-
npm install node-webkit-updater
7-
```
8-
9-
It gives you low-level API to:
10-
11-
1. Check the manifest for version (from your running "old" app).
12-
2. If the version is different from the running one, download new package to a temp directory.
13-
3. Unpack the package in temp.
14-
4. Run new app from temp and kill the old one (i.e. still all from the running app).
15-
5. The new app (in temp) will copy itself to the original folder, overriding the old app.
16-
6. The new app will run itself from original folder and exit the process.
17-
18-
You should build this logic by yourself though. As a reference you can use [example](app/index.html).
19-
20-
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).
21-
### How to run the tests
22-
```
23-
git clone git@github.com:edjafarov/updater.git
24-
npm run deps
25-
npm test
26-
```
27-
28-
## Quick Start
29-
```javascript
30-
var gui = require('nw.gui');
31-
var pkg = require('../package.json'); // Insert your app's manifest here
32-
var updater = require('node-webkit-updater');
33-
var upd = new updater(pkg);
34-
35-
/* Checks the remote manifest for latest available version and calls the autoupgrading function */
36-
upd.checkNewVersion(function(error, newVersionExists, manifest) {
37-
if (!error && newVersionExists) {
38-
upgradeNow(manifest);
39-
}
40-
});
41-
42-
/* Downloads the new version, unpacks it, replaces the existing files, runs the new version, and exits the old app */
43-
function upgradeNow(newManifest) {
44-
var newVersion = upd.download(function(error, filename) {
45-
if (!error) {
46-
upd.unpack(filename, function(error, newAppPath) {
47-
if (!error) {
48-
upd.runInstaller(newAppPath, [upd.getAppPath(), upd.getAppExec()],{});
49-
gui.App.quit();
50-
}
51-
});
52-
}
53-
}, newManifest);
54-
}
55-
```
56-
57-
58-
## API
59-
60-
As a reference you can use the [example](https://github.com/edjafarov/updater/blob/master/app/index.html).
61-
1+
node-webkit-updater [![NPM version][npm-image]][npm-url]
2+
=======
3+
This is [node-webkit](https://github.com/rogerwang/node-webkit)-updater.
4+
5+
```
6+
npm install node-webkit-updater
7+
```
8+
9+
It gives you low-level API to:
10+
11+
1. Check the manifest for version (from your running "old" app).
12+
2. If the version is different from the running one, download new package to a temp directory.
13+
3. Unpack the package in temp.
14+
4. Run new app from temp and kill the old one (i.e. still all from the running app).
15+
5. The new app (in temp) will copy itself to the original folder, overriding the old app.
16+
6. The new app will run itself from original folder and exit the process.
17+
18+
You should build this logic by yourself though. As a reference you can use [example](app/index.html).
19+
20+
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).
21+
### How to run the tests
22+
```
23+
git clone git@github.com:edjafarov/updater.git
24+
npm run deps
25+
npm test
26+
```
27+
28+
## Quick Start
29+
```javascript
30+
var gui = require('nw.gui');
31+
var pkg = require('../package.json'); // Insert your app's manifest here
32+
var updater = require('node-webkit-updater');
33+
var upd = new updater(pkg);
34+
35+
/* Checks the remote manifest for latest available version and calls the autoupgrading function */
36+
upd.checkNewVersion(function(error, newVersionExists, manifest) {
37+
if (!error && newVersionExists) {
38+
upgradeNow(manifest);
39+
}
40+
});
41+
42+
/* Downloads the new version, unpacks it, replaces the existing files, runs the new version, and exits the old app */
43+
function upgradeNow(newManifest) {
44+
var newVersion = upd.download(function(error, filename) {
45+
if (!error) {
46+
upd.unpack(filename, function(error, newAppPath) {
47+
if (!error) {
48+
upd.runInstaller(newAppPath, [upd.getAppPath(), upd.getAppExec()],{});
49+
gui.App.quit();
50+
}
51+
}, newManifest);
52+
}
53+
}, newManifest);
54+
}
55+
```
56+
57+
58+
## API
59+
60+
As a reference you can use the [example](https://github.com/edjafarov/updater/blob/master/app/index.html).
61+
6262
<a name="new_updater"></a>
6363
###new updater(manifest)
64-
Creates new instance of updater. Manifest could be a `package.json` of project.```json{ "name": "updapp", "version": "0.0.2", "author": "Eldar Djafarov <djkojb@gmail.com>", "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)).
64+
Creates new instance of updater. Manifest could be a `package.json` of project.
65+
66+
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)).
6567

6668
**Params**
6769

68-
- manifest `object`
70+
- manifest `object` - See the [manifest schema](#manifest-schema) below.
6971

7072
<a name="updater#checkNewVersion"></a>
7173
###updater.checkNewVersion(cb)
72-
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.
74+
Will check the latest available version of the application by requesting the manifest specified in `manifestUrl`.
75+
76+
The callback will always be called; the second parameter indicates whether or not there's a newer version.
77+
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.
7378

7479
**Params**
7580

76-
- cb `function` - Callback arguments: error, newerVersionExists (`Boolean`), remoteManfiest
81+
- cb `function` - Callback arguments: error, newerVersionExists (`Boolean`), remoteManifest
82+
83+
<a name="updater#clean"></a>
84+
###updater.clean(cb)
85+
Cleans previous app from temp folder. Do it before downloading stuff.
86+
87+
**Params**
88+
89+
- cb `function` - called when download completes. Callback arguments: error, downloaded filepath
7790

7891
<a name="updater#download"></a>
7992
###updater.download(cb, newManifest)
@@ -82,7 +95,7 @@ Downloads the new app to a template folder
8295
**Params**
8396

8497
- cb `function` - called when download completes. Callback arguments: error, downloaded filepath
85-
- newManifest `Object` - package.json manifest where are defined remote url
98+
- newManifest `Object` - see [manifest schema](#manifest-schema) below
8699

87100
**Returns**: `Request` - Request - stream, the stream contains `manifest` property with new manifest
88101
<a name="updater#getAppPath"></a>
@@ -96,13 +109,15 @@ Returns current application executable
96109

97110
**Returns**: `string`
98111
<a name="updater#unpack"></a>
99-
###updater.unpack(filename, cb)
100-
Will unpack the `filename` in temporary folder.For Windows, [unzip](https://www.mkssoftware.com/docs/man1/unzip.1.asp) is used.
112+
###updater.unpack(filename, cb, manifest)
113+
Will unpack the `filename` in temporary folder.
114+
For Windows, [unzip](https://www.mkssoftware.com/docs/man1/unzip.1.asp) is used.
101115

102116
**Params**
103117

104118
- filename `string`
105119
- cb `function` - Callback arguments: error, unpacked directory
120+
- manifest `object`
106121

107122
<a name="updater#runInstaller"></a>
108123
###updater.runInstaller(appPath, args, options)
@@ -131,18 +146,67 @@ Runs the app from original path.
131146
**Params**
132147

133148
- execPath `string`
134-
- args `array` - Arguments based to the app being ran
135-
- options `object` - Optional
149+
- args `array` - Arguments based to the app being ran. Ignored on Windows & Mac
150+
- options `object` - Optional. Ignored on Windows & Mac
151+
152+
---
153+
154+
## Manifest Schema
155+
156+
An example manifest:
157+
158+
```json
159+
{
160+
"name": "updapp",
161+
"version": "0.0.2",
162+
"author": "Eldar Djafarov <djkojb@gmail.com>",
163+
"manifestUrl": "http://localhost:3000/package.json",
164+
"packages": {
165+
"mac": {
166+
"url": "http://localhost:3000/releases/updapp/mac/updapp.zip"
167+
},
168+
"win": {
169+
"url": "http://localhost:3000/releases/updapp/win/updapp.zip"
170+
},
171+
"linux32": {
172+
"url": "http://localhost:3000/releases/updapp/linux32/updapp.tar.gz"
173+
}
174+
}
175+
}
176+
```
177+
178+
The manifest could be a `package.json` of project, but doesn't have to be.
179+
180+
### manifest.name
181+
182+
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.
183+
184+
### manifest.version
185+
[semver](http://semver.org) version of your app.
186+
187+
### manifest.manifestUrl
188+
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.
189+
190+
### manifest.packages
191+
An "object" containing an object for each OS your app (at least this version of your app) supports; `mac`, `win`, `linux32`, `linux64`.
192+
193+
### manifest.packages.{mac, win, linux32, linux64}.url
194+
Each package has to contain a `url` property pointing to where the app (for the version & OS in question) can be downloaded.
195+
196+
### manifest.packages.{mac, win, linux32, linux64}.execPath (Optional)
197+
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).
198+
199+
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`
200+
201+
---
202+
203+
## Troubleshooting
204+
205+
If you get an error on Mac about too many files being open, run `ulimit -n 10240`
206+
207+
## Contributing
208+
209+
See [CONTRIBUTING.md](CONTRIBUTING.md)
136210

137-
---
138-
139-
## Troubleshooting
140-
141-
If you get an error on Mac about too many files being open, run `ulimit -n 10240`
142-
143-
## Contributing
144-
145-
See [CONTRIBUTING.md](CONTRIBUTING.md)
146-
147-
[npm-url]: https://npmjs.org/package/node-webkit-updater
211+
[npm-url]: https://npmjs.org/package/node-webkit-updater
148212
[npm-image]: https://badge.fury.io/js/node-webkit-updater.png

app/index.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
console.log(err);
5252
return;
5353
}
54-
upd.run(execPath, null, {});
54+
upd.run(execPath, null);
5555
gui.App.quit();
5656
}
5757
}
@@ -73,29 +73,31 @@
7373
d = true;
7474
clearInterval(newVersionCheckIntervalId);
7575
var loaded = 0;
76-
var newVersion = upd.download(newVersionDownloaded, manifest);
76+
var newVersion = upd.download(function(error, filename){
77+
newVersionDownloaded(error, filename, manifest);
78+
}, manifest);
7779
newVersion.on('data', function(chunk){
7880
loaded+=chunk.length;
7981
document.getElementById('loaded').innerHTML = "New version loading " + Math.floor(loaded / 1024) + 'kb';
8082
})
8183
}
8284

83-
function newVersionDownloaded(err, filename){
85+
function newVersionDownloaded(err, filename, manifest){
8486
if(err){
8587
console.log(err)
8688
return Error(err);
8789
}
8890
document.getElementById('loaded').innerHTML = "unpacking: " + filename;
89-
upd.unpack(filename, newVersionUnpacked);
91+
upd.unpack(filename, newVersionUnpacked, manifest);
9092
}
9193

9294
function newVersionUnpacked(err, newAppPath){
9395
if(err){
9496
console.log(err)
9597
return Error(err);
9698
}
97-
console.log(newAppPath, upd.getAppPath(), upd.getAppExec());
98-
var runner = upd.runInstaller(newAppPath, [upd.getAppPath(), upd.getAppExec()],{});
99+
console.log(newAppPath, [upd.getAppPath(), upd.getAppExec()]);
100+
var runner = upd.runInstaller(newAppPath, [upd.getAppPath(), upd.getAppExec()]);
99101
runner.stdout.on('data',
100102
function(data){
101103
console.log(data)

app/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"license": "MIT",
77
"manifestUrl": "https://raw.githubusercontent.com/openconf/updater/master/package.json",
88
"packages": {
9-
"mac": "https://github.com/openconf/updater/blob/master/deploy/releases/updapp/mac/updapp.dmg?raw=true"
9+
"mac": {
10+
"url": "https://github.com/openconf/updater/blob/master/deploy/releases/updapp/mac/updapp.dmg?raw=true"
11+
}
1012
},
1113
"window": {
1214
"toolbar": true
@@ -15,6 +17,7 @@
1517
"dependencies": {
1618
"ncp": "^0.5.1",
1719
"request": "^2.36.0",
20+
"del": "~0.1.2",
1821
"semver": "^3.0.1"
1922
}
2023
}

0 commit comments

Comments
 (0)