1
1
//TODO: During next major version bump change to /dist. Leaving at ./form-validator for backwards
2
- //compabilitiy
2
+ //compatibility
3
3
const DIST_DIR = './form-validator' ;
4
4
const MAIN_PLUGIN_FILE = 'form-validator/jquery.form-validator.min.js' ;
5
5
const SRC_DIR = './src' ;
@@ -8,78 +8,23 @@ const MODULE_DIR = '/modules/';
8
8
const LANG_DIR = '/lang/' ;
9
9
const CSS_FILE = 'theme-default.css' ;
10
10
11
-
12
11
var fs = require ( 'fs' ) ,
13
- filesToBuild = {
14
- uglify : { } ,
15
- concat : {
16
- main :{
17
- src : [ SRC_DIR + MAIN_DIR + 'core-validators.js' ] ,
18
- dest : MAIN_PLUGIN_FILE
19
- }
20
- }
21
- } ,
22
12
readFile = function ( file ) {
23
13
return fs . readFileSync ( file , 'utf-8' ) ;
24
14
} ,
25
15
replaceInFile = function ( path , from , to ) {
26
16
fs . writeFileSync ( path , readFile ( path ) . replace ( from , to ) ) ;
27
17
} ;
28
18
29
- module . exports = function ( grunt ) {
30
- // Gather up all module and language files
31
- [ MODULE_DIR , LANG_DIR ] . forEach ( function ( path ) {
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
44
- } ;
45
- } ) ;
46
- } ) ;
47
-
48
- // Gather up all source files that will added to minified core library
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 ) {
52
- filesToBuild . concat . main . src . unshift ( fullPath ) ;
53
- }
54
- } ) ;
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
-
64
- // Add options for concat and uglify
65
- filesToBuild . concat . options = {
66
- banner : "<%= meta.banner %>"
67
- } ;
68
- filesToBuild . uglify . options = {
69
- banner : "<%= meta.banner %>"
70
- } ;
71
-
72
- // Add main script to uglify
73
- filesToBuild . uglify [ MAIN_PLUGIN_FILE ] = MAIN_PLUGIN_FILE ;
74
-
19
+ function initializeGruntConfig ( grunt , filesToBuild ) {
75
20
grunt . initConfig ( {
76
21
77
22
// Import package manifest
78
23
pkg : grunt . file . readJSON ( "package.json" ) ,
79
24
80
25
// Banner definitions
81
26
meta : {
82
- banner : "/**\n" +
27
+ banner : "/** File generated by Grunt -- do not modify \n" +
83
28
" * <%= (pkg.title || pkg.name).toUpperCase() %>\n" +
84
29
" *\n" +
85
30
" * @version <%= pkg.version %>\n" +
@@ -93,9 +38,9 @@ module.exports = function (grunt) {
93
38
concat : filesToBuild . concat ,
94
39
95
40
cssmin : {
96
- target : {
97
- files : filesToBuild . cssFiles
98
- }
41
+ target : {
42
+ files : filesToBuild . cssFiles
43
+ }
99
44
} ,
100
45
// Lint definitions
101
46
jshint : {
@@ -115,7 +60,7 @@ module.exports = function (grunt) {
115
60
watch : {
116
61
files : [ SRC_DIR + '/**' ] ,
117
62
tasks : [ 'test' ] ,
118
- options : { nospawn : true }
63
+ options : { nospawn : true }
119
64
} ,
120
65
121
66
// Unit tests
@@ -132,10 +77,72 @@ module.exports = function (grunt) {
132
77
keepalive : true
133
78
}
134
79
}
80
+ } ,
81
+
82
+ clean : [ DIST_DIR + '/' ]
83
+ } ) ;
84
+ }
85
+
86
+ module . exports = function ( grunt ) {
87
+ var filesToBuild = {
88
+ uglify : { } ,
89
+ concat : {
90
+ main :{
91
+ src : [ SRC_DIR + MAIN_DIR + 'core-validators.js' ] ,
92
+ dest : MAIN_PLUGIN_FILE
93
+ }
94
+ }
95
+ } ;
96
+ // Gather up all module and language files
97
+ [ MODULE_DIR , LANG_DIR ] . forEach ( function ( path ) {
98
+ var srcPath = SRC_DIR + path ;
99
+ var distPath = DIST_DIR + path ;
100
+ if ( path === MODULE_DIR ) {
101
+ distPath = DIST_DIR + '/' ;
102
+ }
103
+
104
+ fs . readdirSync ( srcPath ) . forEach ( function ( fileName ) {
105
+ var fullPath = srcPath + fileName ;
106
+ filesToBuild . uglify [ distPath + fileName ] = fullPath ;
107
+ filesToBuild . concat [ fullPath ] = {
108
+ src : [ fullPath ] ,
109
+ dest : distPath + fileName
110
+ } ;
111
+ } ) ;
112
+ } ) ;
113
+ filesToBuild . concat [ CSS_FILE ] = {
114
+ src : [ SRC_DIR + '/' + CSS_FILE ] ,
115
+ dest : DIST_DIR + '/' + CSS_FILE
116
+ } ;
117
+ // Gather up all source files that will added to minified core library
118
+ fs . readdirSync ( SRC_DIR + MAIN_DIR ) . forEach ( function ( fileName ) {
119
+ var fullPath = SRC_DIR + MAIN_DIR + fileName ;
120
+ if ( filesToBuild . concat . main . src . indexOf ( fullPath ) === - 1 ) {
121
+ filesToBuild . concat . main . src . unshift ( fullPath ) ;
135
122
}
123
+ } ) ;
136
124
125
+ filesToBuild . cssFiles = [ ] ;
126
+ filesToBuild . cssFiles . push ( {
127
+ dest : DIST_DIR ,
128
+ src : CSS_FILE ,
129
+ cwd : SRC_DIR ,
130
+ expand : true ,
131
+ ext : '.min.css'
137
132
} ) ;
138
133
134
+ // Add options for concat and uglify
135
+ filesToBuild . concat . options = {
136
+ banner : "<%= meta.banner %>"
137
+ } ;
138
+ filesToBuild . uglify . options = {
139
+ banner : "<%= meta.banner %>"
140
+ } ;
141
+
142
+ // Add main script to uglify
143
+ filesToBuild . uglify [ MAIN_PLUGIN_FILE ] = MAIN_PLUGIN_FILE ;
144
+
145
+ initializeGruntConfig ( grunt , filesToBuild ) ;
139
146
/*
140
147
* Change to new version or the next version number. The project must be built again after this task
141
148
* in order for the version change to take effect.
@@ -163,7 +170,7 @@ module.exports = function (grunt) {
163
170
grunt . config . set ( 'pkg' , pkg ) ;
164
171
} ) ;
165
172
166
-
173
+ grunt . loadNpmTasks ( 'grunt-contrib-clean' ) ;
167
174
grunt . loadNpmTasks ( "grunt-contrib-concat" ) ;
168
175
grunt . loadNpmTasks ( "grunt-contrib-jshint" ) ;
169
176
grunt . loadNpmTasks ( "grunt-contrib-uglify" ) ;
@@ -174,6 +181,4 @@ module.exports = function (grunt) {
174
181
grunt . registerTask ( "build-production" , [ "version" , "cssmin" , "test" , "uglify" ] ) ;
175
182
grunt . registerTask ( 'test' , [ 'concat' , 'cssmin' , 'jshint' , 'qunit' ] ) ;
176
183
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
179
184
} ;
0 commit comments