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
coverage
wixToolset.zip
output/

View File

@@ -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('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('wixtest', ['getwix'], function(){
return hydroexec({
heatFiles: ['test/integration/heat.rsp'],
candleFiles: ['test/integration/candle.rsp'],
lightFiles: ['test/integration/light.rsp']
});
});
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
#### suppressValidation
Type: `bool`
Default: `false`
If true this will supress ICE validation checks during the linking process.
## License

View File

@@ -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",

View File

@@ -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;
};

View File

@@ -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)
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))
.then(()=>spawn(commands.lightPath, commands.lightCommands), (err)=>processError(err, callback))
.progress(processConsole)
.then(()=>{
if(callback && _.isFunction(callback)){
callback();
}
});
.fail((err)=>processError(err, callback));
};
module.exports = main;

View File

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

View File

@@ -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']);
});
});