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' ;
54const 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
912var 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
3329module . 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} ;
0 commit comments