-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create API for downloading the binary package
- Loading branch information
Showing
3 changed files
with
111 additions
and
168 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 |
---|---|---|
@@ -0,0 +1,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 plaftorm = opts.plaftorm || process.platform; | ||
const arch = opts.arch || process.arch; | ||
|
||
const cacheDir = opts.cache || path.join( os.homedir(), '.launchui' ); | ||
|
||
const fileName = 'launchui-v' + fileVersion + '-' + plaftorm + '-' + 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 | ||
}; |
Oops, something went wrong.