Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
chore(release): jshint the files before release
Browse files Browse the repository at this point in the history
Add JSHint checking to the source files and clean them up to conform to
the .jshintrc file. Added the grunt task to support this.
  • Loading branch information
eddiemonge committed Mar 27, 2014
1 parent 6c54096 commit 1c37e2d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 39 deletions.
30 changes: 16 additions & 14 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -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
}
30 changes: 26 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -44,17 +57,26 @@ 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',
args: ['add'].concat(files)
}, grunt.task.current.async());
});

grunt.registerTask('default', ['bump', 'changelog', 'stage', 'release']);
grunt.registerTask('default', [
'jshint',
'bump',
'changelog',
'stage',
'release'
]);
};
8 changes: 4 additions & 4 deletions decorator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
}
35 changes: 18 additions & 17 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -72,3 +66,10 @@ function appName (self) {
}
return suffix ? self._.classify(suffix) : '';
}


module.exports = {
rewrite: rewrite,
rewriteFile: rewriteFile,
appName: appName
};

0 comments on commit 1c37e2d

Please sign in to comment.