Skip to content

Commit

Permalink
Adding in enhanced grunt config and release process
Browse files Browse the repository at this point in the history
 - Added JSHint and updated syntax to pass
 - Added in Karma Runner using Jasmine, Browserify, and PhantomJS
 - Fixed examples to work under HTTPS
 - Added in Grunt Prompt release process that uses grunt-bump
 - Added in watch task to quickly run tests when a file is updated
  • Loading branch information
Cody Lundquist committed Jul 16, 2014
1 parent 2b7588b commit 977e5d8
Show file tree
Hide file tree
Showing 17 changed files with 294 additions and 51 deletions.
34 changes: 3 additions & 31 deletions Gruntfile.js
@@ -1,34 +1,6 @@
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
options: {
bundleOptions: {
standalone: '<%= pkg.name %>'
}
},
build: {
src: 'src/main.js',
dest: 'dist/band.js'
}
},
uglify: {
options: {
compress: true,
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'dist/band.js',
dest: 'dist/band.min.js'
}
}
require('time-grunt')(grunt);
require('load-grunt-config')(grunt, {
jitGrunt: true
});

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-browserify');

// Default task(s).
grunt.registerTask('default', ['browserify', 'uglify']);
};
2 changes: 1 addition & 1 deletion examples/json-load/index.html
Expand Up @@ -6,7 +6,7 @@
<title>Loading JSON Example</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
<link href="app.css" rel="stylesheet">
<script src="http://code.angularjs.org/1.2.0rc1/angular.min.js"></script>
<script src="//code.angularjs.org/1.2.0rc1/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.5.0/ui-bootstrap-tpls.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.1.0/moment.min.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion examples/mario-bros-overworld/index.html
Expand Up @@ -6,7 +6,7 @@
<title>Super Mario Bros Overworld</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
<link href="app.css" rel="stylesheet">
<script src="http://code.angularjs.org/1.2.0rc1/angular.min.js"></script>
<script src="//code.angularjs.org/1.2.0rc1/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.5.0/ui-bootstrap-tpls.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.1.0/moment.min.js"></script>

Expand Down
28 changes: 28 additions & 0 deletions grunt/.jshintrc
@@ -0,0 +1,28 @@
{
"browser": true,
"curly": true,
"eqnull": true,
"immed": true,
"jquery": false,
"newcap": true,
"noarg": true,
"smarttabs": true,
"sub": true,
"undef": true,
"unused": true,
"globals": {
"require": true,
"it": true,
"iit": true,
"xit": true,
"describe": true,
"ddescribe": true,
"xdescribe": true,
"expect": true,
"beforeEach": true,
"module": true,
"spyOn": true,
"afterEach": true,
"console": true
}
}
22 changes: 22 additions & 0 deletions grunt/aliases.yaml
@@ -0,0 +1,22 @@
---
default:
- "deploy"

deploy:
- "test"
- "clean:dist"
- "browserify:deploy"
- "uglify:deploy"

release:
- "checkbranch:master"
- "prompt:deploy"

test:
- "jshint"
- "karma:once"

run:
- "test"
- "karma:watch"
- "watch"
11 changes: 11 additions & 0 deletions grunt/browserify.js
@@ -0,0 +1,11 @@
module.exports = {
"options": {
"bundleOptions": {
"standalone": '<%= package.name %>'
}
},
"deploy": {
"src": 'src/main.js',
"dest": 'dist/band.js'
}
};
13 changes: 13 additions & 0 deletions grunt/bump.js
@@ -0,0 +1,13 @@
module.exports = {
options: {
files: ['bower.json', 'package.json'],
commit: false,
commitMessage: 'Releasing: %VERSION%',
commitFiles: ['dist/', 'bower.json', 'package.json'],
createTag: false,
tagName: '%VERSION%',
tagMessage: 'Version %VERSION%',
push: false,
pushTo: 'origin master:master'
}
};
5 changes: 5 additions & 0 deletions grunt/clean.js
@@ -0,0 +1,5 @@
// Clean generated asset files
module.exports = {
"dist": ["dist"],
"build": ["build"]
};
6 changes: 6 additions & 0 deletions grunt/jshint.js
@@ -0,0 +1,6 @@
module.exports = {
options: {
jshintrc: 'grunt/.jshintrc'
},
all: ['src/**/*.js']
};
47 changes: 47 additions & 0 deletions grunt/karma.js
@@ -0,0 +1,47 @@
module.exports = {
// Run Unit Tests Once
"once": {
"options": {
"port": 9018,
"runnerPort": 9100,
"singleRun": true,
"background": false
}
},
// Used during watch. It just sets up the server and then watch calls 'karma:watch:run' to fire off tests.
"watch": {
"options": {
"port": 9118,
"runnerPort": 9200,
"singleRun": false,
"background": true
}
},
"options": {
"files": [
"test/*.js"
],
"frameworks": [
"jasmine",
"browserify"
],
"plugins": [
"karma-jasmine",
"karma-phantomjs-launcher",
"karma-browserify"
],
"browserify": {
"watch": true
},
preprocessors: {
"test/*.js": ["browserify"]
},
"reporters": "dots",
"urlRoot": "/",
"autoWatch": false,
"logLevel": "ERROR",
"browsers": [
"PhantomJS"
]
}
};
93 changes: 93 additions & 0 deletions grunt/prompt.js
@@ -0,0 +1,93 @@
module.exports = function(grunt) {
var semver = require('semver'),
currentVersion = require('../package.json').version;
return {
deploy: {
options: {
questions: [
{
config: 'bump.version-type',
type: 'list',
message: 'Bump version from ' + '<%= package.version %>'.cyan + ' to:',
choices: [
{
value: 'patch',
name: 'Patch: '.yellow + semver.inc(currentVersion, 'patch').yellow +
' Backwards-compatible bug fixes.'
},
{
value: 'minor',
name: 'Minor: '.yellow + semver.inc(currentVersion, 'minor').yellow +
' Adding new features but still backwards-compatible.'
},
{
value: 'major',
name: 'Major: '.yellow + semver.inc(currentVersion, 'major').yellow +
' Incompatible API changes.'
},
{
value: 'custom',
name: 'Custom: ?.?.?'.yellow +
' Specify version...'
}
]
},
{
config: 'bump.custom-version',
type: 'input',
message: 'What specific version would you like',
when: function(answers) {
return answers['bump.version-type'] === 'custom';
},
validate: function(value) {
var valid = semver.valid(value) && true;
return valid || 'Must be a valid semver, such as 1.2.3';
}
},
{
config: 'bump.options.commit',
type: 'confirm',
message: 'Do you want to commit the ./dist, bower.json, and package.json files?'
},
{
config: 'bump.options.createTag',
type: 'confirm',
message: 'Do you want to tag this release?',
when: function(answers) {
return answers['bump.options.commit']
}
},
{
config: 'bump.options.push',
type: 'confirm',
message: 'Do you want to push the new release?',
when: function(answers) {
return answers['bump.options.commit'] && answers['bump.options.createTag']
}
},
{
config: 'bump.options.pushTo',
type: 'input',
message: 'Where would you like to push to?',
default: 'origin master:master',
when: function(answers) {
return answers['bump.options.push']
}
}
],
then: function(results) {
var versionType = results['bump.version-type'],
bumpTask = 'bump';

if ('custom' === versionType) {
grunt.option('setversion', results['bump.custom-version']);
} else {
bumpTask += ':' + versionType;
}

grunt.task.run(['deploy', bumpTask]);
}
}
}
};
};
10 changes: 10 additions & 0 deletions grunt/uglify.js
@@ -0,0 +1,10 @@
module.exports = {
"options": {
"compress": true,
"banner": '/*! <%= package.name %> - v<%= package.version %> - <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
"deploy": {
"src": 'dist/band.js',
"dest": 'dist/band.min.js'
}
};
8 changes: 8 additions & 0 deletions grunt/watch.js
@@ -0,0 +1,8 @@
module.exports = {
"build": {
"files": ["src/**/*.js", "test/*.js"],
"tasks": [
"karma:watch:run"
]
}
};
17 changes: 16 additions & 1 deletion package.json
Expand Up @@ -11,8 +11,23 @@
"license": "MIT",
"devDependencies": {
"audiocontext": "0.1.0",
"browserify": "^4.2.1",
"grunt": "0.4.1",
"grunt-browserify": "2.1.3",
"grunt-contrib-uglify": "0.2.2"
"grunt-bump": "0.0.14",
"grunt-checkbranch": "^0.3.1",
"grunt-contrib-clean": "^0.5.0",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-uglify": "0.2.2",
"grunt-contrib-watch": "^0.6.1",
"grunt-karma": "^0.8.3",
"grunt-prompt": "^1.1.0",
"karma": "^0.12.17",
"karma-browserify": "^0.2.1",
"karma-jasmine": "^0.1.5",
"karma-phantomjs-launcher": "^0.1.4",
"load-grunt-config": "^0.12.0",
"semver": "^2.3.1",
"time-grunt": "^0.4.0"
}
}

0 comments on commit 977e5d8

Please sign in to comment.