diff --git a/Gruntfile.js b/Gruntfile.js index b29260ba5..34c5c1717 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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']) } diff --git a/grunt-tasks/babel.js b/grunt-tasks/babel.js new file mode 100644 index 000000000..f462c105e --- /dev/null +++ b/grunt-tasks/babel.js @@ -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' + } + } + }; +}; diff --git a/grunt-tasks/bootlint.js b/grunt-tasks/bootlint.js new file mode 100644 index 000000000..20923ce98 --- /dev/null +++ b/grunt-tasks/bootlint.js @@ -0,0 +1,12 @@ +// Validate Bootstrap HTML +'use strict'; + +module.exports = function (grunt) { + return { + options: { + relaxerror: ['W005'] + }, + // files: ['pages/**/*.html', '*.html'] + files: ['starter.html'] + }; +}; diff --git a/grunt-tasks/clean.js b/grunt-tasks/clean.js new file mode 100644 index 000000000..4afd571eb --- /dev/null +++ b/grunt-tasks/clean.js @@ -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/*"] + }; +}; diff --git a/grunt-tasks/concat.js b/grunt-tasks/concat.js new file mode 100644 index 000000000..365be72df --- /dev/null +++ b/grunt-tasks/concat.js @@ -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' + } + }; +}; diff --git a/grunt-tasks/csslint.js b/grunt-tasks/csslint.js new file mode 100644 index 000000000..13352d1f8 --- /dev/null +++ b/grunt-tasks/csslint.js @@ -0,0 +1,14 @@ +// Validate CSS files +'use strict'; + +module.exports = function (grunt) { + return { + options: { + csslintrc: 'build/less/.csslintrc' + }, + dist: [ + 'dist/css/AdminLTE.css', + ] + } + +}; diff --git a/grunt-tasks/eslint.js b/grunt-tasks/eslint.js new file mode 100644 index 000000000..52ca858eb --- /dev/null +++ b/grunt-tasks/eslint.js @@ -0,0 +1,11 @@ +// Lint ECMASCRIPT +'use strict'; + +module.exports = function (grunt) { + return { + options: { + configFile: 'build/js/.eslintrc' + }, + target: 'build/js/src/*.js' + }; +}; diff --git a/grunt-tasks/image.js b/grunt-tasks/image.js new file mode 100644 index 000000000..599251364 --- /dev/null +++ b/grunt-tasks/image.js @@ -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/' + }] + } + }; +}; diff --git a/grunt-tasks/includes.js b/grunt-tasks/includes.js new file mode 100644 index 000000000..630028931 --- /dev/null +++ b/grunt-tasks/includes.js @@ -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' + } + } + }; +}; diff --git a/grunt-tasks/jscs.js b/grunt-tasks/jscs.js new file mode 100644 index 000000000..373d0c923 --- /dev/null +++ b/grunt-tasks/jscs.js @@ -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' + }*/ + }; +}; diff --git a/grunt-tasks/jshint.js b/grunt-tasks/jshint.js new file mode 100644 index 000000000..4afaacc7a --- /dev/null +++ b/grunt-tasks/jshint.js @@ -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' + } + }; +}; diff --git a/grunt-tasks/sass.js b/grunt-tasks/sass.js new file mode 100644 index 000000000..6188c7b7c --- /dev/null +++ b/grunt-tasks/sass.js @@ -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' + } + } + }; +}; diff --git a/grunt-tasks/uglify.js b/grunt-tasks/uglify.js new file mode 100644 index 000000000..3608df687 --- /dev/null +++ b/grunt-tasks/uglify.js @@ -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'] + } + } + }; +}; diff --git a/grunt-tasks/watch.js b/grunt-tasks/watch.js new file mode 100644 index 000000000..25b8e6d10 --- /dev/null +++ b/grunt-tasks/watch.js @@ -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'] + } + }; +}; diff --git a/package.json b/package.json index f69322525..0c61af7aa 100644 --- a/package.json +++ b/package.json @@ -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" } }