1
1
//TODO: During next major version bump change to /dist. Leaving at ./form-validator for backwards
2
2
//compatibility
3
3
const DIST_DIR = './form-validator' ;
4
- const MAIN_PLUGIN_FILE = './form-validator/ jquery.form-validator' ;
4
+ const MAIN_PLUGIN_FILE = 'jquery.form-validator' ;
5
5
const SRC_DIR = './src' ;
6
6
const MAIN_DIR = '/main/' ;
7
- const MODULE_DIR = '/modules/ ' ;
8
- const LANG_DIR = '/lang/ ' ;
7
+ const MODULE_DIR = '/modules' ;
8
+ const LANG_DIR = '/lang' ;
9
9
const CSS_FILE = 'theme-default.css' ;
10
+ const CORE_VALIDATORS = 'core-validators.js' ; //must come at end of concatted file
11
+ const coreValidatorsPath = SRC_DIR + MAIN_DIR + CORE_VALIDATORS ;
10
12
11
13
var fs = require ( 'fs' ) ,
12
14
readFile = function ( file ) {
@@ -16,7 +18,8 @@ var fs = require('fs'),
16
18
fs . writeFileSync ( path , readFile ( path ) . replace ( from , to ) ) ;
17
19
} ;
18
20
19
- function initializeGruntConfig ( grunt , filesToBuild ) {
21
+ function initializeGruntConfig ( grunt ) {
22
+
20
23
grunt . initConfig ( {
21
24
22
25
// Import package manifest
@@ -34,12 +37,36 @@ function initializeGruntConfig(grunt, filesToBuild) {
34
37
" */\n"
35
38
} ,
36
39
37
- // Concat definitions.
38
- concat : filesToBuild . concat ,
40
+ concat : {
41
+ main :{
42
+ files : [
43
+ //This concatenates the core validators file after the other files
44
+ //Per: http://gruntjs.com/configuring-tasks
45
+ {
46
+ src : [ SRC_DIR + MAIN_DIR + '*.js' , '!' + coreValidatorsPath , coreValidatorsPath ] ,
47
+ dest : DIST_DIR + '/' + MAIN_PLUGIN_FILE + '.js'
48
+ } ,
49
+ {
50
+ src : [ SRC_DIR + MAIN_DIR + '*.js' , '!' + coreValidatorsPath , coreValidatorsPath ] ,
51
+ dest : DIST_DIR + '/' + MAIN_PLUGIN_FILE + '.min.js'
52
+ } ]
53
+ } ,
54
+ options : {
55
+ banner : "<%= meta.banner %>"
56
+ }
57
+ } ,
39
58
40
59
cssmin : {
41
60
target : {
42
- files : filesToBuild . cssFiles
61
+ files : [
62
+ {
63
+ dest : DIST_DIR ,
64
+ src : CSS_FILE ,
65
+ cwd : SRC_DIR ,
66
+ expand : true ,
67
+ ext : '.min.css'
68
+ }
69
+ ]
43
70
}
44
71
} ,
45
72
// Lint definitions
@@ -52,7 +79,21 @@ function initializeGruntConfig(grunt, filesToBuild) {
52
79
} ,
53
80
54
81
// Minify definitions
55
- uglify : filesToBuild . uglify ,
82
+ uglify : {
83
+ options : {
84
+ banner : "<%= meta.banner %>"
85
+ } ,
86
+ main : {
87
+ files : [
88
+ {
89
+ expand : true ,
90
+ cwd : DIST_DIR + '/' ,
91
+ src : [ '**/*.js' , '!' + MAIN_PLUGIN_FILE + '.js' ] ,
92
+ dest : DIST_DIR + '/'
93
+ }
94
+ ]
95
+ }
96
+ } ,
56
97
57
98
// watch for changes to source
58
99
// Better than calling grunt a million times
@@ -79,97 +120,49 @@ function initializeGruntConfig(grunt, filesToBuild) {
79
120
}
80
121
} ,
81
122
123
+ copy : {
124
+ main : {
125
+ files : [
126
+ {
127
+ src : SRC_DIR + '/' + CSS_FILE ,
128
+ dest : DIST_DIR + '/' + CSS_FILE
129
+ } ,
130
+ {
131
+ cwd : SRC_DIR + '/' + MODULE_DIR ,
132
+ src : '**' ,
133
+ dest : DIST_DIR + '/' ,
134
+ expand : true
135
+ } ,
136
+ {
137
+ cwd : SRC_DIR + '/' + LANG_DIR ,
138
+ src : '**' ,
139
+ dest : DIST_DIR + LANG_DIR + '/' ,
140
+ expand : true
141
+ } ]
142
+ }
143
+ } ,
144
+
82
145
clean : [ DIST_DIR + '/' ] ,
146
+
83
147
umd : {
84
148
main : {
85
149
options : {
86
- src : MAIN_PLUGIN_FILE + '.js' ,
150
+ src : DIST_DIR + '/**/*.js' ,
151
+ dest : './' ,
87
152
deps : {
88
153
default : [ 'jQuery' ] ,
89
154
amd : [ { 'jquery' : 'jQuery' } ] ,
90
155
cjs : [ { 'jquery' : 'jQuery' } ]
91
156
}
92
157
}
93
- } ,
94
- minified : {
95
- options : {
96
- src : MAIN_PLUGIN_FILE + '.min.js' ,
97
- deps : {
98
- default : [ '$' ] ,
99
- amd : [ { 'jquery' : 'jQuery' } ] ,
100
- cjs : [ { 'jquery' : 'jQuery' } ]
101
- }
102
- }
103
158
}
104
159
}
105
160
} ) ;
106
161
}
107
162
108
163
module . exports = function ( grunt ) {
109
- var filesToBuild = {
110
- uglify : { } ,
111
- concat : {
112
- main :{
113
- src : [ SRC_DIR + MAIN_DIR + 'core-validators.js' ] ,
114
- dest : MAIN_PLUGIN_FILE + '.js'
115
- }
116
- }
117
- } ;
118
- // Gather up all module and language files
119
- [ MODULE_DIR , LANG_DIR ] . forEach ( function ( path ) {
120
- var srcPath = SRC_DIR + path ;
121
- var distPath = DIST_DIR + path ;
122
- if ( path === MODULE_DIR ) {
123
- distPath = DIST_DIR + '/' ;
124
- }
125
-
126
- fs . readdirSync ( srcPath ) . forEach ( function ( fileName ) {
127
- var fullPath = srcPath + fileName ;
128
- filesToBuild . uglify [ distPath + fileName ] = fullPath ;
129
- filesToBuild . concat [ fullPath ] = {
130
- src : [ fullPath ] ,
131
- dest : distPath + fileName
132
- } ;
133
- } ) ;
134
- } ) ;
135
- filesToBuild . concat [ CSS_FILE ] = {
136
- src : [ SRC_DIR + '/' + CSS_FILE ] ,
137
- dest : DIST_DIR + '/' + CSS_FILE
138
- } ;
139
- // Gather up all source files that will added to minified core library
140
- fs . readdirSync ( SRC_DIR + MAIN_DIR ) . forEach ( function ( fileName ) {
141
- var fullPath = SRC_DIR + MAIN_DIR + fileName ;
142
- if ( filesToBuild . concat . main . src . indexOf ( fullPath ) === - 1 ) {
143
- filesToBuild . concat . main . src . unshift ( fullPath ) ;
144
- }
145
- } ) ;
146
-
147
- filesToBuild . cssFiles = [ ] ;
148
- filesToBuild . cssFiles . push ( {
149
- dest : DIST_DIR ,
150
- src : CSS_FILE ,
151
- cwd : SRC_DIR ,
152
- expand : true ,
153
- ext : '.min.css'
154
- } ) ;
155
-
156
- // Add options for concat and uglify
157
- filesToBuild . concat . options = {
158
- banner : "<%= meta.banner %>"
159
- } ;
160
- filesToBuild . uglify . options = {
161
- banner : "<%= meta.banner %>"
162
- } ;
163
-
164
- // Add main script to uglify
165
- filesToBuild . uglify [ MAIN_PLUGIN_FILE + '.js' ] = {
166
- src : MAIN_PLUGIN_FILE + '.js' ,
167
- expand : true ,
168
- extDot : 'last' ,
169
- ext : '.min.js'
170
- } ;
171
164
172
- initializeGruntConfig ( grunt , filesToBuild ) ;
165
+ initializeGruntConfig ( grunt ) ;
173
166
/*
174
167
* Change to new version or the next version number. The project must be built again after this task
175
168
* in order for the version change to take effect.
@@ -199,6 +192,7 @@ module.exports = function (grunt) {
199
192
200
193
grunt . loadNpmTasks ( 'grunt-contrib-clean' ) ;
201
194
grunt . loadNpmTasks ( "grunt-contrib-concat" ) ;
195
+ grunt . loadNpmTasks ( 'grunt-contrib-copy' ) ;
202
196
grunt . loadNpmTasks ( "grunt-contrib-jshint" ) ;
203
197
grunt . loadNpmTasks ( "grunt-contrib-uglify" ) ;
204
198
grunt . loadNpmTasks ( "grunt-contrib-watch" ) ;
@@ -208,7 +202,7 @@ module.exports = function (grunt) {
208
202
grunt . loadNpmTasks ( 'grunt-umd' ) ;
209
203
210
204
grunt . registerTask ( "build-production" , [ "version" , "test" , "uglify" ] ) ;
211
- grunt . registerTask ( 'test' , [ 'concat' , 'umd' , 'cssmin' , 'jshint' , 'qunit' ] ) ;
205
+ grunt . registerTask ( 'test' , [ 'concat' , 'copy' , ' umd', 'cssmin' , 'jshint' , 'qunit' ] ) ;
212
206
grunt . registerTask ( "default" , [ "test" , "watch" ] ) ;
213
207
grunt . registerTask ( "prepublish" , [ "test" , "uglify" ] ) ;
214
208
} ;
0 commit comments