From 4177b26a1f1228c76fd5ed548237a6f8e3d30029 Mon Sep 17 00:00:00 2001 From: Kevin CARADANT Date: Mon, 29 Feb 2016 18:17:24 +0100 Subject: [PATCH] feat: Add plato to analyse the code complexity --- .gitignore | 1 + Gulpfile.js | 2 ++ README.md | 1 + gulp-tasks/clean-js.js | 5 +++-- gulp-tasks/plato.js | 17 +++++++++++++++++ gulp-tasks/scripts.js | 10 +++++++++- 6 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 gulp-tasks/plato.js diff --git a/.gitignore b/.gitignore index f55d73a..a202283 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ build/* docs/* coverage/* .publish/* +complexity_report/* # files *.zip diff --git a/Gulpfile.js b/Gulpfile.js index ad868fd..7b8ec02 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -15,6 +15,7 @@ let gulp = require('gulp'), $.notifier = require('node-notifier'); $.conventionalGithubReleaser = require('conventional-github-releaser'); $.critical = require('critical').stream; + $.plato = require('plato'); process.env.NODE_ENV = $.argv.production ? 'production' : 'development'; process.env.PORT = $.argv.PORT ? $.argv.PORT : '8080'; @@ -47,6 +48,7 @@ function runTask(task) { } let tasks = [ + 'plato', 'sass', 'build-zip', 'clean-zip', diff --git a/README.md b/README.md index 2e04adc..e2dbecd 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ Note: To view the app please open a new tab and go to `http://localhost:8080/`. - `$ gulp build`: Create distribution package for the development and production environment - `$ gulp serve`: Start web-server and live-reload. - `$ gulp tests`: execute unit tests with Karma +- `$ gulp plato`: build a static analysis and complexity report - `$ gulp xo`: Linter to scan src js files - `$ gulp release`: Automate release workflow - `$ gulp release --patch`: Automate release workflow for a patch release (ex: v.0.0.1) diff --git a/gulp-tasks/clean-js.js b/gulp-tasks/clean-js.js index 1fbca4f..d404006 100644 --- a/gulp-tasks/clean-js.js +++ b/gulp-tasks/clean-js.js @@ -1,11 +1,12 @@ 'use strict'; module.exports = (gulp, $) => { - return () => { + return (cb) => { if($.env.isProd){ return $.del(['build/js']); }else{ - return $.del(['nothing']); + cb(); } } } + diff --git a/gulp-tasks/plato.js b/gulp-tasks/plato.js new file mode 100644 index 0000000..f357264 --- /dev/null +++ b/gulp-tasks/plato.js @@ -0,0 +1,17 @@ +'use strict'; + +module.exports = (gulp, $) => { + return (cb) => { + let files = [ + 'build/**/*.js', + ]; + + let outputDir = 'complexity_report'; + + let options = { + title: 'Report' + }; + + return $.plato.inspect(files, outputDir, options, cb()); + } +} diff --git a/gulp-tasks/scripts.js b/gulp-tasks/scripts.js index b34761c..306e186 100644 --- a/gulp-tasks/scripts.js +++ b/gulp-tasks/scripts.js @@ -12,12 +12,20 @@ module.exports = (gulp, $) => { .pipe($.if($.env.isProd, $.size({title: 'Annotate and StripDebug NodeModules Libs JS'}))) .pipe($.if($.env.isDev, $.size({title: 'Annotate NodeModules Libs JS'}))) .pipe($.if($.env.isDev, gulp.dest('build/libs'))) - , + , gulp.src(allLibsJsApp, {base: '.'}) .pipe($.plumber()) .pipe($.ngAnnotate()) .pipe($.babel()) + .pipe($.if($.env.isProd,$.complexity({ + breakOnErrors: false, + errorsOnly: false, + cyclomatic: [5], + halstead: [15], + maintainability: 100, + hideComplexFunctions: true, + }))) .pipe($.if($.env.isProd, $.stripDebug())) .pipe($.if($.env.isProd, $.size({title: 'Annotate, Babel and StripDebug App Libs JS'}))) .pipe($.if($.env.idDev, $.size({title: 'Annotate, Babel App Libs JS'})))