Skip to content

Commit 020f83c

Browse files
Victor JonssonVictor Jonsson
authored andcommitted
Switched to grunt
1 parent 87e1ebf commit 020f83c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+372
-76
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
indent_size = 2
8+
indent_style = space
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
node_modules
12
.DS_Store
2-
.idea/
3+
.idea/

.jshintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"boss": true,
3+
"curly": true,
4+
"eqeqeq": true,
5+
"eqnull": true,
6+
"expr": true,
7+
"immed": true,
8+
"noarg": true,
9+
"onevar": true,
10+
"quotmark": "single",
11+
"unused": true,
12+
"node": true
13+
}

Gruntfile.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
var fs = require('fs'),
2+
filesToBuild = {
3+
uglify : {},
4+
concat : {},
5+
devFiles : []
6+
},
7+
readFile = function(file) {
8+
return fs.readFileSync(file, 'utf-8');
9+
},
10+
replaceInFile = function(path, from, to) {
11+
fs.writeFileSync(path, readFile(path).replace(from, to));
12+
};
13+
14+
module.exports = function(grunt) {
15+
16+
// Gather up all js files
17+
['form-validator/', 'form-validator/lang/'].forEach(function(path) {
18+
fs.readdirSync(path).forEach(function(fileName) {
19+
if(fileName.substr(-7) == '.dev.js') {
20+
var name = fileName.substr(0, fileName.length - 7);
21+
filesToBuild.uglify[path + name + '.js'] = [path + name + '.js'];
22+
filesToBuild.concat['file'+name] = {
23+
src : [path + fileName],
24+
dest: path + name + '.js'
25+
}
26+
filesToBuild.devFiles.push( path + fileName );
27+
}
28+
});
29+
});
30+
31+
// Add options for concat ang ugligy
32+
filesToBuild.concat.options = {
33+
banner: "<%= meta.banner %>"
34+
};
35+
filesToBuild.uglify.options = {
36+
banner: "<%= meta.banner %>"
37+
};
38+
39+
// Add main script to concat/uglify
40+
filesToBuild.uglify['form-validator/jquery.form-validator.min.js'] = 'form-validator/jquery.form-validator.min.js';
41+
filesToBuild.concat.main = {
42+
src : ['form-validator/jquery.form-validator.js'],
43+
dest : 'form-validator/jquery.form-validator.min.js'
44+
}
45+
46+
grunt.initConfig({
47+
48+
// Import package manifest
49+
pkg: grunt.file.readJSON("package.json"),
50+
51+
// Banner definitions
52+
meta: {
53+
banner: "/**\n" +
54+
" * <%= pkg.title || pkg.name %> %>\n" +
55+
" *\n" +
56+
" * @website by <%= pkg.author.homepage %>\n" +
57+
" * @license <%= pkg.license %>\n" +
58+
" * @version <%= pkg.version %>\n" +
59+
" */\n"
60+
},
61+
62+
// Concat definitions. The only purpose of this
63+
// is to create a distribution file out
64+
// of files name *.dev.js
65+
concat: filesToBuild.concat,
66+
67+
// Lint definitions
68+
jshint: {
69+
files: ["form-validator/*.dev.js", "form-validator/jquery.form-validator.js"],
70+
options: {
71+
jshintrc: ".jshintrc"
72+
}
73+
},
74+
75+
// Minify definitions
76+
uglify: filesToBuild.uglify,
77+
78+
// watch for changes to source
79+
// Better than calling grunt a million times
80+
// (call 'grunt watch')
81+
watch: {
82+
files: ['form-validator/*'],
83+
tasks: ['default']
84+
}
85+
86+
});
87+
88+
89+
/*
90+
* Change to new version or the next version number in all files
91+
* containing the version definition
92+
*/
93+
grunt.registerTask('version', 'Bump up the version number, or change version name by adding --new-version=3.1.0', function() {
94+
var pkg = grunt.config.get('pkg'),
95+
currentVersion = pkg.version,
96+
newVersion = grunt.option('new-version');
97+
98+
99+
if( !newVersion ) {
100+
var versionParts = currentVersion.split('.'),
101+
newSubVersion = parseInt(versionParts.splice(versionParts.length-1, 1)[0]) + 1;
102+
newSubVersion = newSubVersion < 10 && newSubVersion > 0 ? '0'+newSubVersion : newSubVersion.toString();
103+
newVersion = versionParts.join('.') + '.' + newSubVersion;
104+
}
105+
106+
grunt.log.writeln('* Moving from version '+currentVersion+' to '+newVersion);
107+
108+
// replace version in config files and dev-files
109+
replaceInFile('form-validator/jquery.form-validator.min.js', '@version '+currentVersion, '@version '+newVersion);
110+
replaceInFile('form-validator/jquery.form-validator.js', '@version '+currentVersion, '@version '+newVersion);
111+
replaceInFile('package.json', '"version": "'+currentVersion+'"', '"version": "'+newVersion+'"');
112+
replaceInFile('formvalidator.jquery.json', '"version": "'+currentVersion+'"', '"version": "'+newVersion+'"');
113+
filesToBuild.devFiles.forEach(function(filePath) {
114+
replaceInFile(filePath, '@version '+currentVersion, '@version '+newVersion);
115+
});
116+
117+
// Set new version globally (can later on be used by concat/uglify)
118+
pkg.version = newVersion;
119+
grunt.config.set('pkg', pkg);
120+
});
121+
122+
123+
grunt.loadNpmTasks("grunt-contrib-concat");
124+
grunt.loadNpmTasks("grunt-contrib-jshint");
125+
grunt.loadNpmTasks("grunt-contrib-uglify");
126+
grunt.loadNpmTasks("grunt-contrib-watch");
127+
128+
grunt.registerTask("build", ["version", "concat", "uglify"]);
129+
grunt.registerTask("default", ["jshint", "build"]);
130+
131+
};

form-validator/brazil.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @website http://formvalidator.net/#brazil-validators
1313
* @license Dual licensed under the MIT or GPL Version 2 licenses
14-
* @version 2.2.63
14+
* @version 2.2.70
1515
*/
1616

1717
$.formUtils.addValidator({

form-validator/brazil.js

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/date.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#location-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.63
13+
* @version 2.2.70
1414
*/
1515
(function($) {
1616

form-validator/date.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
(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);
1+
/**
2+
* jquery-form-validator %>
3+
*
4+
* @website by
5+
* @license MIT
6+
* @version 2.2.70
7+
*/
8+
!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);

form-validator/file.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#file-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.63
13+
* @version 2.2.70
1414
*/
1515
(function($, window) {
1616

0 commit comments

Comments
 (0)