From 47ed5a2b5cb3aa25dd1bb8c39631a4ad13e2847c Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sat, 15 Oct 2016 12:50:57 +0200 Subject: [PATCH] Improve grunt tasks dependencies. --- Gruntfile.js | 30 +++++++++++++++++----- grunt-config/eslint.js | 8 +++--- grunt-config/jsonlint.js | 12 +++++++-- grunt-config/watch.js | 55 ++++++++++++++++++---------------------- 4 files changed, 61 insertions(+), 44 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index e3e24cb..c69f1b5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -46,23 +46,37 @@ module.exports = function(grunt) { // Toolchain tasks. // ================ + // Manage dev dependencies with npm + grunt.registerTask('npm', [ + // Linting on package.json. + 'newer:jsonlint:package', + // NodeJS dependencies. + 'shell:npmInstall' + ]); + + grunt.registerTask('grunt', [ + // Linting on Grunt files. + 'newer:eslint:grunt', + ]); + // Manage toolchain grunt.registerTask('toolchain', [ - // NodeJS dependencies for toolchain. - 'shell:npmInstall', - // Configuration file linting. - 'newer:eslint:toolchain', - 'newer:jsonlint:toolchain' + // NPM. + 'npm', + // Grunt. + 'grunt' ]); // Backend tasks. // ============== + + // Manage backend dependencies with pip. grunt.registerTask('beDeps', [ // Python dependencies. Does not work in virtualenv. - // 'shell:pipInstall' + //'shell:pipInstall' ]); - // Linting + // Backend linting grunt.registerTask('beLint', [ // Use flake8 for python linting. 'newer:flake8' @@ -79,6 +93,8 @@ module.exports = function(grunt) { // Front dependency management. grunt.registerTask('feDeps', [ + // Bower file linting + 'newer:jsonlint:bower', // Web assets using bower 'shell:bowerInstall', // Inject dependencies into application. diff --git a/grunt-config/eslint.js b/grunt-config/eslint.js index 2564dd6..fea0a89 100644 --- a/grunt-config/eslint.js +++ b/grunt-config/eslint.js @@ -1,13 +1,13 @@ 'use strict'; module.exports = { + grunt: [ + 'Gruntfile.js', + 'grunt-config/*.js' + ], frontend: [ '<%= accountant.frontend.src %>/index.html', '<%= accountant.frontend.src %>/views/*.html', '<%= accountant.frontend.src %>/js/*.js' - ], - toolchain: [ - 'Gruntfile.js', - 'grunt-config/*.js' ] }; diff --git a/grunt-config/jsonlint.js b/grunt-config/jsonlint.js index d85a739..068bc1b 100644 --- a/grunt-config/jsonlint.js +++ b/grunt-config/jsonlint.js @@ -1,8 +1,16 @@ 'use strict'; module.exports = { - toolchain: { - src: ['.eslintrc.json', 'package.json', 'bower.json'], + package: { + src: ['package.json'], + options: { + formatter: 'prose', + reporter: 'jslint', + indent: 2 + } + }, + bower: { + src: ['bower.json'], options: { formatter: 'prose', reporter: 'jslint', diff --git a/grunt-config/watch.js b/grunt-config/watch.js index 156ec79..956a683 100644 --- a/grunt-config/watch.js +++ b/grunt-config/watch.js @@ -1,43 +1,36 @@ 'use strict'; module.exports = { + // Toolchain + npm: { + files: ['package.json'], + taks: ['npm'] + }, + grunt: { + files: ['Gruntfile.js', 'grunt-config/*.js'], + tasks: ['grunt'] + }, + // Backend + requirements: { + files: ['requirements.txt'], + tasks: ['beDeps'] + }, + be: { + files: 'accountant/{,**}/*.py', + tasks: ['beLint', 'bgShell:runserver'] + }, + // Frontend bower: { files: 'bower.json', - tasks: ['wiredep'] + tasks: ['feDeps'] }, - js: { - files: [ - '<%= accountant.frontend.src %>/js/*.js %>', - 'grunt-config/*.js' - ], - tasks: ['jsdev'] - }, - py: { - files: 'accountant/**/*.py', - tasks: ['pydev', 'bgShell:runserver'] - }, - html: { - files: [ - '<%= accountant.frontend.src %>/*.html', - '<%= accountant.frontend.src %>/views/*.html' - ], - tasks: ['htmldev'] - }, - gruntfile: { - files: ['Gruntfile.js', 'grunt-config/*.js'] - }, - livereload: { + fe: { options: { livereload: '<%= connect.options.livereload %>' }, files: [ - '<%= accountant.frontend.src %>/{,*/}*.html', - '<%= accountant.frontend.src %>/js/*.js', - '<%= accountant.frontend.src %>/css/*.css' - ] - }, - requirements: { - files: ['requirements.txt'], - tasks: ['shell:pipInstall'] + '<%= accountant.frontend.src %>/{,**}/*', + ], + tasks: ['feLint'] } };