diff --git a/.gitignore b/.gitignore index 3da2b49..3c3629e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ node_modules -wixFiles diff --git a/Gulpfile.js b/Gulpfile.js new file mode 100644 index 0000000..bed0da0 --- /dev/null +++ b/Gulpfile.js @@ -0,0 +1,13 @@ +var gulp = require('gulp'); +var unzip = require('gulp-unzip'); +var request = require('request'); +var fs = require('fs'); +gulp.task('download', function () { + return request('http://wixtoolset.org/downloads/v3.11.0.129/wix311-binaries.zip').pipe(fs.createWriteStream('wixToolset.zip')); +}); + +gulp.task('getwix',['download'], function(){ + return gulp.src("wixToolset.zip") + .pipe(unzip()) + .pipe(gulp.dest('./wixFiles')); +}); diff --git a/README.md b/README.md index a04d900..456aa79 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # HydroCarbon +simple wrapper over wix. You can see a working demo [here](https://github.com/tparnell8/GulpBuildForDotNet) diff --git a/app.js b/app.js index 0955ea1..e29dc02 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,4 @@ module.exports = { exec: require('./exec.js'), - generator: require('../generator.js') -} \ No newline at end of file + generator: require('./generator.js') +} diff --git a/exec.js b/exec.js index 8e3d7a0..f0834a0 100644 --- a/exec.js +++ b/exec.js @@ -4,9 +4,15 @@ 'use strict'; var fs = require('fs'), when = require('when'), + nodefn = require('when/node'), _ = require('underscore'), path = require('path'), child_process = require('child_process'); +var logger = function(log){ + if(log){ + console.log(log); + } +} var main = function (options) { var heatFiles = options.heatFiles; var candleFiles = options.candleFiles; @@ -14,14 +20,19 @@ var main = function (options) { var heatCommands = options.heatCommands || null; var candleCommands = options.candleCommands || null; var lightCommands = options.lightCommands || null; - var heatPath = options.heatPath || path.normalize(__dirname + "/heat.exe"); - var lightPath = options.lightPath || path.normalize(__dirname + "/light.exe"); - var candlePath = options.candlePath || path.normalize(__dirname + "/candle.exe"); + var heatPath = options.heatPath || __dirname + "/wixFiles/heat.exe"; + var lightPath = options.lightPath || __dirname + "/wixFiles/light.exe"; + var candlePath = options.candlePath || __dirname + "/wixFiles/candle.exe"; + var cb = options.callback || function(){}; + var version = options.version; + if(version){ + process.env.BUILD_VERSION = version; + } if(!heatCommands){ if(!heatFiles || !_.isArray(heatFiles) || heatFiles.length < 1 ){ throw "heat files are required if no commands are passed"; } - checkFiles(heatFiles); + // checkFiles(heatFiles); } if(!candleCommands){ @@ -30,7 +41,7 @@ var main = function (options) { throw "candle files are required"; } - checkFiles(candleCommands); + //checkFiles(candleCommands); } @@ -40,11 +51,57 @@ var main = function (options) { throw "light files are required"; } - checkFiles(lightFiles); + //checkFiles(lightFiles); } - child_process.execFileSync(heatPath, heatCommands? heatCommands: _.map(heatFiles, (file)=>`@${path.normalize(file)}`)); + child_process.execFile(path.normalize(heatPath), heatCommands? heatCommands: _.map(heatFiles, (file)=>`@${path.normalize(file)}`), (err, stdout, stderr)=>{ + logger(stdout); + logger(stderr); + if(err){ + throw err; + } + + child_process.execFile(path.normalize(candlePath), candleCommands? candleCommands: _.map(candleFiles, (file)=>`@${path.normalize(file)}`), (err, stdout, stderr)=>{ + logger(stdout); + logger(stderr); + if(err){ + throw err; + } + + child_process.execFile(path.normalize(lightPath), lightCommands? lightCommands: _.map(lightFiles, (file)=>`@${path.normalize(file)}`), (err, stdout, stderr)=>{ + logger(stdout); + logger(stderr); + if(err){ + throw err; + } + + }); + + }); + + }); + //todo: figure out how to use promises while capturing stderr on the catch + /* + var liftedChild = nodefn.lift(child_process.execFile); + liftedChild(heatPath, heatCommands? heatCommands: _.map(heatFiles, (file)=>`@${path.normalize(file)}`)) + .then((stdin, stderror)=>{ + console.log(stdin); + console.log(stderror); + return liftedChild(candlePath, candleCommands? candleCommands: _.map(candleFiles, (file)=>`@${path.normalize(file)}`)); + }) + + .then((stdin, stderror)=>{ + console.log(stdin); + console.log(stderror); + return liftedChild(lightPath, lightCommands? lightCommands: _.map(lightFiles, (file)=>`@${path.normalize(file)}`)); + }) + .catch((a,b,c)=>{ + console.log(a); + console.log(b); + console.log(c); + })*/ }; + var checkFiles = function(files){ _.each(files, (file)=>{ if(!checkFile(file)){ @@ -57,10 +114,12 @@ var checkFile = function (file) { return false; } try { - fs.access(file, fs.R_OK); //will error if doesnt exist + fs.access(path.normalize(file), fs.R_OK); //will error if doesnt exist //todo async? return true; } catch (error) { return false; } }; + +module.exports = main; diff --git a/package.json b/package.json index 750822d..8ba8708 100644 --- a/package.json +++ b/package.json @@ -10,5 +10,10 @@ "dependencies": { "underscore": "^1.8.3", "when": "^3.7.7" + }, + "devDependencies": { + "gulp": "^3.9.1", + "gulp-unzip": "^0.1.3", + "request": "^2.69.0" } }