grunt-init-assemble
Version:
Initialize new Assemble projects.
149 lines (126 loc) • 4.84 kB
JavaScript
/*
* {%= name %}
* https://github.com/{%= author_name %}/{%= name %}
* Copyright (c) {%= grunt.template.today('yyyy') %}
* Licensed under the {%= licenses.join(', ') %} license{%= licenses.length === 1 ? '' : 's' %}.
*/
module.exports = function(grunt) {
;
// Delete after first run
if(!grunt.file.exists('vendor/bootstrap')) {
grunt.fail.fatal('>> Please run "bower install" before continuing.');
}
// Project configuration.
grunt.initConfig({
// Project metadata
pkg : grunt.file.readJSON('package.json'),
vendor: grunt.file.readJSON('.bowerrc').directory,
site : grunt.file.readYAML('_config.yml'),
bootstrap: '<%= vendor %>/bootstrap',
// Before generating any new files, remove files from previous build.
clean: {
example: ['<%= site.dest %>/*.html'],
// Delete this target after first run!!!
once: ['<%= site.theme %>/bootstrap/{var*,mix*,util*}.less']
},
// Lint JavaScript
jshint: {
all: ['Gruntfile.js', 'templates/helpers/*.js'],
options: {
jshintrc: '.jshintrc'
}
},
// Build HTML from templates and data
assemble: {
options: {
flatten: true,
production: false,
assets: '<%= site.assets %>',
postprocess: require('pretty'),
// Metadata
pkg: '<%= pkg %>',
site: '<%= site %>',
data: ['<%= site.data %>'],
// Templates
partials: '<%= site.includes %>',
layoutdir: '<%= site.layouts %>',
layout: '<%= site.layout %>',
// Extensions
helpers: '<%= site.helpers %>',
plugins: '<%= site.plugins %>'
},
example: {
files: {'<%= site.dest %>/': ['<%= site.templates %>/*.hbs']}
}
},
// Compile LESS to CSS
less: {
options: {
vendor: 'vendor',
paths: [
'<%= site.theme %>',
'<%= site.theme %>/bootstrap',
'<%= site.theme %>/components',
'<%= site.theme %>/utils'
],
},
site: {
src: ['<%= site.theme %>/site.less'],
dest: '<%= site.assets %>/css/site.css'
}
},
// Copy Bootstrap's assets to site assets
copy: {
// Delete this target after first run!!! Afterwards you'll need to
// decide on a strategy for adding javascripts, fonts etc.
once: {
files: [
{expand: true, cwd: '<%= bootstrap %>/less', src: ['*', '!{var*,mix*,util*}'], dest: '<%= site.theme %>/bootstrap/'},
{expand: true, cwd: '<%= bootstrap %>/less', src: ['{util*,mix*}.less'], dest: '<%= site.theme %>/utils'},
{expand: true, cwd: '<%= bootstrap %>/less', src: ['variables.less'], dest: '<%= site.theme %>/'},
{expand: true, cwd: 'node_modules/showup', src: ['showup.js'], dest: '<%= site.assets %>/js/'},
{expand: true, cwd: 'node_modules/showup', src: ['showup.css'], dest: '<%= site.theme %>/components/', ext: '.less'},
]
},
// Keep this target as a getting started point
assets: {
files: [
{expand: true, cwd: '<%= bootstrap %>/dist/fonts', src: ['*.*'], dest: '<%= site.assets %>/fonts/'},
{expand: true, cwd: '<%= bootstrap %>/dist/js', src: ['*.*'], dest: '<%= site.assets %>/js/'},
]
}
},
watch: {
all: {
files: ['<%= jshint.all %>'],
tasks: ['jshint', 'nodeunit']
},
site: {
files: ['Gruntfile.js', '<%= less.options.paths %>/*.less', 'templates/**/*.hbs'],
tasks: ['design']
}
}
});
// Load npm plugins to provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-readme');
grunt.loadNpmTasks('grunt-sync-pkg');
grunt.loadNpmTasks('assemble-less');
grunt.loadNpmTasks('assemble');
// Run this task once, then delete it as well as all of the "once" targets.
grunt.registerTask('setup', ['copy:once', 'clean:once']);
// Build HTML, compile LESS and watch for changes. You must first run "bower install"
// or install Bootstrap to the "vendor" directory before running this command.
grunt.registerTask('design', ['clean', 'assemble', 'less:site', 'watch:site']);
grunt.registerTask('docs', ['readme', 'sync']);
// Delete this conditional logic after first run.
if(!grunt.file.exists('_gh_pages_/assets/fonts') && !grunt.file.exists('_gh_pages_/assets/js')) {
grunt.registerTask('default', ['setup', 'clean', 'jshint', 'copy:assets', 'assemble', 'less', 'docs']);
} else {
// Use this going forward.
grunt.registerTask('default', ['clean', 'jshint', 'copy:assets', 'assemble', 'less', 'docs']);
}
};