Skip to content

Commit

Permalink
Adding build validation
Browse files Browse the repository at this point in the history
- Update gulp tasks to allow setting different destinations
- Add gulp prep-diff
- Add travis.yml for CI
- Add validate.sh for travis to run & diff files to ensure build run before branch merging
- update npm dependencies, lock to specific versions
  • Loading branch information
benjaminapetersen committed Mar 17, 2016
1 parent 93e5658 commit ec6d8b2
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.tmp
node_modules
bower_components
concept
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ language: node_js

before_script:
- npm install -g gulp
# creates ./.tmp/build to test against ./dist
- gulp prep-diff

script: gulp min

# after_script:
# - git status
# Only in ./dist: errors mean the prep-diff task has not run
script: ./validate.sh
4 changes: 2 additions & 2 deletions demo/all/extensions/extension.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
extensionRegistry.add('thing', function(args) {
return [
{
type: 'html',
html: [
type: 'dom',
node: [
'<div>',
args.name.first,
' is an employee.'
Expand Down
2 changes: 1 addition & 1 deletion demo/list-items/extensions/extension.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
text: 'Random: ' + args[(Math.floor(Math.random() * (args.length-1)) + 0)]
}, {
type: 'dom',
dom: $('<div>')
node: $('<div>')
.addClass('outline-red')
.append('<span>')
.text('Hello world')
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-extension-registry.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 66 additions & 40 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@ var gulp = require('gulp'),
concat = require('gulp-concat'),
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),
//rimraf = require('gulp-rimraf'),
del = require('del'),
diff = require('gulp-diff'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
templateCache = require('gulp-angular-templatecache');

var match = {
recurse: '**/*'
};

var src = './src/',
dist = './dist/',
demos = './demo/';
demos = './demo/',
tmp = './.tmp/',
tmpBuild = tmp + 'build/';

var srcAll = src + '**/*',
distAll = dist +'**/*',
demoAll = demos + '**.*';
var srcAll = src + match.recurse,
distAll = dist +match.recurse,
demoAll = demos + match.recurse,
tmpAll = tmpBuild + match.recurse;

var srcJS = src + '/**/*.js',
srcView = src + '/views/**/*.html';
var srcJS = src + match.recurse + '.js',
srcView = src + '/views/'+ match.recurse + '.html';

var outputJS = 'angular-extension-registry.js',
outputTpl = 'compiled-templates.js';
Expand All @@ -38,9 +42,39 @@ var buildSource = [
src + 'directives/extension-renderer.js'
];


var concatSource = function(outputDest) {
return gulp
.src(buildSource)
.pipe(concat(outputJS))
.pipe(filesize())
.pipe(gulp.dest(outputDest || dist));
};

var minifyDist = function(outputDest) {
return gulp
.src(dist + outputJS)
.pipe(uglify().on('error', gutil.log))
.pipe(rename({ extname: '.min.js' }))
.pipe(filesize())
.pipe(gulp.dest(outputDest || dist));
};

var cacheTemplates = function(outputDest) {
return gulp
.src(srcView)
.pipe(templateCache({
module: 'extension-registry'
}))
.pipe(rename(outputTpl))
.pipe(filesize())
.pipe(gulp.dest(outputDest || dist));
};


gulp.task('clean', function() {
return del([dist + '**.*.js'], function(err, paths) {
gutil.log('cleaned files/folders:\n', paths.join('\n'), gutil.colors.green());
return del([distAll, tmpAll], function(err, paths) {
return gutil.log('cleaned files/folders:\n', paths.join('\n'), gutil.colors.green());
});
});

Expand All @@ -51,32 +85,16 @@ gulp.task('jshint', function() {
.pipe(jshint.reporter(stylish));
});

gulp.task('templates', function () {
return gulp
.src(srcView)
.pipe(templateCache({
module: 'extension-registry'
}))
.pipe(rename(outputTpl))
.pipe(filesize())
.pipe(gulp.dest(dist));
gulp.task('templates', ['clean'], function () {
return cacheTemplates();
});

gulp.task('build', ['clean','templates', 'jshint'], function () {
return gulp
.src(buildSource)
.pipe(concat(outputJS))
.pipe(filesize())
.pipe(gulp.dest(dist));
return concatSource();
});

gulp.task('min', ['build', 'templates'], function() {
return gulp
.src(dist + outputJS)
.pipe(uglify().on('error', gutil.log))
.pipe(rename({ extname: '.min.js' }))
.pipe(filesize())
.pipe(gulp.dest(dist));
return minifyDist();
});

gulp.task('serve', function() {
Expand All @@ -91,16 +109,24 @@ gulp.task('serve', function() {
});


// initial stub in of a gulp task to check diff
gulp.task('verify', function() {
// TODO: will have to go all the way to src, not the semi-built,
// to be confident that there is no diff. How to do via gulp
// w/o having a task that is just a repeat of all other tasks?
// return gulp
// .src(dist + outputJS)
// .pipe(uglify())
// .pipe(diff(dist + 'angular-extension-registry.js'))
// .pipe(diff.reporter({fail: true}));
gulp.task('_tmp-build', function() {
return concatSource(tmpBuild);
});
gulp.task('_tmp-templates', function() {
return cacheTemplates(tmpBuild);
});

gulp.task('_tmp-min', ['_tmp-build', '_tmp-templates'], function() {
return minifyDist(tmpBuild);
});


// at present this task exists for travis to use to before
// running ./validate.sh to diff our dist against ./.tmp/build
// and validate that templates have been cached, js minified, etc.
gulp.task('prep-diff', ['_tmp-min'], function() {
// nothing here atm.
});


gulp.task('default', ['min', 'serve']);
34 changes: 19 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-extension-registry",
"version": "1.1.3",
"description": "An angular module allowing arbitrary data to be injected & rendered in UI",
"description": "An angular module allowing a developer to define extension points in an application allowing others to easily extend a UI through a simple interface",
"authors": [
"benjaminapetersen <admin@benjaminapetersen.me>"
],
Expand All @@ -14,28 +14,32 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/benjaminapetersen/angular-extension-registry.git"
"url": "git+https://github.com/openshift/angular-extension-registry.git"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/benjaminapetersen/angular-extension-registry/issues"
"url": "https://github.com/openshift/angular-extension-registry/issues"
},
"homepage": "https://github.com/benjaminapetersen/angular-extension-registry#readme",
"homepage": "https://github.com/openshift/angular-extension-registry#readme",
"devDependencies": {
"browser-sync": "^2.11.1",
"del": "^1.2.0",
"gulp": "^3.9.0",
"gulp-angular-templatecache": "^1.7.0",
"gulp-concat": "^2.6.0",
"gulp-diff": "^1.0.0",
"gulp": "3.9.0",
"gulp-angular-templatecache": "1.7.0",
"gulp-concat": "2.6.0",
"gulp-conflict": "0.4.0",
"gulp-debug": "2.1.2",
"gulp-diff": "1.0.0",
"gulp-filesize": "0.0.6",
"gulp-jshint": "^1.11.2",
"gulp-if": "2.0.0",
"gulp-jshint": "1.11.2",
"gulp-remove-empty-lines": "0.0.2",
"gulp-rename": "^1.2.2",
"gulp-rimraf": "^0.1.1",
"gulp-strip-comments": "^1.0.1",
"gulp-uglify": "^1.2.0",
"gulp-util": "^3.0.6",
"jshint-stylish": "^2.0.1"
"gulp-rename": "1.2.2",
"gulp-rimraf": "0.1.1",
"gulp-strip-comments": "1.0.1",
"gulp-uglify": "1.5.3",
"gulp-util": "3.0.6",
"jshint-stylish": "2.0.1",
"yargs": "4.2.0"
}
}
16 changes: 16 additions & 0 deletions validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`

echo 'Validating build'
# options tried:
# -uB --ignore-blank-lines --ignore-space-change --strip-trailing-cr
if ! assetdiff=$(diff -uB --ignore-blank-lines --ignore-space-change --strip-trailing-cr ./.tmp/build ./dist) ; then
echo "${red}[ERROR] There is a diff that needs to be resolved (run gulp min) ${reset}"
echo "$assetdiff"
exit 1
else
echo "${green}[SUCCESS] No diff ${reset}"
exit 0
fi

0 comments on commit ec6d8b2

Please sign in to comment.