Added 'load-grunt-config' plugin

The plugin replaces the custom 'loadConfig()' function with a more robust and extensible solution.

It handles 'grunt.initConfig()' and 'load-grunt-tasks'.

Changes:
- Moved Grunt task configurations into a 'config/' sub-directory to allow room for custom plugins, modules, and tasks to be defined without being included by the config-loader;
- Updated '.eslintrc' to better lint module-based JS;
- Updated EditorConfig recommendations;
This commit is contained in:
Chauncey McAskill
2016-04-11 15:26:20 -04:00
parent 6d3b8134f1
commit a4c1721e74
32 changed files with 349 additions and 279 deletions

View File

@@ -1,3 +1,3 @@
{
"presets": ["es2015"]
"presets": [ "es2015" ]
}

View File

@@ -10,9 +10,6 @@ end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
[*.json,.bowerrc]
insert_final_newline = false
[{.htaccess,.bowerrc,bower.json,package.json,component.json}]
[{*.md,.*rc,.*.json,*.yml,.editorconfig,.env,.env.*,.git*,.htaccess,.jshintignore,bower.json,composer.json,package.json}]
indent_style = space
indent_size = 2

View File

@@ -1,42 +1,46 @@
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"ecmaFeatures": {
"arrowFunctions": true,
"binaryLiterals": true,
"blockBindings": true,
"classes": true,
"defaultParams": true,
"destructuring": true,
"forOf": true,
"generators": true,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"octalLiterals": true,
"regexUFlag": true,
"regexYFlag": true,
"spread": true,
"superInFunctions": false,
"templateStrings": true,
"unicodeCodePointEscapes": true,
"globalReturn": true,
"jsx": true
},
"rules": {
"eqeqeq": 2,
"strict": 0,
"no-empty": 1,
"no-alert": 2,
"no-eval": 2,
"quotes": [1, "single", "avoid-escape"],
"no-trailing-spaces": [2, { "skipBlankLines": true }],
"eol-last": 0,
"yoda": [2, "never", { "exceptRange": true }]
}
"env": {
"browser": true,
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"ecmaFeatures": {
"arrowFunctions": true,
"binaryLiterals": true,
"blockBindings": true,
"classes": true,
"defaultParams": true,
"destructuring": true,
"forOf": true,
"generators": true,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"octalLiterals": true,
"regexUFlag": true,
"regexYFlag": true,
"spread": true,
"superInFunctions": false,
"templateStrings": true,
"unicodeCodePointEscapes": true,
"globalReturn": true,
"jsx": true
},
"rules": {
"eqeqeq": 2,
"strict": 0,
"no-empty": 1,
"no-alert": 2,
"no-eval": 2,
"quotes": [1, "single", "avoid-escape"],
"no-trailing-spaces": [2, { "skipBlankLines": true }],
"eol-last": 0,
"yoda": [2, "never", { "exceptRange": true }]
}
}

16
.gitignore vendored
View File

@@ -1,3 +1,15 @@
.DS_Store
# General
# -----------------
# Logs
logs
*.log
error_log
# Package Managers
# -----------------
composer.phar
vendor/
node_modules/
npm-debug.log
bower_components/

View File

@@ -1,55 +1,35 @@
module.exports = function(grunt) {
/**
* Grunt Task Wrangler
*
* @copyright Copyright © 2016 Locomotive
* @license Licensed under the MIT license.
*/
function loadConfig(path) {
var glob = require('glob');
var object = {};
var key;
'use strict';
glob.sync('*', {cwd: path}).forEach(function(option) {
key = option.replace(/\.js$/,'');
object[key] = require(path + option);
});
module.exports = function (grunt)
{
var path = require('path');
return object;
}
var config = {
pkg: grunt.file.readJSON('package.json')
}
grunt.loadTasks('build/grunt');
grunt.util._.extend(config, loadConfig('./build/grunt/'));
grunt.initConfig(config);
// Load tasks
require('load-grunt-tasks')(grunt);
// Register tasks
grunt.registerTask('default', ['build']);
grunt.registerTask('sync', ['browserSync', 'browserify:dev', 'watch', 'notify:watch']);
grunt.registerTask('build', [
// CSS
'sass',
'postcss',
'cssmin',
// JS
'browserify:prod',
'uglify',
// SVG
'svgstore',
'svgmin',
// Notify
'notify:build'
]);
grunt.registerTask('w', ['browserify:dev', 'watch', 'notify:watch']);
grunt.registerTask('c', [
'csscomb'
]);
grunt.registerTask('j', [
'eslint'
]);
grunt.registerTask('p', [
'phplint'
]);
require('load-grunt-config')(grunt, {
configPath: path.join(process.cwd(), 'build/grunt/config'),
data: {
paths: {
grunt: 'build/grunt',
js: {
src: 'assets/scripts',
dist: 'www/assets/scripts'
},
css: {
src: 'assets/styles',
dist: 'www/assets/styles'
},
img: {
src: 'assets/images',
dist: 'www/assets/images'
}
}
}
});
};

View File

@@ -1,18 +0,0 @@
module.exports = {
dev: {
bsFiles: {
src : [
'www/assets/styles/**/*.css'
,'www/assets/scripts/**/*.js'
,'www/assets/images/**/*.svg'
,'www/**/*.php'
]
},
options: {
proxy: "localhost",
port: 3000,
watchTask: true,
notify: false
}
}
};

View File

@@ -1,30 +0,0 @@
module.exports = {
dev: {
options: {
transform: [['babelify', { presets: ['es2015'] }]],
watch : true, // use watchify for incremental builds!
browserifyOptions : {
debug : true // source mapping
}
},
files: {
'www/assets/scripts/app.js': [
'assets/scripts/**/*.js',
'!assets/scripts/vendors/*.js'
]
}
},
prod: {
options: {
transform: [['babelify', { presets: ['es2015'] }]],
browserifyOptions: { debug: false },
exclude: ''
},
files: {
'www/assets/scripts/app.js': [
'assets/scripts/**/*.js',
'!assets/scripts/vendors/*.js'
]
}
}
};

View File

@@ -1,8 +0,0 @@
module.exports = {
vendors: {
src: [
'assets/scripts/vendors/*.js'
],
dest: 'www/assets/scripts/vendors.js'
}
};

View File

@@ -0,0 +1,41 @@
{
"default": [
"build"
],
"sync": [
"browserSync",
"browserify:dev",
"watch",
"notify:watch"
],
"build": [
"sass",
"postcss",
"cssmin",
"browserify:prod",
"uglify",
"svgstore",
"svgmin",
"notify:build"
],
"w": [
"browserify:dev",
"watch",
"notify:watch"
],
"c": [
"csscomb"
],
"j": [
"eslint"
],
"p": [
"phplint"
]
}

View File

@@ -0,0 +1,18 @@
module.exports = {
options: {
proxy : 'localhost',
port : 3000,
watchTask : true,
notify : false
},
dev: {
bsFiles: {
src : [
'<%= paths.css.dist %>/**/*.css',
'<%= paths.js.dist %>/**/*.js',
'<%= paths.img.dist %>/**/*.svg',
'**/*.php'
]
}
}
};

View File

@@ -0,0 +1,34 @@
module.exports = {
options: {
browserifyOptions: {
debug: false
},
exclude: "",
transform: [
[ 'babelify', { presets: [ 'es2015' ] } ]
]
},
dev: {
options: {
browserifyOptions: {
debug: true
},
watch: true
},
src: [
'<%= paths.js.src %>/**/*.js',
'!<%= paths.js.src %>/vendors/**/*.js'
],
dest: '<%= paths.js.dist %>/app.js'
},
prod: {
options: {
banner: '/*! <%= package.title %> - <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
src: [
'<%= paths.js.src %>/**/*.js',
'!<%= paths.js.src %>/vendors/**/*.js'
],
dest: '<%= paths.js.dist %>/app.js'
}
};

View File

@@ -0,0 +1,12 @@
module.exports = {
options: {
stripBanners: true
},
prod: {
options: {
banner: '/*! Dependencies for <%= package.title %> - <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
src : [ '<%= paths.js.src %>/vendors/**/*.js' ],
dest : '<%= paths.js.dist %>/vendors.js'
}
};

View File

@@ -0,0 +1,15 @@
module.exports = {
options: {
config: '.csscomb.json'
},
dev: {
files: [
{
expand : true,
cwd : '<%= paths.css.src %>',
src : [ '**/*.scss', '!base/_fonts.scss' ],
dest : '<%= paths.css.src %>'
}
]
}
};

View File

@@ -0,0 +1,13 @@
module.exports = {
options: {},
prod: {
files: [
{
expand : true,
cwd : '<%= paths.css.dist %>',
src : [ '**/*.css', '!**/*.min.css' ],
dest : '<%= paths.css.dist %>'
}
]
}
};

View File

@@ -0,0 +1,11 @@
module.exports = {
options: {
quiet : false,
format : require('eslint-tap'),
configFile : '.eslintrc'
},
dev: [
'<%= paths.js.src %>/**/*.js',
'!<%= paths.js.src %>/vendors/**/*.js'
]
};

View File

@@ -1,31 +1,35 @@
module.exports = {
notify_hooks: {
options: {
enabled : true,
success : true,
duration : 3,
title : '<%= package.name %>',
max_jshint_notifications : 5
}
},
watch: {
options: {
// title: '<%= pkg.title %>',
message: 'Keeping an eye out, Chief!'
}
},
build: {
options: {
// title: '<%= pkg.title %>',
message: 'Everything is ready to go!'
}
},
sass: {
options: {
// title: '<%= pkg.title %>',
message: 'CSS is compiled'
}
},
javascript: {
options: {
// title: '<%= pkg.title %>',
message: 'JavaScript is compiled'
}
},
svg: {
options: {
// title: '<%= pkg.title %>',
message: 'SVG is concatenated'
}
}

View File

@@ -1,14 +1,12 @@
module.exports = {
options: {
swapPath: '/tmp',
phpArgs : {
swapPath : '/tmp',
phpArgs : {
// add -f for fatal errors
'-lf': null
}
},
project: [
dev: [
'**/*.php'
]
}
;
};

View File

@@ -0,0 +1,27 @@
module.exports = function (grunt, options)
{
return {
options: {
map: false,
processors: [
require('autoprefixer')({
browsers: [ 'last 2 versions', '> 1%', 'ie >= 9' ]
}),
require('postcss-banner')({
banner: grunt.template.process('! <%= package.title %> - <%= grunt.template.today("yyyy-mm-dd") %> ', { data: options })
})
]
},
prod: {
files: [
{
expand : true,
flatten : true,
cwd : '<%= paths.css.dist %>',
src : [ '**/*.css', '!**/*.min.css' ],
dest : '<%= paths.css.dist %>'
}
]
}
}
};

View File

@@ -0,0 +1,17 @@
module.exports = {
options: {
sourceMap : false,
outputStyle : 'expanded'
},
prod: {
files: [
{
expand : true,
cwd : '<%= paths.css.src %>',
src : [ '**/*.scss' ],
dest : '<%= paths.css.dist %>',
ext : '.css'
}
]
}
};

View File

@@ -14,11 +14,9 @@ module.exports = {
]
},
dist: {
expand: true,
cwd: 'www/assets/images/',
src: '*.svg',
dest: 'www/assets/images/',
ext: '.svg',
extDot: 'first'
expand : true,
cwd : '<%= paths.img.dist %>',
src : '*.svg',
dest : '<%= paths.img.dist %>'
}
};

View File

@@ -0,0 +1,8 @@
module.exports = {
options: {},
prod: {
files: {
'<%= paths.img.dist %>/sprite.svg': [ '<%= paths.img.src %>/sprite/*.svg' ]
}
}
};

View File

@@ -0,0 +1,13 @@
module.exports = {
options: {},
prod: {
files: [
{
expand : true,
cwd : '<%= paths.js.dist %>',
src : [ '**/*.js', '!**/*.min.js' ],
dest : '<%= paths.js.dist %>'
}
]
}
};

View File

@@ -0,0 +1,27 @@
module.exports = {
options: {
spawn: false,
livereload: false
},
javascript_vendors: {
files: [ '<%= paths.js.src %>/vendors/**/*.js' ],
tasks: [ 'concat:vendors', 'notify:javascript' ]
},
sass: {
files: [ '<%= paths.css.src %>/**/*.scss' ],
tasks: [ 'sass', 'postcss', 'notify:sass' ]
},
svg: {
files: [ '<%= paths.img.src %>/**/*.svg' ],
tasks: [ 'svgstore', 'notify:svg' ]
},
tasks: {
options: {
reload: true
},
files: [
'Gruntfile.js',
'<%= paths.grunt %>/**/*'
]
}
};

View File

@@ -1,11 +0,0 @@
module.exports = {
options: {
config: '.csscomb.json'
},
build: {
expand: true,
cwd: 'assets/styles/',
src: ['**/*.scss', '!base/_fonts.scss'],
dest: 'assets/styles/'
}
};

View File

@@ -1,10 +0,0 @@
module.exports = {
combine: {
files: [{
expand: true,
cwd: 'www/assets/styles/',
src: '*.css',
dest: 'www/assets/styles/'
}]
}
};

View File

@@ -1,10 +0,0 @@
module.exports = {
options: {
format: require('eslint-tap'),
configFile: '.eslintrc'
},
target: [
'assets/scripts/**/*.js',
'!assets/scripts/vendors/*.js'
],
};

View File

@@ -1,19 +0,0 @@
module.exports = {
postcss: {
options: {
processors: [
require('autoprefixer')({
browsers: ['last 2 versions', '> 1%', 'ie >= 9']
}),
]
},
files: [
{
src : ['www/assets/styles/*.css'],
dest : 'www/assets/styles/',
expand : true,
flatten : true
}
]
}
};

View File

@@ -1,10 +0,0 @@
module.exports = {
options: {
sourceMap: false
},
dist: {
files: {
'www/assets/styles/main.css': 'assets/styles/main.scss'
}
}
};

View File

@@ -1,10 +0,0 @@
module.exports = {
options: {
},
default : {
files: {
'www/assets/images/sprite.svg': ['assets/images/sprite/*.svg'],
}
}
};

View File

@@ -1,10 +0,0 @@
module.exports = {
target: {
files: [{
expand: true,
cwd: 'www/assets/scripts/',
src: '**/*.js',
dest: 'www/assets/scripts/'
}]
}
};

View File

@@ -1,26 +0,0 @@
module.exports = {
javascript_vendors: {
files: [
'assets/scripts/vendors/*.js'
],
tasks: ['concat:vendors', 'notify:javascript']
},
sass: {
files: ['assets/styles/**/*.scss'],
tasks: ['sass', 'postcss', 'notify:sass'],
options: {
spawn: false,
livereload: true
}
},
svg: {
files: ['assets/images/**/*.svg'],
tasks: ['svgstore', 'notify:svg']
},
tasks: {
files: ['build/grunt/*.js'],
options: {
reload: true
}
}
};

View File

@@ -1,5 +1,7 @@
{
"name": "boilerplate",
"private": true,
"name": "@locomotivemtl/boilerplate",
"title": "Locomotive Boilerplate",
"version": "1.0.0",
"author": "Locomotive <info@locomotive.ca>",
"devDependencies": {
@@ -12,7 +14,7 @@
"grunt-browser-sync": "2.2.0",
"grunt-browserify": "4.0.1",
"grunt-contrib-concat": "1.0.0",
"grunt-contrib-cssmin": "1.0.0",
"grunt-contrib-cssmin": "^1.0.1",
"grunt-contrib-uglify": "1.0.0",
"grunt-contrib-watch": "0.6.1",
"grunt-csscomb": "3.1.0",
@@ -23,6 +25,7 @@
"grunt-sass": "1.1.0",
"grunt-svgmin": "3.1.2",
"grunt-svgstore": "1.0.0",
"load-grunt-tasks": "3.4.1"
"load-grunt-config": "^0.19.1",
"postcss-banner": "^1.2.0"
}
}