refactor complete

This commit is contained in:
Tommy Parnell
2016-03-12 23:20:17 -05:00
parent 28ed26dd29
commit 7c7c6891fd
11 changed files with 152 additions and 36 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@ node_modules
coverage coverage
wixToolset.zip wixToolset.zip
output/ output/
test-tmp/

View File

@@ -1,3 +1,4 @@
//require('babel-core/register');
var gulp = require('gulp'); var gulp = require('gulp');
var unzip = require('gulp-unzip'); var unzip = require('gulp-unzip');
var request = require('request'); var request = require('request');
@@ -5,29 +6,49 @@ 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 tap = require('gulp-tap');
var hydroexec = require('./lib/exec.js'); var coveralls = require('gulp-coveralls');
require('babel-core/register'); var babel = require('gulp-babel');
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'));
}); });
gulp.task('getwix',['download'], function(){ gulp.task('getwix',['download', 'prepublish'], function(){
return gulp.src("wixToolset.zip") return gulp.src("wixToolset.zip")
.pipe(unzip()) .pipe(unzip())
.pipe(gulp.dest('./lib/wixFiles')); .pipe(gulp.dest('./lib/wixFiles'))
.pipe(gulp.dest('./test-tmp/wixFiles'));
}); });
//todo use gulp-istanbul and gulp-mocha gulp.task('pre-test', function () {
gulp.task('test', function(){ return gulp.src('src/**/*.js')
return exec('npm run test'); // Covering files
}) .pipe(istanbul({Instrumenter: isparta.Instrumenter, includeUntested: true}), {read: false})
// Force `require` to return covered files
gulp.task('wixtest', ['getwix'], function(){ .pipe(gulp.dest('test-tmp/'))
return hydroexec({ .pipe(istanbul.hookRequire());
heatFiles: ['test/integration/heat.rsp'],
candleFiles: ['test/integration/candle.rsp'],
lightFiles: ['test/integration/light.rsp']
}); });
gulp.task('test', ['pre-test', 'getwix'], function () {
return gulp.src(['test/**/*.js'])
.pipe(mocha())
// Creating the reports after tests ran
.pipe(istanbul.writeReports())
// Enforce a coverage of at least 90%
.pipe(istanbul.enforceThresholds({ thresholds: { lines: 70 } }));
});
//todo use babel
gulp.task('prepublish', function(){
gulp.src('src/**/*.js')
.pipe(babel({
presets: ['es2015']
}))
.pipe(gulp.dest('lib'));
});
gulp.task('coveralls', ['test'], function(){
gulp.src('coverage/**/lcov.info')
.pipe(coveralls())
}); });

View File

@@ -1,16 +1,15 @@
{ {
"name": "hydrocarbon", "name": "hydrocarbon",
"description": "making windows installers great again", "description": "making windows installers great again",
"version": "0.1.2", "version": "0.3.0",
"main": "index.js", "main": "index.js",
"author": "tparnell8", "author": "tparnell8",
"repository": "tparnell8/HydroCarbon", "repository": "http://github.com/tparnell8/Hydrocarbon",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"compile": "babel src --out-dir lib",
"coveralls": "cat ./coverage/lcov.info | coveralls", "coveralls": "cat ./coverage/lcov.info | coveralls",
"prepublish": "npm run compile", "prepublish": "./node_modules/.bin/gulp getwix",
"test": "./node_modules/.bin/isparta cover node_modules/mocha/bin/_mocha" "test": "./node_modules/.bin/gulp test"
}, },
"dependencies": { "dependencies": {
"child-process-promise": "^1.1.0", "child-process-promise": "^1.1.0",
@@ -26,8 +25,10 @@
"coveralls": "*", "coveralls": "*",
"gulp": "^3.9.1", "gulp": "^3.9.1",
"gulp-babel": "^6.1.2", "gulp-babel": "^6.1.2",
"gulp-coveralls": "^0.1.4",
"gulp-istanbul": "^0.10.3", "gulp-istanbul": "^0.10.3",
"gulp-mocha": "^2.2.0", "gulp-mocha": "^2.2.0",
"gulp-tap": "^0.1.3",
"gulp-unzip": "^0.1.3", "gulp-unzip": "^0.1.3",
"isparta": "^4.0.0", "isparta": "^4.0.0",
"jscover": "^1.0.0", "jscover": "^1.0.0",

View File

@@ -7,7 +7,8 @@ var fs = require('fs'),
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'); Q = require('q'),
processConsole = require('./processConsole.js');
var processError = function(err, cb){ var processError = function(err, cb){
if(cb && _.isFunction(cb) && err){ if(cb && _.isFunction(cb) && err){
@@ -18,21 +19,9 @@ var processError = function(err, cb){
} }
} }
var processConsole = function processConsole(childProcess) {
if(childProcess && childProcess.stdout){
childProcess.stdout.on('data', (data)=>console.log(data.toString()));
}
if(childProcess && childProcess.stderr){
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; var heat = null;
console.log(commands);
//todo redo this a little...
if(commands.heatCommands){ if(commands.heatCommands){
console.log(commands.heatPath, commands.heatCommands); console.log(commands.heatPath, commands.heatCommands);
heat = spawn(commands.heatPath, commands.heatCommands) heat = spawn(commands.heatPath, commands.heatCommands)
@@ -45,7 +34,12 @@ var main = function (options, callback) {
.progress(processConsole) .progress(processConsole)
.then(()=>spawn(commands.lightPath, commands.lightCommands), (err)=>processError(err, callback)) .then(()=>spawn(commands.lightPath, commands.lightCommands), (err)=>processError(err, callback))
.progress(processConsole) .progress(processConsole)
.fail((err)=>processError(err, callback)); .fail((err)=>processError(err, callback))
.then(()=>{
if(callback){
callback();
}
});
}; };
module.exports = main; module.exports = main;

11
src/processConsole.js Normal file
View File

@@ -0,0 +1,11 @@
'use strict'
module.exports = function processConsole(childProcess) {
if(childProcess && childProcess.stdout){
childProcess.stdout.on('data', (data)=>console.log(data.toString()));
}
if(childProcess && childProcess.stderr){
childProcess.stderr.on('data', (data)=>console.log(data.toString()));
}
};

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">
<Product Id="*"
Name="Tommy"
Language="1033"
Version="1.0.0"
Manufacturer="Tommy"
UpgradeCode="{aba1c34e-39c6-47cf-b50a-cae4e77f8204}">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<Media Id="1" Cabinet="product.cab" EmbedCab="yes" />
<!-- Allows our MSI to automatically uninstall any previously installed versions (makes it play nicer with puppet) -->
<Property Id="PREVIOUSVERSIONSINSTALLED" Secure="yes" />
<!-- Upgrade id has to match our upgrade code -->
<Upgrade Id="{aba1c34e-39c6-47cf-b50a-cae4e77f8204}">
<UpgradeVersion
Minimum="0.0.0.1" Maximum="99.0.0.0"
Property="PREVIOUSVERSIONINSTALLED"
IncludeMinimum="yes" IncludeMaximum="no" />
</Upgrade>
<!--
We need to be able to uninstall a newer version from an older version.
The default reinstallmode is "omus", of which the 'o' means "reinstall if missing or older"
The 'd' means "reinstall if different". This ensures that, at the individual component level, rollbacks work correctly.
See http://msdn.microsoft.com/en-us/library/windows/desktop/aa371182(v=vs.85).aspx
-->
<Property Id="REINSTALLMODE" Value="dmus" />
<Feature Id="TommysFiles" Title="TommysFiles">
<ComponentGroupRef Id="files" />
<ComponentRef Id='main' />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Test" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<Component Directory="INSTALLFOLDER" Id="main" Guid="1330738a-9a86-41ed-a0de-68c55318612a"></Component>
</Fragment>
<Fragment>
<InstallExecuteSequence>
<RemoveExistingProducts After="InstallInitialize" />
</InstallExecuteSequence>
</Fragment>
</Wix>

View File

@@ -0,0 +1,5 @@
-dSourceDir=test
-nologo
-out output\test\installers\
test\integration\Product.wsx
output\test\installers\testfiles.gen.wxs

View File

@@ -0,0 +1,7 @@
dir test
-nologo
-cg files
-gg -scom -sreg -sfrag -srd
-dr INSTALLFOLDER
-out output\test\installers\testfiles.gen.wxs
-var var.SourceDir

View File

@@ -0,0 +1,14 @@
var assert = require('chai').assert;
var expect = require('chai').expect;
var hydroexec = require('../../test-tmp/exec');
describe('wix', function(){
it('creates an msi', function(cb){
this.timeout(1000000);
return hydroexec({
heatFiles: ['test/integration/heat.rsp'],
candleFiles: ['test/integration/candle.rsp'],
lightFiles: ['test/integration/light.rsp']
}, cb);
})
});

View File

@@ -0,0 +1,8 @@
-dSourceDir=test
output\test\installers\testfiles.gen.wixobj
output\test\installers\Product.wixobj
-out output\test\installers\Web.msi
-nologo
-sw1076
-sice:ICE80
-sice:ICE18

View File

@@ -1,10 +1,10 @@
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');
describe('CommandBuilderWorks', function(){ describe('CommandBuilderWorks', function(){
var commandBuilder = require('../../test-tmp/CommandBuilder');
it('Should not throw when files are passed in', function(){ it('Should not throw when files are passed in', function(){
var testObject = { var testObject = {
heatFiles: ['tst'], heatFiles: ['tst'],