Skip to content

Commit

Permalink
Switched to grunt
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Jonsson authored and Victor Jonsson committed Sep 24, 2015
1 parent 87e1ebf commit 020f83c
Show file tree
Hide file tree
Showing 44 changed files with 372 additions and 76 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.DS_Store
.idea/
.idea/
13 changes: 13 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"expr": true,
"immed": true,
"noarg": true,
"onevar": true,
"quotmark": "single",
"unused": true,
"node": true
}
131 changes: 131 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
var fs = require('fs'),
filesToBuild = {
uglify : {},
concat : {},
devFiles : []
},
readFile = function(file) {
return fs.readFileSync(file, 'utf-8');
},
replaceInFile = function(path, from, to) {
fs.writeFileSync(path, readFile(path).replace(from, to));
};

module.exports = function(grunt) {

// Gather up all js files
['form-validator/', 'form-validator/lang/'].forEach(function(path) {
fs.readdirSync(path).forEach(function(fileName) {
if(fileName.substr(-7) == '.dev.js') {
var name = fileName.substr(0, fileName.length - 7);
filesToBuild.uglify[path + name + '.js'] = [path + name + '.js'];
filesToBuild.concat['file'+name] = {
src : [path + fileName],
dest: path + name + '.js'
}
filesToBuild.devFiles.push( path + fileName );
}
});
});

// Add options for concat ang ugligy
filesToBuild.concat.options = {
banner: "<%= meta.banner %>"
};
filesToBuild.uglify.options = {
banner: "<%= meta.banner %>"
};

// Add main script to concat/uglify
filesToBuild.uglify['form-validator/jquery.form-validator.min.js'] = 'form-validator/jquery.form-validator.min.js';
filesToBuild.concat.main = {
src : ['form-validator/jquery.form-validator.js'],
dest : 'form-validator/jquery.form-validator.min.js'
}

grunt.initConfig({

// Import package manifest
pkg: grunt.file.readJSON("package.json"),

// Banner definitions
meta: {
banner: "/**\n" +
" * <%= pkg.title || pkg.name %> %>\n" +
" *\n" +
" * @website by <%= pkg.author.homepage %>\n" +
" * @license <%= pkg.license %>\n" +
" * @version <%= pkg.version %>\n" +
" */\n"
},

// Concat definitions. The only purpose of this
// is to create a distribution file out
// of files name *.dev.js
concat: filesToBuild.concat,

// Lint definitions
jshint: {
files: ["form-validator/*.dev.js", "form-validator/jquery.form-validator.js"],
options: {
jshintrc: ".jshintrc"
}
},

// Minify definitions
uglify: filesToBuild.uglify,

// watch for changes to source
// Better than calling grunt a million times
// (call 'grunt watch')
watch: {
files: ['form-validator/*'],
tasks: ['default']
}

});


/*
* Change to new version or the next version number in all files
* containing the version definition
*/
grunt.registerTask('version', 'Bump up the version number, or change version name by adding --new-version=3.1.0', function() {
var pkg = grunt.config.get('pkg'),
currentVersion = pkg.version,
newVersion = grunt.option('new-version');


if( !newVersion ) {
var versionParts = currentVersion.split('.'),
newSubVersion = parseInt(versionParts.splice(versionParts.length-1, 1)[0]) + 1;
newSubVersion = newSubVersion < 10 && newSubVersion > 0 ? '0'+newSubVersion : newSubVersion.toString();
newVersion = versionParts.join('.') + '.' + newSubVersion;
}

grunt.log.writeln('* Moving from version '+currentVersion+' to '+newVersion);

// replace version in config files and dev-files
replaceInFile('form-validator/jquery.form-validator.min.js', '@version '+currentVersion, '@version '+newVersion);
replaceInFile('form-validator/jquery.form-validator.js', '@version '+currentVersion, '@version '+newVersion);
replaceInFile('package.json', '"version": "'+currentVersion+'"', '"version": "'+newVersion+'"');
replaceInFile('formvalidator.jquery.json', '"version": "'+currentVersion+'"', '"version": "'+newVersion+'"');
filesToBuild.devFiles.forEach(function(filePath) {
replaceInFile(filePath, '@version '+currentVersion, '@version '+newVersion);
});

// Set new version globally (can later on be used by concat/uglify)
pkg.version = newVersion;
grunt.config.set('pkg', pkg);
});


grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-watch");

grunt.registerTask("build", ["version", "concat", "uglify"]);
grunt.registerTask("default", ["jshint", "build"]);

};
2 changes: 1 addition & 1 deletion form-validator/brazil.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @website http://formvalidator.net/#brazil-validators
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.2.63
* @version 2.2.70
*/

$.formUtils.addValidator({
Expand Down
9 changes: 8 additions & 1 deletion form-validator/brazil.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion form-validator/date.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @website http://formvalidator.net/#location-validators
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.2.63
* @version 2.2.70
*/
(function($) {

Expand Down
9 changes: 8 additions & 1 deletion form-validator/date.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
(function($){$.formUtils.addValidator({name:"time",validatorFunction:function(time){if(time.match(/^(\d{2}):(\d{2})$/)===null){return false}else{var hours=parseInt(time.split(":")[0],10);var minutes=parseInt(time.split(":")[1],10);if(hours>23||minutes>59){return false}}return true},errorMessage:"",errorMessageKey:"badTime"});$.formUtils.addValidator({name:"birthdate",validatorFunction:function(val,$el,conf){var dateFormat="yyyy-mm-dd";if($el.valAttr("format")){dateFormat=$el.valAttr("format")}else if(typeof conf.dateFormat!="undefined"){dateFormat=conf.dateFormat}var inputDate=$.formUtils.parseDate(val,dateFormat);if(!inputDate){return false}var d=new Date;var currentYear=d.getFullYear();var year=inputDate[0];var month=inputDate[1];var day=inputDate[2];if(year===currentYear){var currentMonth=d.getMonth()+1;if(month===currentMonth){var currentDay=d.getDate();return day<=currentDay}else{return month<currentMonth}}else{return year<currentYear&&year>currentYear-124}},errorMessage:"",errorMessageKey:"badDate"})})(jQuery);
/**
* jquery-form-validator %>
*
* @website by
* @license MIT
* @version 2.2.70
*/
!function(a){a.formUtils.addValidator({name:"time",validatorFunction:function(a){if(null===a.match(/^(\d{2}):(\d{2})$/))return!1;var b=parseInt(a.split(":")[0],10),c=parseInt(a.split(":")[1],10);return b>23||c>59?!1:!0},errorMessage:"",errorMessageKey:"badTime"}),a.formUtils.addValidator({name:"birthdate",validatorFunction:function(b,c,d){var e="yyyy-mm-dd";c.valAttr("format")?e=c.valAttr("format"):"undefined"!=typeof d.dateFormat&&(e=d.dateFormat);var f=a.formUtils.parseDate(b,e);if(!f)return!1;var g=new Date,h=g.getFullYear(),i=f[0],j=f[1],k=f[2];if(i===h){var l=g.getMonth()+1;if(j===l){var m=g.getDate();return m>=k}return l>j}return h>i&&i>h-124},errorMessage:"",errorMessageKey:"badDate"})}(jQuery);
2 changes: 1 addition & 1 deletion form-validator/file.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @website http://formvalidator.net/#file-validators
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.2.63
* @version 2.2.70
*/
(function($, window) {

Expand Down
Loading

0 comments on commit 020f83c

Please sign in to comment.