Skip to content

Commit 3fe952c

Browse files
committed
now having a more efficient watch task
1 parent 58c39a3 commit 3fe952c

Some content is hidden

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

47 files changed

+160
-161
lines changed

Gruntfile.js

Lines changed: 91 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,120 @@
11
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) {
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) {
1515

1616
// 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') {
17+
['form-validator/', 'form-validator/lang/'].forEach(function (path) {
18+
fs.readdirSync(path).forEach(function (fileName) {
19+
if (fileName.substr(-7) == '.dev.js') {
2020
var name = fileName.substr(0, fileName.length - 7);
2121
filesToBuild.uglify[path + name + '.js'] = [path + name + '.js'];
22-
filesToBuild.concat['file'+name] = {
23-
src : [path + fileName],
22+
filesToBuild.concat['file' + name] = {
23+
src: [path + fileName],
2424
dest: path + name + '.js'
25-
}
26-
filesToBuild.devFiles.push( path + fileName );
25+
};
26+
filesToBuild.devFiles.push(path + fileName);
2727
}
2828
});
2929
});
3030

3131
// Add options for concat ang ugligy
3232
filesToBuild.concat.options = {
33-
banner: "<%= meta.banner %>"
34-
};
33+
banner: "<%= meta.banner %>"
34+
};
3535
filesToBuild.uglify.options = {
36-
banner: "<%= meta.banner %>"
37-
};
36+
banner: "<%= meta.banner %>"
37+
};
3838

3939
// Add main script to concat/uglify
4040
filesToBuild.uglify['form-validator/jquery.form-validator.min.js'] = 'form-validator/jquery.form-validator.min.js';
4141
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).toUpperCase() %>\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
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).toUpperCase() %>\n" +
55+
" *\n" +
56+
" * @author <%= pkg.author.name %>, <%= pkg.author.url %>\n" +
57+
" * @license <%= pkg.license %>\n" +
58+
" * @version <%= pkg.version %>\n" +
59+
" */\n"
60+
},
61+
62+
// Concat definitions. The only purpose of this
6363
// is to create a distribution file out
6464
// 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-
},
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: ['build'],
84+
options : { nospawn : true }
85+
},
8586

8687
qunit: {
8788
all: ['test/qunit.html']
8889
}
8990

90-
});
91-
91+
});
9292

9393
/*
9494
* Change to new version or the next version number in all files
9595
* containing the version definition
9696
*/
97-
grunt.registerTask('version', 'Bump up the version number, or change version name by adding --new-version=3.1.0', function() {
97+
grunt.registerTask('version', 'Bump up the version number, or change version name by adding --new-version=3.1.0', function () {
9898
var pkg = grunt.config.get('pkg'),
99-
currentVersion = pkg.version,
100-
newVersion = grunt.option('new-version');
101-
102-
103-
if( !newVersion ) {
104-
var versionParts = currentVersion.split('.'),
105-
newSubVersion = parseInt(versionParts.splice(versionParts.length-1, 1)[0]) + 1;
106-
newSubVersion = newSubVersion < 10 && newSubVersion > 0 ? '0'+newSubVersion : newSubVersion.toString();
107-
newVersion = versionParts.join('.') + '.' + newSubVersion;
99+
currentVersion = pkg.version,
100+
newVersion = grunt.option('new-version');
101+
102+
if (!newVersion) {
103+
var versionParts = currentVersion.split('.'),
104+
newSubVersion = parseInt(versionParts.splice(versionParts.length - 1, 1)[0]) + 1;
105+
newSubVersion = newSubVersion < 10 && newSubVersion > 0 ? '0' + newSubVersion : newSubVersion.toString();
106+
newVersion = versionParts.join('.') + '.' + newSubVersion;
108107
}
109108

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

112111
// replace version in config files and dev-files
113-
replaceInFile('form-validator/jquery.form-validator.min.js', '@version '+currentVersion, '@version '+newVersion);
114-
replaceInFile('form-validator/jquery.form-validator.js', '@version '+currentVersion, '@version '+newVersion);
115-
replaceInFile('package.json', '"version": "'+currentVersion+'"', '"version": "'+newVersion+'"');
116-
replaceInFile('formvalidator.jquery.json', '"version": "'+currentVersion+'"', '"version": "'+newVersion+'"');
117-
filesToBuild.devFiles.forEach(function(filePath) {
118-
replaceInFile(filePath, '@version '+currentVersion, '@version '+newVersion);
112+
replaceInFile('form-validator/jquery.form-validator.min.js', '@version ' + currentVersion, '@version ' + newVersion);
113+
replaceInFile('form-validator/jquery.form-validator.js', '@version ' + currentVersion, '@version ' + newVersion);
114+
replaceInFile('package.json', '"version": "' + currentVersion + '"', '"version": "' + newVersion + '"');
115+
replaceInFile('formvalidator.jquery.json', '"version": "' + currentVersion + '"', '"version": "' + newVersion + '"');
116+
filesToBuild.devFiles.forEach(function (filePath) {
117+
replaceInFile(filePath, '@version ' + currentVersion, '@version ' + newVersion);
119118
});
120119

121120
// Set new version globally (can later on be used by concat/uglify)
@@ -124,14 +123,14 @@ module.exports = function(grunt) {
124123
});
125124

126125

127-
grunt.loadNpmTasks("grunt-contrib-concat");
128-
grunt.loadNpmTasks("grunt-contrib-jshint");
129-
grunt.loadNpmTasks("grunt-contrib-uglify");
130-
grunt.loadNpmTasks("grunt-contrib-watch");
131-
grunt.loadNpmTasks('grunt-contrib-qunit');
126+
grunt.loadNpmTasks("grunt-contrib-concat");
127+
grunt.loadNpmTasks("grunt-contrib-jshint");
128+
grunt.loadNpmTasks("grunt-contrib-uglify");
129+
grunt.loadNpmTasks("grunt-contrib-watch");
130+
grunt.loadNpmTasks('grunt-contrib-qunit');
132131

133-
grunt.registerTask("build", ["version", "concat", "uglify"]);
134-
grunt.registerTask('test', ['jshint', 'qunit']);
135-
grunt.registerTask("default", ["test", "build"]);
132+
grunt.registerTask("build", ["version", "concat", "uglify"]);
133+
grunt.registerTask('test', ['jshint', 'qunit']);
134+
grunt.registerTask("default", ["test", "build"]);
136135

137136
};

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 MIT
14-
* @version 2.2.101
14+
* @version 2.2.116
1515
*/
1616

1717
$.formUtils.addValidator({

form-validator/brazil.js

Lines changed: 2 additions & 2 deletions
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 MIT
13-
* @version 2.2.101
13+
* @version 2.2.116
1414
*/
1515
(function($) {
1616

form-validator/date.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* JQUERY-FORM-VALIDATOR
33
*
4-
* @website by
4+
* @author Victor Jonsson, http://victorjonsson.se
55
* @license MIT
6-
* @version 2.2.101
6+
* @version 2.2.116
77
*/
88
!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 MIT
13-
* @version 2.2.101
13+
* @version 2.2.116
1414
*/
1515
(function($, window) {
1616

form-validator/file.js

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

form-validator/html5.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @website http://formvalidator.net/
1919
* @license MIT
20-
* @version 2.2.101
20+
* @version 2.2.116
2121
*/
2222
(function($, window) {
2323

form-validator/html5.js

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

form-validator/jquery.form-validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @website http://formvalidator.net/
77
* @license MIT
8-
* @version 2.2.101
8+
* @version 2.2.102
99
*/
1010
(function ($) {
1111

form-validator/jquery.form-validator.min.js

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

form-validator/jsconf.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @website http://formvalidator.net/#location-validators
99
* @license MIT
10-
* @version 2.2.101
10+
* @version 2.2.116
1111
*/
1212
(function($) {
1313

form-validator/jsconf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* JQUERY-FORM-VALIDATOR
33
*
4-
* @website by
4+
* @author Victor Jonsson, http://victorjonsson.se
55
* @license MIT
6-
* @version 2.2.101
6+
* @version 2.2.116
77
*/
88
!function(a){"use strict";a.setupValidation=function(b){var c=a(b.form||"form");a.each(b.validate||b.validation||{},function(b,d){var e;e="#"===b[0]?a(b):c.find("."===b[0]?b:'*[name="'+b+'"]'),e.attr("data-validation",d.validation),a.each(d,function(a,b){"validation"!==a&&b!==!1&&(b===!0&&(b="true"),"_"===a[0]?(a=a.substring(1),b===!1?e.removeAttr(a):e.attr(a,b)):e.valAttr(a,b))})}),a.validate(b)}}(jQuery);

form-validator/lang/cz.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @website http://formvalidator.net/
88
* @license MIT
9-
* @version 2.2.101
9+
* @version 2.2.116
1010
*/
1111
(function($, window) {
1212

0 commit comments

Comments
 (0)