From 05dc68d6890505ced38a3c71f760c3a7203e475e Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Sun, 5 Jul 2015 20:53:25 -0700 Subject: [PATCH] Download and start Sonarr using gulp (Can work on UI without VS) --- .gitignore | 1 + gulp/gulpFile.js | 3 +- gulp/start.js | 95 ++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 5 ++- 4 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 gulp/start.js diff --git a/.gitignore b/.gitignore index c9ff8e66b..e94e097f6 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,4 @@ output/* #OS X metadata files ._* +_start diff --git a/gulp/gulpFile.js b/gulp/gulpFile.js index 0f90de37d..428fad285 100644 --- a/gulp/gulpFile.js +++ b/gulp/gulpFile.js @@ -8,5 +8,4 @@ require('./less.js'); require('./stripBom.js'); require('./imageMin.js'); require('./webpack.js'); - - +require('./start.js'); diff --git a/gulp/start.js b/gulp/start.js new file mode 100644 index 000000000..e3d5f7b3a --- /dev/null +++ b/gulp/start.js @@ -0,0 +1,95 @@ +// will download and run sonarr (server) in a non-windows enviroment +// you can use this if you don't care about the server code and just want to work +// with the web code. + +var http = require('http'); +var gulp = require('gulp'); +var fs = require('fs'); +var targz = require('tar.gz'); +var del = require('del'); +var print = require('gulp-print'); +var spawn = require('child_process').spawn; + +function download(url, dest, cb) { + console.log('Downloading ' + url + ' to ' + dest); + var file = fs.createWriteStream(dest); + var request = http.get(url, function (response) { + response.pipe(file); + file.on('finish', function () { + console.log('Download completed'); + file.close(cb); + }); + }); +} + +function getLatest(cb) { + var req = http.get('http://services.sonarr.tv/v1/update/develop?os=osx', function (response) { + response.on('data', function (data) { + var updatePackage = JSON.parse(data).updatePackage; + console.log('Latest version avilable: ' + updatePackage.version + ' Release Date: ' + updatePackage.releaseDate); + cb(updatePackage); + }); + }); + req.on('error', function (e) { + console.log('problem with request: ' + e.message); + }); +} + +function extract(source, dest, cb) { + console.log('extracting download page to ' + dest); + new targz().extract(source, dest, function (err) { + if (err) { + console.log(err); + } + console.log('Update package extracted.'); + cb(); + }); +} + +gulp.task('getSonarr', function () { + + //gulp.src('/Users/kayone/git/Sonarr/_start/2.0.0.3288/NzbDrone/*.*') + // .pipe(print()) + // .pipe(gulp.dest('./_output + + //return; + try { + fs.mkdirSync('./_start/'); + } catch (e) { + if (e.code != 'EEXIST') { + throw e; + } + } + + getLatest(function (package) { + var packagePath = "./_start/" + package.filename; + var dirName = "./_start/" + package.version; + download(package.url, packagePath, function () { + extract(packagePath, dirName, function () { + // clean old binaries + console.log('Cleaning old binaries') + del.sync(['./_output/*', '!./_output/UI/']); + console.log('copying binaries to target'); + gulp.src(dirName + '/NzbDrone/*.*') + .pipe(gulp.dest('./_output/')); + }); + }); + }); +}); + +gulp.task('startSonarr', function () { + + var ls = spawn('mono', ['--debug', './_output/NzbDrone.exe']); + + ls.stdout.on('data', function (data) { + process.stdout.write('' + data); + }); + + ls.stderr.on('data', function (data) { + process.stdout.write('' + data); + }); + + ls.on('close', function (code) { + console.log('child process exited with code ' + code); + }); +}); diff --git a/package.json b/package.json index 5dcf6a48c..cc4cfd2ec 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,9 @@ "gulp-jshint": "1.11.2", "gulp-less": "3.0.3", "gulp-print": "1.1.0", - "gulp-replace": "0.5.2", - "gulp-stripbom": "1.0.4", + "gulp-replace": "0.5.3", "gulp-run": "1.6.8", + "gulp-stripbom": "1.0.4", "gulp-webpack": "1.5.0", "gulp-wrap": "0.11.0", "handlebars": "3.0.3", @@ -34,6 +34,7 @@ "jshint-stylish": "2.0.1", "run-sequence": "1.1.1", "streamqueue": "1.1.0", + "tar.gz": "^0.1.1", "webpack": "1.10.1" } }