Skip to content

Instantly share code, notes, and snippets.

@carlesandres
Last active December 15, 2015 10:59
Show Gist options
  • Save carlesandres/5249835 to your computer and use it in GitHub Desktop.
Save carlesandres/5249835 to your computer and use it in GitHub Desktop.
Testing Gruntfile configurations for using PHP with Yeoman
'use strict';
//var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;
//var mountFolder = function (connect, dir) {
// return connect.static(require('path').resolve(dir));
//};
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// configurable paths
var yeomanConfig = {
app: 'app',
dist: 'dist'
};
grunt.initConfig({
yeoman: yeomanConfig,
watch: {
coffee: {
files: ['<%= yeoman.app %>/scripts/*.coffee'],
tasks: ['coffee:dist']
},
coffeeTest: {
files: ['test/spec/*.coffee'],
tasks: ['coffee:test']
},
compass: {
files: ['<%= yeoman.app %>/styles/*.{scss,sass}'],
tasks: ['compass']
},
livereload: {
files: [
'<%= yeoman.app %>/*.php',
'{.tmp,<%= yeoman.app %>}/styles/*.css',
'{.tmp,<%= yeoman.app %>}/scripts/*.js',
'<%= yeoman.app %>/images/*.{png,jpg,jpeg}'
],
tasks: ['livereload']
}
},
php: {
options: {
port: 9000
},
test: {
options: {
keepalive: false,
open: true,
base: 'test'
}
},
server: {
options: {
keepalive: true,
base: 'app'
}
}
},
open: {
server: {
url: 'http://localhost:<%= connect.options.port %>'
}
},
clean: {
dist: ['.tmp', '<%= yeoman.dist %>/*'],
server: '.tmp'
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= yeoman.app %>/scripts/main.js',
'<%= yeoman.app %>/scripts/inner/innertools.js',
'test/spec/*.js'
]
},
mocha: {
all: {
options: {
run: true,
urls: ['http://localhost:<%= connect.options.port %>/index.php']
}
}
},
coffee: {
dist: {
files: {
'.tmp/scripts/coffee.js': '<%= yeoman.app %>/scripts/*.coffee'
}
},
test: {
files: [{
expand: true,
cwd: '.tmp/spec',
src: '*.coffee',
dest: 'test/spec'
}]
}
},
compass: {
options: {
sassDir: '<%= yeoman.app %>/styles',
cssDir: '.tmp/styles',
imagesDir: '<%= yeoman.app %>/images',
javascriptsDir: '<%= yeoman.app %>/scripts',
fontsDir: '<%= yeoman.app %>/styles/fonts',
importPath: 'app/components',
relativeAssets: true
},
dist: {},
server: {
options: {
debugInfo: true
}
}
},
// not used since Uglify task does concat,
// but still available if needed
/*concat: {
dist: {}
},*/
uglify: {
dist: {
files: {
'<%= yeoman.dist %>/scripts/main.js': [
'.tmp/scripts/*.js',
'<%= yeoman.app %>/scripts/*.js'
],
'<%= yeoman.dist %>/scripts/inner.js': [
'<%= yeoman.app %>/scripts/inner/*.js'
],
}
}
},
useminPrepare: {
html: '<%= yeoman.app %>/index.php',
options: {
dest: '<%= yeoman.dist %>'
}
},
usemin: {
html: ['<%= yeoman.dist %>/*.php'],
css: ['<%= yeoman.dist %>/styles/*.css'],
options: {
dirs: ['<%= yeoman.dist %>']
}
},
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '*.{png,jpg,jpeg}',
dest: '<%= yeoman.dist %>/images'
}]
}
},
cssmin: {
dist: {
files: {
'<%= yeoman.dist %>/styles/main.css': [
'.tmp/styles/*.css',
'<%= yeoman.app %>/styles/*.css'
]
}
}
},
htmlmin: {
dist: {
options: {
/*removeCommentsFromCDATA: true,
// https://github.com/yeoman/grunt-usemin/issues/44
//collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeOptionalTags: true*/
},
files: [{
expand: true,
cwd: '<%= yeoman.app %>',
src: '*.php',
dest: '<%= yeoman.dist %>'
}]
}
},
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,txt,}',
'images/*.gif',
'.htaccess'
]
},
{
expand: true,
dot: true,
cwd: '',
dest: '<%= yeoman.dist %>',
src: [ 'server/**' ]
}
]
}
},
bower: {
rjsConfig: 'app/scripts/main.js',
indent: ' '
}
});
grunt.renameTask('regarde', 'watch');
// remove when mincss task is renamed
grunt.renameTask('mincss', 'cssmin');
grunt.registerTask('server', function (target) {
if (target === 'dist') {
return grunt.task.run(['open', 'php:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'coffee:dist',
'compass:server',
'livereload-start',
'php:server',
'open',
'watch'
]);
});
grunt.registerTask('test', [
'clean:server',
'coffee',
'compass',
'php:test',
'mocha'
]);
grunt.registerTask('build', [
'clean:dist',
'jshint',
'test',
'coffee',
'compass:dist',
'useminPrepare',
'imagemin',
'cssmin',
'htmlmin',
'concat',
'uglify',
'copy',
'usemin'
]);
grunt.registerTask('default', ['build']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment