Skip to content

Commit

Permalink
create API for downloading the binary package
Browse files Browse the repository at this point in the history
  • Loading branch information
mimecorg committed May 30, 2018
1 parent 5855058 commit 4b090e4
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 168 deletions.
46 changes: 46 additions & 0 deletions index.js
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
};
Loading

0 comments on commit 4b090e4

Please sign in to comment.