Merge pull request #1082 from gitarno/feature/load-grunt-config

Feature/load grunt config
pull/1005/head
Abdullah Almsaeed 2016-06-28 20:37:04 -04:00 committed by GitHub
commit cd2293e814
15 changed files with 234 additions and 202 deletions

View File

@ -2,213 +2,28 @@
module.exports = function (grunt) {
'use strict'
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('package.json'),
banner: '/*!\n' +
' * AdminLTE v<%= pkg.version %> (<%= pkg.homepage %>)\n' +
' * Copyright 2014-<%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' * Project website Almsaeed Studio (https://almsaeedstudio.com)\n' +
' * Licensed under MIT (https://github.com/almasaeed2010/AdminLTE/blob/master/LICENSE)\n' +
' */\n',
// Watch files for changes and invoke appropriate compiler
watch: {
sass: {
files: ['build/scss/*.scss', 'build/scss/skins/*.scss'],
tasks: ['sass']
},
es6: {
files: ['build/js/src/*.js'],
tasks: ['concat', 'babel', 'uglify']
},
js: {
files: ['dist/js/adminlte.js', 'dist/js/app.js'],
tasks: ['uglify']
}
},
// SASS compiler
sass: {
development: {
options: {
style: 'expanded'
},
files: {
'dist/css/AdminLTE.css': 'build/scss/AdminLTE.scss'
}
},
production: {
options: {
style: 'compressed'
},
files: {
'dist/css/adminlte.min.css': 'build/scss/AdminLTE.scss'
}
}
},
// Compress the js files.
uglify: {
options: {
mangle: true,
preserveComments: 'some'
},
target: {
files: {
'dist/js/adminlte.min.js': ['dist/js/adminlte.js'],
'dist/js/app.min.js': ['dist/js/app.js']
}
}
},
// Compile ES6
babel: {
options: {
sourceMap: true,
presets: ['es2015']
},
dist: {
files: {
'build/js/dist/Layout.js': 'build/js/src/Layout.js',
'build/js/dist/Treeview.js': 'build/js/src/Treeview.js',
'build/js/dist/PushMenu.js': 'build/js/src/PushMenu.js',
'build/js/dist/Widget.js': 'build/js/src/Widget.js',
'dist/js/adminlte.js': 'build/js/src/AdminLTE.js'
}
}
},
// Concat compiled JS files
concat: {
options: {
stripBanners: true,
banner: '<%= banner %>'
},
adminlte: {
src: [
'build/js/src/Layout.js',
'build/js/src/Treeview.js',
'build/js/src/PushMenu.js',
'build/js/src/Widget.js'
],
dest: 'build/js/src/AdminLTE.js'
}
},
// Build the documentation files
includes: {
build: {
src: ['*.html'], // Source files
dest: 'documentation/', // Destination directory
flatten: true,
cwd: 'documentation/build',
options: {
silent: true,
includePath: 'documentation/build/include'
}
}
},
// Optimize images
image: {
dynamic: {
files: [
{
expand: true,
cwd: 'build/img/',
src: ['**/*.{png,jpg,gif,svg,jpeg}'],
dest: 'dist/img/'
}
]
}
},
eslint: {
options: {
configFile: 'build/js/.eslintrc'
},
target: 'build/js/src/*.js'
},
// Lint JS code
jscs: {
options: {
config: 'build/js/.jscsrc'
},
grunt: {
src: ['Gruntfile.js']
},
core: {
src: 'js/src/*.js'
}
/*app: {
src: 'dist/js/app.js'
}*/
},
// Validate CSS files
csslint: {
options: {
csslintrc: 'build/scss/.csslintrc'
},
dist: [
'dist/css/AdminLTE.css'
]
},
// Validate Bootstrap HTML
bootlint: {
options: {
relaxerror: ['W005']
},
// files: ['pages/**/*.html', '*.html']
files: ['starter.html']
},
// Delete images in build directory
// After compressing the images in the build/img dir, there is no need
// for them
clean: {
build: ['build/img/*']
'use strict';
//loading the configurations and grunt tasks
var configs = require('load-grunt-config')(grunt,{
configPath: __dirname + '/grunt-tasks',
data:{
// Metadata.
pkg: grunt.file.readJSON('package.json'),
banner: '/*!\n' +
' * AdminLTE v<%= pkg.version %> (<%= pkg.homepage %>)\n' +
' * Copyright 2014-<%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' * Project website Almsaeed Studio (https://almsaeedstudio.com)\n' +
' * Licensed under MIT (https://github.com/almasaeed2010/AdminLTE/blob/master/LICENSE)\n' +
' */\n'
}
})
});
// Load all grunt tasks
// SASS compiler
grunt.loadNpmTasks('grunt-sass')
// Watch File Changes
grunt.loadNpmTasks('grunt-contrib-watch')
// Compress JS Files
grunt.loadNpmTasks('grunt-contrib-uglify')
// Include Files Within HTML
grunt.loadNpmTasks('grunt-includes')
// Optimize images
grunt.loadNpmTasks('grunt-image')
// Delete not needed files
grunt.loadNpmTasks('grunt-contrib-clean')
// Lint JS code
grunt.loadNpmTasks('grunt-jscs')
// Lint ECMA6 code
grunt.loadNpmTasks('grunt-eslint')
// Lint CSS
grunt.loadNpmTasks('grunt-contrib-csslint')
// Lint Bootstrap
grunt.loadNpmTasks('grunt-bootlint')
// Grunt Babel to compile ECMA6 to ECMA5
grunt.loadNpmTasks('grunt-babel')
// Concat files
grunt.loadNpmTasks('grunt-contrib-concat')
grunt.initConfig(configs);
// Linting task
grunt.registerTask('lint', ['jscs', 'eslint', 'csslint', 'bootlint'])
// JS Build Task
grunt.registerTask('build-js', ['babel', 'concat', 'uglify'])
// The default task (running 'grunt' in console) is 'watch'
grunt.registerTask('default', ['watch'])
}

20
grunt-tasks/babel.js Normal file
View File

@ -0,0 +1,20 @@
// Compile ECMA6 to ECMA5
'use strict';
module.exports = function (grunt) {
return {
options: {
sourceMap: true,
presets: ['es2015']
},
dist: {
files: {
'build/js/dist/Layout.js': 'build/js/src/Layout.js',
'build/js/dist/Treeview.js': 'build/js/src/Treeview.js',
'build/js/dist/PushMenu.js': 'build/js/src/PushMenu.js',
'build/js/dist/Widget.js': 'build/js/src/Widget.js',
'dist/js/adminlte.js': 'build/js/src/AdminLTE.js'
}
}
};
};

12
grunt-tasks/bootlint.js Normal file
View File

@ -0,0 +1,12 @@
// Validate Bootstrap HTML
'use strict';
module.exports = function (grunt) {
return {
options: {
relaxerror: ['W005']
},
// files: ['pages/**/*.html', '*.html']
files: ['starter.html']
};
};

10
grunt-tasks/clean.js Normal file
View File

@ -0,0 +1,10 @@
// Delete images in build directory
// After compressing the images in the build/img dir, there is no need
// for them
'use strict';
module.exports = function (grunt) {
return {
build: ["build/img/*"]
};
};

20
grunt-tasks/concat.js Normal file
View File

@ -0,0 +1,20 @@
// Concat compiled JS files
'use strict';
module.exports = function (grunt) {
return {
options: {
stripBanners: true,
banner: '<%= banner %>'
},
adminlte: {
src: [
'build/js/src/Layout.js',
'build/js/src/Treeview.js',
'build/js/src/PushMenu.js',
'build/js/src/Widget.js'
],
dest: 'build/js/src/AdminLTE.js'
}
};
};

14
grunt-tasks/csslint.js Normal file
View File

@ -0,0 +1,14 @@
// Validate CSS files
'use strict';
module.exports = function (grunt) {
return {
options: {
csslintrc: 'build/less/.csslintrc'
},
dist: [
'dist/css/AdminLTE.css',
]
}
};

11
grunt-tasks/eslint.js Normal file
View File

@ -0,0 +1,11 @@
// Lint ECMASCRIPT
'use strict';
module.exports = function (grunt) {
return {
options: {
configFile: 'build/js/.eslintrc'
},
target: 'build/js/src/*.js'
};
};

15
grunt-tasks/image.js Normal file
View File

@ -0,0 +1,15 @@
// Optimize images
'use strict';
module.exports = function (grunt) {
return {
dynamic: {
files: [{
expand: true,
cwd: 'build/img/',
src: ['**/*.{png,jpg,gif,svg,jpeg}'],
dest: 'dist/img/'
}]
}
};
};

17
grunt-tasks/includes.js Normal file
View File

@ -0,0 +1,17 @@
// Build the documentation files
'use strict';
module.exports = function (grunt) {
return {
build: {
src: ['*.html'], // Source files
dest: 'documentation/', // Destination directory
flatten: true,
cwd: 'documentation/build',
options: {
silent: true,
includePath: 'documentation/build/include'
}
}
};
};

19
grunt-tasks/jscs.js Normal file
View File

@ -0,0 +1,19 @@
// Lint JS code
'use strict';
module.exports = function (grunt) {
return {
options: {
config: 'build/js/.jscsrc'
},
grunt: {
src: ['Gruntfile.js']
},
core: {
src: 'js/src/*.js'
}
/*app: {
src: 'dist/js/app.js'
}*/
};
};

19
grunt-tasks/jshint.js Normal file
View File

@ -0,0 +1,19 @@
// Validate JS code
'use strict';
module.exports = function (grunt) {
return {
options: {
jshintrc: '.jshintrc'
},
core: {
src: 'dist/js/app.js'
},
demo: {
src: 'dist/js/demo.js'
},
pages: {
src: 'dist/js/pages/*.js'
}
};
};

24
grunt-tasks/sass.js Normal file
View File

@ -0,0 +1,24 @@
// SASS compiler
'use strict';
module.exports = function (grunt) {
return {
development: {
options: {
style: 'expanded'
},
files: {
'dist/css/AdminLTE.css': 'build/scss/AdminLTE.scss'
}
},
production: {
options: {
style: 'compressed'
},
files: {
'dist/css/adminlte.min.css': 'build/scss/AdminLTE.scss'
}
}
};
};

17
grunt-tasks/uglify.js Normal file
View File

@ -0,0 +1,17 @@
// Uglify task info. Compress the js files.
'use strict';
module.exports = function (grunt) {
return {
options: {
mangle: true,
preserveComments: 'some'
},
target: {
files: {
'dist/js/adminlte.min.js': ['dist/js/adminlte.js'],
'dist/js/app.min.js': ['dist/js/app.js']
}
}
};
};

19
grunt-tasks/watch.js Normal file
View File

@ -0,0 +1,19 @@
// Watch files for changes and invoke appropriate compiler
'use strict';
module.exports = function (grunt) {
return {
sass: {
files: ['build/scss/*.scss', 'build/scss/skins/*.scss'],
tasks: ['sass']
},
es6: {
files: ['build/js/src/*.js'],
tasks: ['concat', 'babel', 'uglify']
},
js: {
files: ['dist/js/adminlte.js', 'dist/js/app.js'],
tasks: ['uglify']
}
};
};

View File

@ -44,7 +44,7 @@
"grunt-image": "^1.0.5",
"grunt-includes": "^0.4.5",
"grunt-jscs": "^2.3.0",
"grunt-sass": "^1.1.0",
"grunt-scss-lint": "^0.3.8"
"grunt-scss-lint": "^0.3.8",
"load-grunt-config": "^0.19.2"
}
}