Skip to content

Commit e8b07cb

Browse files
committed
Change Grunt tasks to match new directory structure
-Fix JSHint to check language files (it wasn't checking those before) -Fix JSHint errors -Add task to minify CSS -Bump dependencies -Reorganize tasks. Default task is now a dev task which watches directory for changes and does tests/builds upon changes, but not minification; "build-production" task bumps version, does tests, and minifies output
1 parent 4a58e75 commit e8b07cb

File tree

4 files changed

+64
-53
lines changed

4 files changed

+64
-53
lines changed

Gruntfile.js

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
2-
const SRC_DIR = './form-validator/src/';
3-
const MODULE_DIR = './form-validator/';
4-
const LANG_DIR = './form-validator/lang/';
1+
//TODO: During next major version bump change to /dist. Leaving at ./form-validator for backwards
2+
//compabilitiy
3+
const DIST_DIR = './form-validator';
54
const MAIN_PLUGIN_FILE = 'form-validator/jquery.form-validator.min.js';
6-
const JS_EXTENSION = '.js';
7-
const DEV_EXTENSION = '.dev.js';
5+
const SRC_DIR = './src';
6+
const MAIN_DIR = '/main/';
7+
const MODULE_DIR = '/modules/';
8+
const LANG_DIR = '/lang/';
9+
const CSS_FILE = 'theme-default.css';
10+
811

912
var fs = require('fs'),
1013
filesToBuild = {
1114
uglify: {},
1215
concat: {
1316
main:{
14-
src:[SRC_DIR+'core-validators.js'],
17+
src: [SRC_DIR + MAIN_DIR+'core-validators.js'],
1518
dest: MAIN_PLUGIN_FILE
1619
}
17-
},
18-
devFiles: []
19-
},
20-
isJavascriptFile = function(fileName) {
21-
return fileName.substr(-3) == JS_EXTENSION;
22-
},
23-
isDevFile = function(fileName) {
24-
return fileName.substr(-1 * DEV_EXTENSION.length) == DEV_EXTENSION;
20+
}
2521
},
2622
readFile = function (file) {
2723
return fs.readFileSync(file, 'utf-8');
@@ -31,31 +27,40 @@ var fs = require('fs'),
3127
};
3228

3329
module.exports = function (grunt) {
34-
3530
// Gather up all module and language files
3631
[MODULE_DIR, LANG_DIR].forEach(function (path) {
37-
fs.readdirSync(path).forEach(function (fileName) {
38-
if (isDevFile(fileName)) {
39-
var name = fileName.substr(0, fileName.length - DEV_EXTENSION.length),
40-
fullPath = path + name + JS_EXTENSION;
41-
42-
filesToBuild.uglify[fullPath] = [fullPath];
43-
filesToBuild.concat['file' + name] = {
44-
src: [path + fileName],
45-
dest: path + name + JS_EXTENSION
32+
var srcPath = SRC_DIR + path;
33+
var distPath = DIST_DIR + path;
34+
if (path === MODULE_DIR) {
35+
distPath = DIST_DIR + '/';
36+
}
37+
38+
fs.readdirSync(srcPath).forEach(function (fileName) {
39+
var fullPath = srcPath + fileName;
40+
filesToBuild.uglify[distPath + fileName] = fullPath;
41+
filesToBuild.concat[fullPath] = {
42+
src: [fullPath],
43+
dest: distPath + fileName
4644
};
47-
filesToBuild.devFiles.push(path + fileName);
48-
}
4945
});
5046
});
47+
5148
// Gather up all source files that will added to minified core library
52-
fs.readdirSync(SRC_DIR).forEach(function (fileName) {
53-
var fullPath = SRC_DIR + fileName;
54-
if (isJavascriptFile(fileName) && filesToBuild.concat.main.src.indexOf(fullPath) == -1) {
49+
fs.readdirSync(SRC_DIR + MAIN_DIR).forEach(function (fileName) {
50+
var fullPath = SRC_DIR + MAIN_DIR + fileName;
51+
if (filesToBuild.concat.main.src.indexOf(fullPath) === -1) {
5552
filesToBuild.concat.main.src.unshift(fullPath);
5653
}
5754
});
5855

56+
filesToBuild.cssFiles = [];
57+
filesToBuild.cssFiles.push({
58+
dest: DIST_DIR,
59+
src: CSS_FILE,
60+
cwd: SRC_DIR,
61+
expand: true
62+
});
63+
5964
// Add options for concat and uglify
6065
filesToBuild.concat.options = {
6166
banner: "<%= meta.banner %>"
@@ -87,11 +92,17 @@ module.exports = function (grunt) {
8792
// Concat definitions.
8893
concat: filesToBuild.concat,
8994

95+
cssmin: {
96+
target: {
97+
files: filesToBuild.cssFiles
98+
}
99+
},
90100
// Lint definitions
91101
jshint: {
92-
files: [MODULE_DIR+"*"+DEV_EXTENSION, SRC_DIR+"*.js"],
102+
files: [SRC_DIR + '/*'],
93103
options: {
94-
jshintrc: ".jshintrc"
104+
jshintrc: ".jshintrc",
105+
ignores: [SRC_DIR + '/' + CSS_FILE]
95106
}
96107
},
97108

@@ -102,8 +113,8 @@ module.exports = function (grunt) {
102113
// Better than calling grunt a million times
103114
// (call 'grunt watch')
104115
watch: {
105-
files: [SRC_DIR+'/*', LANG_DIR+'/*', MODULE_DIR+'/*'],
106-
tasks: ['build'],
116+
files: [SRC_DIR + '/**'],
117+
tasks: ['test'],
107118
options : { nospawn : true }
108119
},
109120

@@ -143,7 +154,8 @@ module.exports = function (grunt) {
143154

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

146-
replaceInFile('package.json', '"version": "' + currentVersion + '"', '"version": "' + newVersion + '"');
157+
replaceInFile('package.json', '"version": "' + currentVersion + '"',
158+
'"version": "' + newVersion + '"');
147159
replaceInFile('formvalidator.jquery.json', '"version": "' + currentVersion + '"', '"version": "' + newVersion + '"');
148160

149161
// Set new version globally (can later on be used by concat/uglify)
@@ -158,10 +170,10 @@ module.exports = function (grunt) {
158170
grunt.loadNpmTasks("grunt-contrib-watch");
159171
grunt.loadNpmTasks('grunt-contrib-connect');
160172
grunt.loadNpmTasks('grunt-contrib-qunit');
161-
162-
grunt.registerTask("build", ["version", "concat", "uglify"]);
163-
grunt.registerTask('test', ['concat', 'jshint', 'qunit']);
164-
grunt.registerTask('test-uglify', ['concat', 'uglify', 'jshint', 'qunit']);
165-
grunt.registerTask("default", ["test", "build"]);
166-
173+
grunt.loadNpmTasks('grunt-contrib-cssmin');
174+
grunt.registerTask("build-production", ["version", "cssmin", "test", "uglify"]);
175+
grunt.registerTask('test', ['concat', 'cssmin','jshint', 'qunit']);
176+
grunt.registerTask("default", ["test", "watch"]);
177+
//TODO: add clean task, don't minify CSS in dev build, ?remove volo (its {version} is busted anyway)
178+
//Add unminified CSS to prod build
167179
};

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
"grunt-cli": "~0.1.13",
3131
"grunt-contrib-concat": "^0.5.1",
3232
"grunt-contrib-connect": "^0.11.2",
33-
"grunt-contrib-jshint": "^0.11.0",
33+
"grunt-contrib-cssmin": "~0.14.0",
34+
"grunt-contrib-jshint": "~1.0.0",
3435
"grunt-contrib-qunit": "^0.7.0",
35-
"grunt-contrib-uglify": "^0.8.0",
36+
"grunt-contrib-uglify": "~0.11.1",
3637
"grunt-contrib-watch": "^0.6.1",
3738
"jquery": "^2.1.4",
3839
"numeral": "~1.5.3",

src/lang/it.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* @version 2.2.163
1010
*/
1111
(function($, window) {
12-
1312
'use strict';
1413

1514
$(window).bind('validatorsLoaded', function() {
@@ -18,7 +17,7 @@
1817
errorTitle: 'Impossibile inviare il modulo!',
1918
requiredField: 'Campo obbligatorio',
2019
requiredFields: 'Non sono stati compilati tutti i campi richiesti',
21-
badTime: "L'ora scelta non &egrave; valida",
20+
badTime: 'L\'ora scelta non &egrave; valida',
2221
badEmail: 'Questo indirizzo email non &egrave; valido',
2322
badTelephone: 'Il numero di telefono imputato non &egrave; valido',
2423
badSecurityAnswer: 'La risposta alla domanda di sicurezza &egrave; errata',
@@ -29,7 +28,7 @@
2928
lengthTooShortStart: 'La lunghezza della risposta deve essere maggiore di ',
3029
notConfirmed: 'Los valores proporcionados no pudieron ser confirmados',
3130
badDomain: 'Il dominio inserito non &egrave; corretto.',
32-
badUrl: "L' URL inserito non &egrave; valido",
31+
badUrl: 'L\' URL inserito non &egrave; valido',
3332
badCustomVal: 'I valori inseriti non sono validi',
3433
andSpaces: ' e spazi ',
3534
badInt: 'Il numero inserito non &egrave; valido',
@@ -48,13 +47,13 @@
4847
groupCheckedEnd: ' opzione/i',
4948
badCreditCard: 'Il numero di carta di credito non risulta valido',
5049
badCVV: 'CVV non valido',
51-
wrongFileDim: "La dimensione dell'immagine non &egrave; valida,",
52-
imageTooTall: "il lato alto dell'immagine non può essere maggiore di ",
53-
imageTooWide: "il lato lungo dell'immagine non può essere maggiore di",
54-
imageTooSmall: "L'immagine è troppo piccola",
50+
wrongFileDim: 'La dimensione dell\'immagine non &egrave; valida,',
51+
imageTooTall: 'il lato alto dell\'immagine non può essere maggiore di',
52+
imageTooWide: 'il lato lungo dell\'immagine non può essere maggiore di',
53+
imageTooSmall: 'L\'immagine è troppo piccola',
5554
min: 'min.',
5655
max: 'máx.',
57-
imageRatioNotAccepted : "La proporzione dell' immagine (altezza x larghezza) non &egrave; valida"
56+
imageRatioNotAccepted : 'La proporzione dell\' immagine (altezza x larghezza) non &egrave; valida'
5857
};
5958

6059
});

src/lang/ru.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
* @license MIT
99
*/
1010
(function($, window) {
11-
12-
"use strict";
11+
'use strict';
1312

1413
$(window).bind('validatorsLoaded', function() {
1514

0 commit comments

Comments
 (0)