From 1c37e2d0691530ab4fa7a730e00acebd12566955 Mon Sep 17 00:00:00 2001 From: Eddie Monge Date: Thu, 27 Mar 2014 16:40:21 -0700 Subject: [PATCH] chore(release): jshint the files before release Add JSHint checking to the source files and clean them up to conform to the .jshintrc file. Added the grunt task to support this. --- .jshintrc | 30 ++++++++++++++++-------------- Gruntfile.js | 30 ++++++++++++++++++++++++++---- decorator/index.js | 8 ++++---- util.js | 35 ++++++++++++++++++----------------- 4 files changed, 64 insertions(+), 39 deletions(-) diff --git a/.jshintrc b/.jshintrc index c8ba9d651..0918c7458 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,16 +1,18 @@ { - "node": true, - "esnext": true, - "bitwise": false, - "curly": false, - "eqeqeq": true, - "eqnull": true, - "immed": true, - "latedef": true, - "newcap": true, - "noarg": true, - "undef": true, - "strict": false, - "trailing": true, - "smarttabs": true + "node": true, + "esnext": true, + "bitwise": false, + "curly": false, + "eqeqeq": true, + "eqnull": true, + "immed": true, + "latedef": true, + "newcap": true, + "noarg": true, + "undef": true, + "strict": false, + "globalstrict": true, + "trailing": true, + "smarttabs": true, + "node": true } diff --git a/Gruntfile.js b/Gruntfile.js index 23ab17759..5d9e5aedd 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -6,7 +6,20 @@ module.exports = function (grunt) { require('load-grunt-tasks')(grunt); grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), + pkg: require('./package.json'), + jshint: { + all: { + options: { + jshintrc: './.jshintrc' + }, + src: [ + '**/index.js', + '*.js', + '!test/**/*.js', + '!node_modules/**/*.js' + ] + } + }, changelog: { options: { dest: 'CHANGELOG.md', @@ -44,11 +57,14 @@ module.exports = function (grunt) { } var config = setup(options.file, type); - grunt.file.write(config.file, JSON.stringify(config.pkg, null, ' ') + '\n'); + grunt.file.write( + config.file, + JSON.stringify(config.pkg, null, ' ') + '\n' + ); grunt.log.ok('Version bumped to ' + config.newVersion); }); - grunt.registerTask('stage', 'git add files before running the release task', function () { + grunt.registerTask('stage', 'git adds files', function () { var files = this.options().files; grunt.util.spawn({ cmd: process.platform === 'win32' ? 'git.cmd' : 'git', @@ -56,5 +72,11 @@ module.exports = function (grunt) { }, grunt.task.current.async()); }); - grunt.registerTask('default', ['bump', 'changelog', 'stage', 'release']); + grunt.registerTask('default', [ + 'jshint', + 'bump', + 'changelog', + 'stage', + 'release' + ]); }; diff --git a/decorator/index.js b/decorator/index.js index 56fb2115f..9ea86fbd2 100644 --- a/decorator/index.js +++ b/decorator/index.js @@ -3,6 +3,10 @@ var util = require('util'); var ScriptBase = require('../script-base.js'); var fs = require('fs'); +function buildRelativePath(fileName){ + return 'decorators/' + fileName + "Decorator"; +} + var Generator = module.exports = function Generator(args, options) { ScriptBase.apply(this, arguments); this.fileName = this.name; @@ -61,7 +65,3 @@ Generator.prototype.createDecoratorFiles = function createDecoratorFiles() { this.appTemplate('decorator', 'scripts/' + buildRelativePath(this.fileName)); this.addScriptToIndex(buildRelativePath(this.fileName)); }; - -function buildRelativePath(fileName){ - return 'decorators/' + fileName + "Decorator"; -} diff --git a/util.js b/util.js index ca9a74352..b2578b227 100644 --- a/util.js +++ b/util.js @@ -2,28 +2,12 @@ var path = require('path'); var fs = require('fs'); - -module.exports = { - rewrite: rewrite, - rewriteFile: rewriteFile, - appName: appName -}; - -function rewriteFile (args) { - args.path = args.path || process.cwd(); - var fullPath = path.join(args.path, args.file); - - args.haystack = fs.readFileSync(fullPath, 'utf8'); - var body = rewrite(args); - - fs.writeFileSync(fullPath, body); -} - function escapeRegExp (str) { return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); } function rewrite (args) { + /* jshint -W044 */ // check if splicable is already in the body text var re = new RegExp(args.splicable.map(function (line) { return '\s*' + escapeRegExp(line); @@ -59,6 +43,16 @@ function rewrite (args) { return lines.join('\n'); } +function rewriteFile (args) { + args.path = args.path || process.cwd(); + var fullPath = path.join(args.path, args.file); + + args.haystack = fs.readFileSync(fullPath, 'utf8'); + var body = rewrite(args); + + fs.writeFileSync(fullPath, body); +} + function appName (self) { var counter = 0, suffix = self.options['app-suffix']; // Have to check this because of generator bug #386 @@ -72,3 +66,10 @@ function appName (self) { } return suffix ? self._.classify(suffix) : ''; } + + +module.exports = { + rewrite: rewrite, + rewriteFile: rewriteFile, + appName: appName +};