diff --git a/__mocks__/remote.js b/__mocks__/remote.js new file mode 100644 index 0000000000..b2c2ab1348 --- /dev/null +++ b/__mocks__/remote.js @@ -0,0 +1,4 @@ +module.exports = { + require: jest.genMockFunction(), + match: jest.genMockFunction() +}; diff --git a/gulpfile.js b/gulpfile.js index b52142baa2..09b70a92b9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -14,6 +14,9 @@ var plumber = require('gulp-plumber'); var runSequence = require('run-sequence'); var shell = require('gulp-shell'); var sourcemaps = require('gulp-sourcemaps'); +var execFile = require('child_process').execFile; +var request = require('request'); +var path = require('path'); var dependencies = Object.keys(packagejson.dependencies); var argv = require('minimist')(process.argv.slice(2)); @@ -175,16 +178,96 @@ gulp.task('settings', function () { string_src('settings.json', JSON.stringify(settings)).pipe(gulp.dest('dist/osx/' + options.appFilename.replace(' ', '\ ').replace('(','\(').replace(')','\)') + '/Contents/Resources/app')); }); -gulp.task('download-deps', function () { - if(process.platform === 'win32') { - return gulp.src('').pipe( - shell(['powershell.exe -ExecutionPolicy unrestricted -File util\\deps.ps1']) - ); - } else { - return gulp.src('').pipe( - shell(['./util/deps']) - ); +var version = function (str) { + var match = str.match(/(\d+\.\d+\.\d+)/); + if (match) { + return match[1]; + } else { + return null; + } +}; + +gulp.task('download-docker', function (cb) { + if (process.platform === 'win32' && fs.existsSync(path.join('resources', 'docker.exe'))) { + cb(); + return; + } + + execFile(path.join('resources', 'docker'), ['-v'], function (err, stdout, stderr) { + var currentVersion = version(stdout); + if (currentVersion && currentVersion === packagejson['docker-version']) { + cb(); + return; } + + gutil.log(gutil.colors.green('Downloading Docker')); + + if(process.platform === 'win32') { + request('https://master.dockerproject.com/windows/amd64/docker-1.7.0-dev.exe').pipe(fs.createWriteStream('./resources/docker.exe')).on('finish', cb); + } else { + request('https://get.docker.com/builds/Darwin/x86_64/docker-' + packagejson['docker-version']) + .pipe(fs.createWriteStream('./resources/docker')).on('finish', function () { + fs.chmodSync('./resources/docker', 755); + cb(); + }); + } + }); +}); + +gulp.task('download-docker-machine', function (cb) { + execFile(path.join('resources', 'docker-machine'), ['-v'], function (err, stdout, stderr) { + var currentVersion = version(stdout); + if (currentVersion && currentVersion === version(packagejson['docker-machine-version'])) { + cb(); + return; + } + + gutil.log(gutil.colors.green('Downloading Docker Machine')); + + if(process.platform === 'win32') { + request('https://github.com/docker/machine/releases/download/v' + packagejson['docker-machine-version'] + '/docker-machine_windows-amd64.exe') + .pipe(fs.createWriteStream('./resources/docker-machine.exe')).on('finish', function () {cb()}); + } else { + request('https://github.com/docker/machine/releases/download/v' + packagejson['docker-machine-version'] + '/docker-machine_darwin-amd64') + .pipe(fs.createWriteStream('./resources/docker-machine')).on('finish', function () { + fs.chmodSync('./resources/docker-machine', 755); + cb(); + }); + } + }); +}); + +gulp.task('download-docker-compose', function (cb) { + execFile(path.join('resources', 'docker-compose'), ['--version'], function (err, stdout, stderr) { + var currentVersion = version(stdout); + if (currentVersion && currentVersion === packagejson['docker-compose-version']) { + cb(); + return; + } + + if(process.platform === 'win32') { + // Todo: install windows version of compose + cb(); + } else { + gutil.log(gutil.colors.green('Downloading Docker Compose')); + request('https://github.com/docker/compose/releases/download/' + packagejson['docker-compose-version'] + '/docker-compose-Darwin-x86_64') + .pipe(fs.createWriteStream('./resources/docker-compose')).on('finish', function () { + fs.chmodSync('./resources/docker-compose', 755); + cb(); + }); + } + }); +}); + +gulp.task('download-boot2docker-iso', function (cb) { + var b2dFile = path.join('resources', 'boot2docker-' + packagejson['docker-version'] + '.iso'); + if (!fs.existsSync(b2dFile)) { + gutil.log(gutil.colors.green('Downloading Boot2Docker iso')); + request('https://github.com/boot2docker/boot2docker/releases/download/v' + packagejson['docker-version'] + '/boot2docker.iso') + .pipe(fs.createWriteStream(b2dFile)).on('finish', cb); + } else { + cb(); + } }); gulp.task('reset', function () { @@ -200,10 +283,10 @@ gulp.task('reset', function () { }); gulp.task('release', function () { - runSequence('download-deps', 'download', 'dist', ['copy', 'images', 'js', 'styles', 'settings'], 'sign', 'zip'); + runSequence('download-docker', 'download-docker-machine', 'download-docker-compose', 'download-boot2docker-iso', 'download', 'dist', ['copy', 'images', 'js', 'styles', 'settings'], 'sign', 'zip'); }); -gulp.task('default', ['download-deps', 'download', 'copy', 'js', 'images', 'styles'], function () { +gulp.task('default', ['download-docker', 'download-docker-machine', 'download-docker-compose', 'download-boot2docker-iso', 'download', 'copy', 'js', 'images', 'styles'], function () { gulp.watch('src/**/*.js', ['js']); gulp.watch('index.html', ['copy']); gulp.watch('styles/**/*.less', ['styles']); diff --git a/index.html b/index.html index 69fafdb727..699c7186f0 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,6 @@