heavy refactor

This commit is contained in:
Tommy Parnell
2016-03-12 17:49:03 -05:00
parent e2ad38a581
commit 28ed26dd29
8 changed files with 61 additions and 88 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,4 @@
node_modules node_modules
coverage coverage
wixToolset.zip
output/

View File

@@ -4,8 +4,10 @@ var request = require('request');
var fs = require('fs'); var fs = require('fs');
var mocha = require('gulp-mocha'); var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul'); 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 () { gulp.task('download', function () {
return request('http://wixtoolset.org/downloads/v3.11.0.129/wix311-binaries.zip').pipe(fs.createWriteStream('wixToolset.zip')); 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(unzip())
.pipe(gulp.dest('./lib/wixFiles')); .pipe(gulp.dest('./lib/wixFiles'));
}); });
var paths = { //todo use gulp-istanbul and gulp-mocha
server: { gulp.task('test', function(){
scripts: ['src/**/*.js'], return exec('npm run test');
tests: ['test/**/*.js'], })
coverage: 'coverage/'
} 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
}); });

View File

@@ -80,6 +80,12 @@ Default: `undefined`
Sets the BUILD_VERSION environment variable to version before calling heat, candle, and light 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 ## License

View File

@@ -14,15 +14,18 @@
}, },
"dependencies": { "dependencies": {
"child-process-promise": "^1.1.0", "child-process-promise": "^1.1.0",
"lodash": "^4.6.1" "lodash": "^4.6.1",
"q": "^1.4.1"
}, },
"devDependencies": { "devDependencies": {
"babel-cli": "*", "babel-cli": "*",
"babel-core": "^6.6.5", "babel-core": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"babel-preset-es2015-node4": "*", "babel-preset-es2015-node4": "*",
"chai": "*", "chai": "*",
"coveralls": "*", "coveralls": "*",
"gulp": "^3.9.1", "gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-istanbul": "^0.10.3", "gulp-istanbul": "^0.10.3",
"gulp-mocha": "^2.2.0", "gulp-mocha": "^2.2.0",
"gulp-unzip": "^0.1.3", "gulp-unzip": "^0.1.3",

View File

@@ -9,6 +9,7 @@ var calculateCommands = function(options){
lightPath: options.lightPath || path.normalize(__dirname + "/wixFiles/light.exe"), lightPath: options.lightPath || path.normalize(__dirname + "/wixFiles/light.exe"),
candlePath: options.candlePath || path.normalize(__dirname + "/wixFiles/candle.exe") candlePath: options.candlePath || path.normalize(__dirname + "/wixFiles/candle.exe")
} }
if(options.version){ if(options.version){
process.env.BUILD_VERSION = version; process.env.BUILD_VERSION = version;
} }
@@ -40,6 +41,9 @@ var calculateCommands = function(options){
} }
commands.lightCommands = _.map(options.lightFiles, (file)=>`@${path.normalize(file)}`) commands.lightCommands = _.map(options.lightFiles, (file)=>`@${path.normalize(file)}`)
} }
if(options.suppressValidation){
commands.lightCommands.unshift('-sval');
}
return commands; return commands;
}; };

View File

@@ -6,66 +6,46 @@ var fs = require('fs'),
_ = require('lodash'), _ = require('lodash'),
path = require('path'), path = require('path'),
commandBuilder = require('./CommandBuilder.js'), commandBuilder = require('./CommandBuilder.js'),
spawn = require('child-process-promise').spawn; spawn = require('child-process-promise').spawn,
Q = require('q');
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);
}
};
var processError = function(err, cb){ var processError = function(err, cb){
console.log(err);
if(cb && _.isFunction(cb) && err){ if(cb && _.isFunction(cb) && err){
cb(err) cb(err)
} }
else if(err){ else if(err){
throw err throw err.message;
} }
} }
var processConsole = function processConsole(childProcess) { var processConsole = function processConsole(childProcess) {
if(childProcess && childProcess.stdout){ 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){ 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 main = function (options, callback) {
var commands = commandBuilder(options); var commands = commandBuilder(options);
var heat = null;
console.log(commands);
//todo redo this a little... //todo redo this a little...
if(commands.heatCommands){ if(commands.heatCommands){
return spawn(commands.heatPath, commands.heatCommands) console.log(commands.heatPath, commands.heatCommands);
.progress(processConsole) heat = spawn(commands.heatPath, commands.heatCommands)
.then(()=>spawn(commands.candlePath, commands.candleCommands)) .progress(processConsole);
.progress(processConsole)
.then(()=>spawn(commands.lightPath, commands.lightCommands))
.progress(processConsole)
.then(()=>{
if(callback && _.isFunction(callback)){
callback();
}
});
} }
return spawn(commands.candlePath, commands.candleCommands) heat = heat || Q.Promise();
.progress(processConsole)
.then(()=>spawn(commands.lightPath, commands.lightCommands)) return Q.all([heat])
.progress(processConsole) .then(()=>spawn(commands.candlePath, commands.candleCommands), (err)=>processError(err, callback))
.then(()=>{ .progress(processConsole)
if(callback && _.isFunction(callback)){ .then(()=>spawn(commands.lightPath, commands.lightCommands), (err)=>processError(err, callback))
callback(); .progress(processConsole)
} .fail((err)=>processError(err, callback));
});
}; };
module.exports = main; module.exports = main;

View File

@@ -1,3 +1,3 @@
./test/unit/**/*.test.js ./test/unit/*.test.js
--reporter spec --reporter spec
--recursive --recursive

View File

@@ -1,6 +1,6 @@
var assert = require('chai').assert; var assert = require('chai').assert;
var expect = require('chai').expect; var expect = require('chai').expect;
var commandBuilder = require('../../src/CommandBuilder.js'); var commandBuilder = require('../../src/CommandBuilder');
describe('CommandBuilderWorks', function(){ describe('CommandBuilderWorks', function(){
@@ -105,5 +105,15 @@ describe('CommandBuilderWorks', function(){
var result = commandBuilder(testObject); var result = commandBuilder(testObject);
expect(result.lightPath).to.eql("../awesome"); 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']);
});
}); });