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' ;
5
4
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
+
8
11
9
12
var fs = require ( 'fs' ) ,
10
13
filesToBuild = {
11
14
uglify : { } ,
12
15
concat : {
13
16
main :{
14
- src :[ SRC_DIR + 'core-validators.js' ] ,
17
+ src : [ SRC_DIR + MAIN_DIR + 'core-validators.js' ] ,
15
18
dest : MAIN_PLUGIN_FILE
16
19
}
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
+ }
25
21
} ,
26
22
readFile = function ( file ) {
27
23
return fs . readFileSync ( file , 'utf-8' ) ;
@@ -31,31 +27,40 @@ var fs = require('fs'),
31
27
} ;
32
28
33
29
module . exports = function ( grunt ) {
34
-
35
30
// Gather up all module and language files
36
31
[ 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
46
44
} ;
47
- filesToBuild . devFiles . push ( path + fileName ) ;
48
- }
49
45
} ) ;
50
46
} ) ;
47
+
51
48
// 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 ) {
55
52
filesToBuild . concat . main . src . unshift ( fullPath ) ;
56
53
}
57
54
} ) ;
58
55
56
+ filesToBuild . cssFiles = [ ] ;
57
+ filesToBuild . cssFiles . push ( {
58
+ dest : DIST_DIR ,
59
+ src : CSS_FILE ,
60
+ cwd : SRC_DIR ,
61
+ expand : true
62
+ } ) ;
63
+
59
64
// Add options for concat and uglify
60
65
filesToBuild . concat . options = {
61
66
banner : "<%= meta.banner %>"
@@ -87,11 +92,17 @@ module.exports = function (grunt) {
87
92
// Concat definitions.
88
93
concat : filesToBuild . concat ,
89
94
95
+ cssmin : {
96
+ target : {
97
+ files : filesToBuild . cssFiles
98
+ }
99
+ } ,
90
100
// Lint definitions
91
101
jshint : {
92
- files : [ MODULE_DIR + "*" + DEV_EXTENSION , SRC_DIR + "*.js" ] ,
102
+ files : [ SRC_DIR + '/*' ] ,
93
103
options : {
94
- jshintrc : ".jshintrc"
104
+ jshintrc : ".jshintrc" ,
105
+ ignores : [ SRC_DIR + '/' + CSS_FILE ]
95
106
}
96
107
} ,
97
108
@@ -102,8 +113,8 @@ module.exports = function (grunt) {
102
113
// Better than calling grunt a million times
103
114
// (call 'grunt watch')
104
115
watch : {
105
- files : [ SRC_DIR + '/*' , LANG_DIR + '/*' , MODULE_DIR + '/ *'] ,
106
- tasks : [ 'build ' ] ,
116
+ files : [ SRC_DIR + '/* *'] ,
117
+ tasks : [ 'test ' ] ,
107
118
options : { nospawn : true }
108
119
} ,
109
120
@@ -143,7 +154,8 @@ module.exports = function (grunt) {
143
154
144
155
grunt . log . writeln ( '* Moving from version ' + currentVersion + ' to ' + newVersion ) ;
145
156
146
- replaceInFile ( 'package.json' , '"version": "' + currentVersion + '"' , '"version": "' + newVersion + '"' ) ;
157
+ replaceInFile ( 'package.json' , '"version": "' + currentVersion + '"' ,
158
+ '"version": "' + newVersion + '"' ) ;
147
159
replaceInFile ( 'formvalidator.jquery.json' , '"version": "' + currentVersion + '"' , '"version": "' + newVersion + '"' ) ;
148
160
149
161
// Set new version globally (can later on be used by concat/uglify)
@@ -158,10 +170,10 @@ module.exports = function (grunt) {
158
170
grunt . loadNpmTasks ( "grunt-contrib-watch" ) ;
159
171
grunt . loadNpmTasks ( 'grunt-contrib-connect' ) ;
160
172
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
167
179
} ;
0 commit comments