From 28ed26dd2987d1309476b733187d8f0dcf7e5780 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Sat, 12 Mar 2016 17:49:03 -0500 Subject: [PATCH] heavy refactor --- .gitignore | 2 ++ Gulpfile.js | 62 ++++++++------------------------ README.md | 6 ++++ package.json | 5 ++- src/CommandBuilder.js | 4 +++ src/exec.js | 56 ++++++++++------------------- test/mocha.opts | 2 +- test/unit/CommandBuilder.test.js | 12 ++++++- 8 files changed, 61 insertions(+), 88 deletions(-) diff --git a/.gitignore b/.gitignore index ba2a97b..1a36f14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules coverage +wixToolset.zip +output/ diff --git a/Gulpfile.js b/Gulpfile.js index 7c7dace..e601cbf 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -4,8 +4,10 @@ var request = require('request'); var fs = require('fs'); var mocha = require('gulp-mocha'); var istanbul = require('gulp-istanbul'); -var isparta = require('isparta'); - +var isparta = require('isparta') +var exec = require('child_process').execSync; +var hydroexec = require('./lib/exec.js'); +require('babel-core/register'); gulp.task('download', function () { return request('http://wixtoolset.org/downloads/v3.11.0.129/wix311-binaries.zip').pipe(fs.createWriteStream('wixToolset.zip')); @@ -16,50 +18,16 @@ gulp.task('getwix',['download'], function(){ .pipe(unzip()) .pipe(gulp.dest('./lib/wixFiles')); }); -var paths = { - server: { - scripts: ['src/**/*.js'], - tests: ['test/**/*.js'], - coverage: 'coverage/' - } -}; +//todo use gulp-istanbul and gulp-mocha +gulp.task('test', function(){ + return exec('npm run test'); +}) + +gulp.task('wixtest', ['getwix'], function(){ + return hydroexec({ + heatFiles: ['test/integration/heat.rsp'], + candleFiles: ['test/integration/candle.rsp'], + lightFiles: ['test/integration/light.rsp'] + }); -gulp.task('test-coverage-server', function(cb) { - var coverageDir = paths.server.coverage; - gulp.src(paths.server.scripts) - .pipe(istanbul({ // Covering files - instrumenter: isparta.Instrumenter, - includeUntested: true - })) - .pipe(istanbul.hookRequire()) // Force `require` to return covered files - .on('finish', function() { - gulp.src(paths.server.tests, {read: false}) - .pipe(mocha({reporter: 'spec'})) - .pipe(istanbul.writeReports({ - dir: coverageDir, - reportOpts: {dir: coverageDir}, - reporters: ['text', 'text-summary', 'json', 'html'] - })) - .on('end', cb); - }); -}); - -gulp.task('pre-test', function () { - return gulp.src(['src/CommandBuilder.js']) - // Covering files - .pipe(istanbul({ - // instrumenter: isparta.Instrumenter, - includeUntested: true} - - )) - // Force `require` to return covered files - .pipe(istanbul.hookRequire()); -}); - -gulp.task('test',['pre-test'], function(){ - return gulp.src('test/unit/*.js') - .pipe(mocha()) - .pipe(istanbul.writeReports()); - //.pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } })); - //usemocha }); diff --git a/README.md b/README.md index e172961..9a74f1e 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,12 @@ Default: `undefined` Sets the BUILD_VERSION environment variable to version before calling heat, candle, and light +#### suppressValidation + +Type: `bool` +Default: `false` + +If true this will supress ICE validation checks during the linking process. ## License diff --git a/package.json b/package.json index 94bd6d3..f971e98 100644 --- a/package.json +++ b/package.json @@ -14,15 +14,18 @@ }, "dependencies": { "child-process-promise": "^1.1.0", - "lodash": "^4.6.1" + "lodash": "^4.6.1", + "q": "^1.4.1" }, "devDependencies": { "babel-cli": "*", "babel-core": "^6.6.5", + "babel-preset-es2015": "^6.6.0", "babel-preset-es2015-node4": "*", "chai": "*", "coveralls": "*", "gulp": "^3.9.1", + "gulp-babel": "^6.1.2", "gulp-istanbul": "^0.10.3", "gulp-mocha": "^2.2.0", "gulp-unzip": "^0.1.3", diff --git a/src/CommandBuilder.js b/src/CommandBuilder.js index 3a4c11f..49fa7d7 100644 --- a/src/CommandBuilder.js +++ b/src/CommandBuilder.js @@ -9,6 +9,7 @@ var calculateCommands = function(options){ lightPath: options.lightPath || path.normalize(__dirname + "/wixFiles/light.exe"), candlePath: options.candlePath || path.normalize(__dirname + "/wixFiles/candle.exe") } + if(options.version){ process.env.BUILD_VERSION = version; } @@ -40,6 +41,9 @@ var calculateCommands = function(options){ } commands.lightCommands = _.map(options.lightFiles, (file)=>`@${path.normalize(file)}`) } + if(options.suppressValidation){ + commands.lightCommands.unshift('-sval'); + } return commands; }; diff --git a/src/exec.js b/src/exec.js index 0efba27..389f5fe 100644 --- a/src/exec.js +++ b/src/exec.js @@ -6,66 +6,46 @@ var fs = require('fs'), _ = require('lodash'), path = require('path'), commandBuilder = require('./CommandBuilder.js'), - spawn = require('child-process-promise').spawn; - -var processResults = function (stdout) { - if(stdout && _.isArray(stdout)){ - _.chain(stdout) - .filter((item)=>item && item.length > 0) - .each((item)=>console.log(item)) - .value(); - } - else if(stdout && _.isString(stdout) && stdout.length > 0){ - console.log(stdout); - } - -}; + spawn = require('child-process-promise').spawn, + Q = require('q'); var processError = function(err, cb){ - console.log(err); if(cb && _.isFunction(cb) && err){ cb(err) } else if(err){ - throw err + throw err.message; } } var processConsole = function processConsole(childProcess) { if(childProcess && childProcess.stdout){ - childProcess.stdout.on('data', (data)=>processResults(data.toString())); + childProcess.stdout.on('data', (data)=>console.log(data.toString())); } if(childProcess && childProcess.stderr){ - childProcess.stderr.on('data', (data)=>processResults(data.toString())); + childProcess.stderr.on('data', (data)=>console.log(data.toString())); } }; var main = function (options, callback) { var commands = commandBuilder(options); + var heat = null; + console.log(commands); //todo redo this a little... if(commands.heatCommands){ - return spawn(commands.heatPath, commands.heatCommands) - .progress(processConsole) - .then(()=>spawn(commands.candlePath, commands.candleCommands)) - .progress(processConsole) - .then(()=>spawn(commands.lightPath, commands.lightCommands)) - .progress(processConsole) - .then(()=>{ - if(callback && _.isFunction(callback)){ - callback(); - } - }); + console.log(commands.heatPath, commands.heatCommands); + heat = spawn(commands.heatPath, commands.heatCommands) + .progress(processConsole); } - return spawn(commands.candlePath, commands.candleCommands) - .progress(processConsole) - .then(()=>spawn(commands.lightPath, commands.lightCommands)) - .progress(processConsole) - .then(()=>{ - if(callback && _.isFunction(callback)){ - callback(); - } - }); + heat = heat || Q.Promise(); + + return Q.all([heat]) + .then(()=>spawn(commands.candlePath, commands.candleCommands), (err)=>processError(err, callback)) + .progress(processConsole) + .then(()=>spawn(commands.lightPath, commands.lightCommands), (err)=>processError(err, callback)) + .progress(processConsole) + .fail((err)=>processError(err, callback)); }; module.exports = main; diff --git a/test/mocha.opts b/test/mocha.opts index 916505e..5d4ff46 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,3 +1,3 @@ -./test/unit/**/*.test.js +./test/unit/*.test.js --reporter spec --recursive diff --git a/test/unit/CommandBuilder.test.js b/test/unit/CommandBuilder.test.js index 7400575..539edc1 100644 --- a/test/unit/CommandBuilder.test.js +++ b/test/unit/CommandBuilder.test.js @@ -1,6 +1,6 @@ var assert = require('chai').assert; var expect = require('chai').expect; -var commandBuilder = require('../../src/CommandBuilder.js'); +var commandBuilder = require('../../src/CommandBuilder'); describe('CommandBuilderWorks', function(){ @@ -105,5 +105,15 @@ describe('CommandBuilderWorks', function(){ var result = commandBuilder(testObject); expect(result.lightPath).to.eql("../awesome"); }); + it('should suppress validations', function(){ + var testObject = { + lightCommands: ['lightfile'], + candleCommands: ['candlefile'], + heatCommands: ['heatfile'], + suppressValidation: true + }; + var result = commandBuilder(testObject); + expect(result.lightCommands).to.eql(['-sval', 'lightfile']); + }); });