Skip to content

Commit

Permalink
Added the update examples task and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentGoderre committed Oct 20, 2014
1 parent ed68eae commit 8d3ddc6
Show file tree
Hide file tree
Showing 9 changed files with 485 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ node_modules

# Users Environment Variables
.lock-wscript

# Test results
test/actual
62 changes: 62 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"predef": [
"console",
"describe",
"it",
"after",
"afterEach",
"before",
"beforeEach"
],

"indent": 4,
"node": true,
"devel": true,

"bitwise": false,
"curly": false,
"eqeqeq": true,
"forin": false,
"immed": true,
"latedef": false,
"newcap": true,
"noarg": true,
"noempty": false,
"nonew": true,
"plusplus": false,
"regexp": false,
"undef": true,
"unused": "vars",
"quotmark": "single",
"strict": false,
"trailing": true,
"camelcase": true,

"asi": false,
"boss": true,
"debug": false,
"eqnull": true,
"es5": false,
"esnext": false,
"evil": false,
"expr": false,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": true,
"laxcomma": false,
"loopfunc": true,
"multistr": false,
"onecase": true,
"regexdash": false,
"scripturl": false,
"smarttabs": false,
"shadow": false,
"sub": false,
"supernew": true,
"validthis": false,

"nomen": false,
"white": true
}
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js
node_js:
- '0.10'

before_install:
- npm instal -g grunt-cli

script:
- grunt travis
38 changes: 38 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt, {
pattern: ['grunt-*', '!grunt-run-task']
});

grunt.initConfig({
jshint: {
options: {
jshintrc: '.jshintrc'
},
files: [
'Gruntfile.js',
'tasks/**/*.js',
'test/**/*.js',
]
},
simplemocha: {
options: {
reporter: 'spec',
timeout: '5000'
},
full: {
src: ['test/test.js']
},
short: {
options: {
reporter: 'dot'
},
src: ['test/test.js']
}
}
});

grunt.registerTask('test', ['jshint','simplemocha:full']);
grunt.registerTask('travis', ['test']);
grunt.registerTask('default', 'test');
};
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Web Experience Toolkit (WET) Post Build Grunt Module

[![Build Status](https://secure.travis-ci.org/wet-boew/grunt-wet-boew-postbuild.svg?branch=master)](http://travis-ci.org/wet-boew/grunt-wet-boew-postbuild)
[![dependency Status](https://david-dm.org/wet-boew/grunt-wet-boew-postbuild/status.svg)](https://david-dm.org/wet-boew/grunt-wet-boew-postbuild)
[![devDependency Status](https://david-dm.org/wet-boew/grunt-wet-boew-postbuild/dev-status.svg)](https://david-dm.org/wet-boew/grunt-wet-boew-postbuild#info=devDependencies)

This module performs various post build task in Continuous Intergration environment.

## Install

```sh
$ npm install grunt-wet-boew-postbuild --save-dev
```

wet-boew-postbuild depends on nodejs, grunt and git
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "grunt-wet-boew-postbuild",
"version": "0.0.0",
"description": "Grunt post build tasks for the Web Experience Toolkit",
"scripts": {
"test": "grunt test"
},
"repository": {
"type": "git",
"url": "https://github.com/wet-boew/grunt-wet-boew-postbuild.git"
},
"author": "Laurent Goderre <[email protected]> (http://github.com/LaurentGoderre)",
"license": "MIT",
"bugs": {
"url": "https://github.com/wet-boew/grunt-wet-boew-postbuild/issues"
},
"homepage": "https://github.com/wet-boew/grunt-wet-boew-postbuild",
"dependencies": {
"node-git-simple": "wet-boew/node-git-simple#v0.1.1"
},
"devDependencies": {
"expect.js": "^0.3.1",
"grunt": "^0.4.5",
"grunt-contrib-jshint": "^0.10.0",
"grunt-simple-mocha": "^0.4.0",
"grunt-run-task": "0.1.0-rc8",
"load-grunt-tasks": "^0.6.0",
"mocha": "^1.21.4",
"rimraf": "^2.2.8"
},
"peerDependencies": {
"grunt": "~0.4.0"
},
"files": [
"tasks"
]
}
69 changes: 69 additions & 0 deletions tasks/updateexamples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
var Git = require('node-git-simple');

module.exports = function(grunt) {

var callback, silent;

function errorLog(error) {
if (!silent) {
callback(error);
} else {
callback('Unspecified error (run without silent option for detail)');
}
}

function updateExample(repo, options, done) {
var branch = options.branch || 'gh-pages',
oldBranch;

repo.exec('branch')
.then(function(repo) {
oldBranch = repo.lastCommand.stdout.match(/\*\s*([^\n]*)/)[1];
return repo.exec('checkout', branch);
}, errorLog)
.then(function(repo) {
return repo.exec('submodule', 'update', '--remote', '--init');
}, errorLog)
.then(function(repo){
return repo.exec('add', '.');
}, errorLog)
.then(function(repo){
return repo.exec('commit', '-m', options.message);
}, errorLog)
.then(function(repo){
return repo.exec('push', 'origin', branch);
}, errorLog)
.then(function() {
return repo.exec('checkout', oldBranch);
})
.then(function(){
done();
});

}

grunt.registerMultiTask('wb-update-examples', 'Update working examples', function () {
var options = this.options(),
done;

if (!options.message){
return grunt.fail.warn('Mandatory option \'message\' not found.');
}

done = this.async();
callback = done;

silent = options.slient;

if (options.repo) {
Git.clone(process.cwd(), options.repo)
.then(function(repo) {
return updateExample(repo, options, done);
}, function(err) {
done(err);
});
} else {
return updateExample(new Git(process.cwd()), options, done);
}
});
};
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var fs = require('fs');
var rimraf = require('rimraf');

var actual = './test/actual';

require('./updateexamples');

before(function() {
fs.mkdirSync(actual);
});

after(function(){
rimraf.sync(actual);
});
Loading

0 comments on commit 8d3ddc6

Please sign in to comment.