-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
46 lines (33 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const fs = require( 'fs' );
const os = require( 'os' );
const path = require( 'path' );
const nugget = require( 'nugget' );
const version = require( './package' ).version;
function download( opts, callback ) {
if ( typeof opts === 'function' ) {
callback = opts;
opts = {};
}
const fileVersion = opts.version || version;
const platform = opts.platform || process.platform;
const arch = opts.arch || process.arch;
const cacheDir = opts.cache || path.join( os.homedir(), '.launchui' );
const fileName = 'launchui-v' + fileVersion + '-' + platform + '-' + arch + '.zip';
const zipPath = path.join( cacheDir, fileName );
if ( !fs.existsSync( zipPath ) ) {
if ( !fs.existsSync( cacheDir ) )
fs.mkdirSync( cacheDir )
const url = 'https://github.com/mimecorg/launchui/releases/download/v' + fileVersion + '/' + fileName;
nugget( url, { target: fileName, dir: cacheDir }, errors => {
if ( errors != null )
return callback( errors[ 0 ], null );
callback( null, zipPath );
} );
} else {
callback( null, zipPath );
}
}
module.exports = {
version,
download
};