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
@@ -78,98 +119,47 @@ function initializeGruntConfig(grunt, filesToBuild) {
78
119
}
79
120
}
80
121
} ,
81
-
122
+ copy : {
123
+ main : {
124
+ files : [
125
+ {
126
+ src : SRC_DIR + '/' + CSS_FILE ,
127
+ dest : DIST_DIR + '/' + CSS_FILE
128
+ } ,
129
+ {
130
+ cwd : SRC_DIR + '/' + MODULE_DIR ,
131
+ src : '**' ,
132
+ dest : DIST_DIR + '/' ,
133
+ expand : true
134
+ } ,
135
+ {
136
+ cwd : SRC_DIR + '/' + LANG_DIR ,
137
+ src : '**' ,
138
+ dest : DIST_DIR + LANG_DIR + '/' ,
139
+ expand : true
140
+ } ]
141
+ }
142
+ } ,
82
143
clean : [ DIST_DIR + '/' ] ,
83
144
umd : {
84
145
main : {
85
146
options : {
86
- src : MAIN_PLUGIN_FILE + '.js' ,
147
+ src : DIST_DIR + '/**/*.js' ,
148
+ dest : './' ,
87
149
deps : {
88
150
default : [ 'jQuery' ] ,
89
151
amd : [ { 'jquery' : 'jQuery' } ] ,
90
152
cjs : [ { 'jquery' : 'jQuery' } ]
91
153
}
92
154
}
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
155
}
104
156
}
105
157
} ) ;
106
158
}
107
159
108
160
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
161
172
- initializeGruntConfig ( grunt , filesToBuild ) ;
162
+ initializeGruntConfig ( grunt ) ;
173
163
/*
174
164
* Change to new version or the next version number. The project must be built again after this task
175
165
* in order for the version change to take effect.
@@ -199,6 +189,7 @@ module.exports = function (grunt) {
199
189
200
190
grunt . loadNpmTasks ( 'grunt-contrib-clean' ) ;
201
191
grunt . loadNpmTasks ( "grunt-contrib-concat" ) ;
192
+ grunt . loadNpmTasks ( 'grunt-contrib-copy' ) ;
202
193
grunt . loadNpmTasks ( "grunt-contrib-jshint" ) ;
203
194
grunt . loadNpmTasks ( "grunt-contrib-uglify" ) ;
204
195
grunt . loadNpmTasks ( "grunt-contrib-watch" ) ;
@@ -208,7 +199,7 @@ module.exports = function (grunt) {
208
199
grunt . loadNpmTasks ( 'grunt-umd' ) ;
209
200
210
201
grunt . registerTask ( "build-production" , [ "version" , "test" , "uglify" ] ) ;
211
- grunt . registerTask ( 'test' , [ 'concat' , 'umd' , 'cssmin' , 'jshint' , 'qunit' ] ) ;
202
+ grunt . registerTask ( 'test' , [ 'concat' , 'copy' , ' umd', 'cssmin' , 'jshint' , 'qunit' ] ) ;
212
203
grunt . registerTask ( "default" , [ "test" , "watch" ] ) ;
213
204
grunt . registerTask ( "prepublish" , [ "test" , "uglify" ] ) ;
214
205
} ;
0 commit comments