Created
September 23, 2015 21:09
-
-
Save xavierzwirtz/2327b06e62347d2fbd65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global require */ | |
/* global process */ | |
/* global __dirname */ | |
/* jshint strict: true */ | |
var gulp = require('gulp'); | |
require('gulp-load')(gulp); | |
var merge = require('merge-stream'); | |
var fs = require('fs'); | |
var path = require('path'); | |
var _ = require('lodash'); | |
var argv = require('yargs') | |
.argv; | |
var sass = require('gulp-sass'); | |
var msbuild = require('gulp-msbuild'); | |
var nunit = require('gulp-nunit-runner'); | |
var gulpif = require('gulp-if'); | |
var minifyCSS = require('gulp-minify-css'); | |
var zip = require('gulp-zip'); | |
var ignore = require('gulp-ignore'); | |
var del = require('del'); | |
var vinylPaths = require('vinyl-paths'); | |
var S = require('string'); | |
var jshint = require('gulp-jshint'); | |
var connect = require('gulp-connect'); | |
var runSequence = require('run-sequence'); | |
(function() { | |
'use strict'; | |
var outputResults = require('./scripts/gulp/outputResults.js') | |
.init(['software-test', 'integration-test', 'factory-test', 'web-test', 'serialization-test', 'customization-test']); | |
var production = (function() { | |
var production = argv.production; | |
if (_.isUndefined(production)) { | |
return false; | |
} else { | |
return production === 'true'; | |
} | |
})(); | |
_.each(argv, function(val, key) { | |
var argPrefix = 'config_'; | |
var configPrefix = 'Setting_'; | |
if (S(key) | |
.startsWith(argPrefix)) { | |
var envKey = configPrefix + key.substring(argPrefix.length); | |
console.log('Setting enviroment variable "' + envKey + | |
'" to "' + val + '"'); | |
process.env[envKey] = val; | |
} | |
}); | |
var webDir = 'BirdDogSoftware.WebProjects/BirdDogSoftware.Web/'; | |
var webDeployDir = 'BirdDogSoftware.WebProjects/Deploy/'; | |
var appThemeDir = path.join(webDir,'App_Themes'); | |
var appThemeSelector = path.join(appThemeDir, '**/*.scss'); | |
var themeDir = path.join(webDir, 'Theme'); | |
var jsDir = path.join(webDir, 'js'); | |
var jsStyleSelector = path.join(jsDir, '**/*.scss'); | |
var themeSelector = path.join(themeDir, '**/*.scss'); | |
var makeStylesTask = function(swallowErrors) { | |
var swallow = function(stream) { | |
if(swallowErrors){ | |
stream.on('error', function(err){ | |
stream.emit('end'); | |
console.log(err.message); | |
}); | |
} | |
}; | |
var appThemeSass = sass({ | |
includePaths: [ | |
'bower_components/foundation/scss', | |
themeDir | |
] | |
}); | |
swallow(appThemeSass); | |
var appThemeStream = gulp.src(appThemeSelector) | |
.pipe(appThemeSass) | |
.pipe(gulpif(production, minifyCSS())) | |
.pipe(gulp.dest(appThemeDir)); | |
var jsSass = sass(); | |
swallow(jsSass); | |
var jsStream = gulp.src(jsStyleSelector) | |
.pipe(jsSass) | |
.pipe(gulp.dest(jsDir)); | |
return merge(appThemeStream, jsStream); | |
}; | |
gulp.task('styles', function() { | |
return makeStylesTask(false); | |
}); | |
gulp.task('styles-swallow', function() { | |
return makeStylesTask(true); | |
}); | |
gulp.task('webserver', function() { | |
connect.server({ | |
root: webDir, | |
livereload: false | |
}); | |
}); | |
var tinylr; | |
gulp.task('livereload', function() { | |
tinylr = require('tiny-lr')(); | |
tinylr.listen(35729); | |
}); | |
var notifyLiveReload = function(event) { | |
var fileName = path.relative(__dirname, event.path); | |
tinylr.changed({ | |
body: { | |
files: [fileName] | |
} | |
}); | |
}; | |
gulp.task('watch', ['styles-swallow', 'webserver', 'livereload'], function() { | |
gulp.watch([appThemeSelector, themeSelector, jsStyleSelector], ['styles-swallow']); | |
gulp.watch(path.join(appThemeDir, '**/*.css'), notifyLiveReload); | |
gulp.watch([path.join(jsDir, '/**/*.*'), '!**/*.scss'], notifyLiveReload); | |
gulp.watch(path.join(webDir, 'Areas/**/*.*'), notifyLiveReload); | |
}); | |
gulp.task('copy-foundationJS', function() { | |
return gulp | |
.src('bower_components/foundation/js/**/*.*') | |
.pipe(gulp.dest( | |
'BirdDogSoftware.WebProjects/BirdDogSoftware.Web/scripts/foundation/' | |
)); | |
}); | |
gulp.task('copy-fancytree', function() { | |
return gulp | |
.src('bower_components/fancytree/dist/**/*.*') | |
.pipe(gulp.dest( | |
'BirdDogSoftware.WebProjects/BirdDogSoftware.Web/scripts/fancytree' | |
)); | |
}); | |
gulp.task('copy-libs', ['copy-foundationJS', 'copy-fancytree']); | |
gulp.task('compile-sln', function() { | |
var compileStream = gulp.src('BirdDog.sln') | |
.pipe(msbuild({ | |
errorOnFail: true, | |
configuration: 'Debug', | |
properties: { | |
Configuration: 'Debug', | |
verbosity: 'quiet', | |
WarningLevel: 0, | |
PreBuildEvent: '', | |
DeployOnBuild: 'True', | |
PublishProfile: 'Release' | |
}, | |
verbosity: 'quiet', | |
targets: ['Clean', 'Rebuild'], | |
stdout: true | |
})); | |
return compileStream; | |
}); | |
gulp.task('deploy-web', function() { | |
var custom = gulp | |
.src([path.join(webDir,'CustomExamples') + '/**/*.*', path.join(webDir,'Areas/web.config')]) | |
.pipe(gulp.dest( | |
path.join(webDeployDir, 'CustomExamples/') | |
)); | |
var js = gulp | |
.src(path.join(webDir,'js') + '/**/*.*') | |
.pipe(gulp.dest( | |
path.join(webDeployDir, 'js/') | |
)); | |
return merge(custom, js); | |
}); | |
gulp.task('copy-examples', function() { | |
return gulp | |
.src('BirdDogSoftware.WebProjects/BirdDogSoftware.Web/CustomExamples/**/*.*') | |
.pipe(gulp.dest( | |
'BirdDogSoftware.WebProjects/Deploy/CustomExamples/' | |
)); | |
}); | |
gulp.task('copy-custom-webconfig', function() { | |
return gulp | |
.src('BirdDogSoftware.WebProjects/BirdDogSoftware.Web/Areas/web.config') | |
.pipe(gulp.dest( | |
'BirdDogSoftware.WebProjects/BirdDogSoftware.Web/Custom/' | |
)); | |
}); | |
var runNunit = function(name, dllPath) { | |
console.log('XML: ' + name + '.xml'); | |
var stream = gulp.src(dllPath, { read: false}) | |
.pipe(nunit({ | |
executable: path.join(process.cwd(), '/packages/NUnit.Runners.2.6.3/tools/nunit-console.exe'), | |
options:{ | |
xml: name + '.xml' | |
} | |
})); | |
return outputResults(name, stream); | |
}; | |
gulp.task('integration-test', function() { | |
return runNunit('integration-test', 'BirdDogFrameworkLayer/BirdDogSoftware.IntegrationTest/bin/BirdDogSoftware.IntegrationTest.dll'); | |
}); | |
gulp.task('software-test', function() { | |
return runNunit('software-test', 'BirdDogSoftwareLayer/BirdDogSoftwareTest/bin/BirdDogSoftwareTest.dll'); | |
}); | |
gulp.task('serialization-test', function() { | |
return runNunit('serialization-test', 'BirdDogSoftwareLayer/BirdDogSoftware.SerializationTest/bin/Debug/BirdDogSoftware.Utilities.SerializationTest.dll'); | |
}); | |
gulp.task('customization-test', function() { | |
return runNunit('customization-test', 'BirdDogSoftwareLayer/BirdDogSoftware.CustomizationTest/bin/Debug/BirdDogSoftware.CustomizationTest.dll'); | |
}); | |
gulp.task('factory-test', function() { | |
return runNunit('factory-test', 'BirdDogFrameworkLayer/BirdDogSoftware.FactoryTest/bin/BirdDogSoftware.FactoryTest.dll'); | |
}); | |
gulp.task('web-test', function() { | |
return runNunit('web-test', 'BirdDogSoftware.WebProjects/BirdDogSoftware.WebTest/bin/Debug/BirdDogSoftware.WebTest.dll'); | |
}); | |
gulp.task('cleanup:tests', function() { | |
return gulp.src('*-test.xml') | |
.pipe(vinylPaths(del)); | |
}); | |
gulp.task('deploy-artifacts', function() { | |
var jobmaster = gulp | |
.src('KennelProjects/BirdDogSoftware.JobMaster/bin/**/*.*') | |
.pipe(zip('Jobmaster.zip')) | |
.pipe(gulp.dest(argv.artifact_dir)); | |
var enterprise = gulp | |
.src( | |
'KennelProjects/BirdDogSoftware.Enterprise/bin/Debug/**/*.*' | |
) | |
.pipe(zip('Enterprise.zip')) | |
.pipe(gulp.dest(argv.artifact_dir)); | |
var webDeployDir = 'BirdDogSoftware.WebProjects/Deploy/'; | |
var web = gulp | |
.src([ | |
webDeployDir + '/**/*.*', | |
'!' + webDeployDir + 'App.config', | |
'!' + webDeployDir + 'BirdDog.config', | |
'!' + webDeployDir + 'UserApp.config' | |
]) | |
.pipe(zip('Web.zip')) | |
.pipe(gulp.dest(argv.artifact_dir)); | |
return merge(jobmaster, enterprise, web); | |
}); | |
gulp.task('lint', function() { | |
return gulp.src([ | |
'gulpfile.js', | |
'BirdDogSoftware.WebProjects/BirdDogSoftware.Web/js/**/*.js', | |
'!BirdDogSoftware.WebProjects/BirdDogSoftware.Web/js/lib/**/*.js', | |
'BirdDogSoftware.WebProjects/BirdDogSoftware.Web/Areas/**/*.js', | |
]) | |
.pipe(jshint()) | |
.pipe(jshint.reporter('jshint-stylish')) | |
.pipe(jshint.reporter('fail')); | |
}); | |
(function() { | |
var taskDir = path.join(process.cwd(), '/scripts/tasks/'); | |
fs.readdirSync(taskDir) | |
.forEach(function(file) { | |
if (S(file) | |
.endsWith('.js')) { | |
gulp.loadTasks(taskDir + file); | |
} | |
}); | |
})(); | |
gulp.task('full-build', [ | |
'styles', | |
'copy-custom-webconfig', | |
'copy-libs', | |
'compile-sln', | |
'copy-examples' | |
]); | |
gulp.task('test', [ | |
'software-test', | |
'customization-test', | |
'serialization-test', | |
'integration-test', | |
'factory-test' | |
]); | |
gulp.task('quicktest', [ | |
'software-test', | |
'customization-test', | |
'serialization-test', | |
'lint' | |
]); | |
// gulp.task('test', ['factory-test']); | |
gulp.task('build-installers', | |
['build-enterprise-installer', | |
'build-jobmaster-installer'] | |
); | |
gulp.task('cleanup', [ | |
'cleanup:tests' | |
]); | |
gulp.task('dist-build', function() { | |
return runSequence( | |
'cleanup', | |
'version', | |
'full-build', | |
'build-installers', | |
'deploy-web', | |
'mercurial-tag', | |
'mercurial-push', | |
['deploy-artifacts', 'test'] | |
); | |
}); | |
gulp.task('birddogsoftware.web.prebuild', ['styles', 'copy-custom-webconfig']); | |
gulp.task('default', ['full-build']); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment