11//TODO: During next major version bump change to /dist. Leaving at ./form-validator for backwards
2- //compabilitiy
2+ //compatibility
33const DIST_DIR = './form-validator' ;
4- const MAIN_PLUGIN_FILE = 'form-validator/jquery.form-validator.min .js' ;
4+ const MAIN_PLUGIN_FILE = './ form-validator/jquery.form-validator.js' ;
55const SRC_DIR = './src' ;
66const MAIN_DIR = '/main/' ;
77const MODULE_DIR = '/modules/' ;
88const LANG_DIR = '/lang/' ;
99const CSS_FILE = 'theme-default.css' ;
1010
11-
1211var 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- } ,
2212 readFile = function ( file ) {
2313 return fs . readFileSync ( file , 'utf-8' ) ;
2414 } ,
2515 replaceInFile = function ( path , from , to ) {
2616 fs . writeFileSync ( path , readFile ( path ) . replace ( from , to ) ) ;
2717 } ;
2818
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 ) {
7520 grunt . initConfig ( {
7621
7722 // Import package manifest
7823 pkg : grunt . file . readJSON ( "package.json" ) ,
7924
8025 // Banner definitions
8126 meta : {
82- banner : "/**\n" +
27+ banner : "/** File generated by Grunt -- do not modify \n" +
8328 " * <%= (pkg.title || pkg.name).toUpperCase() %>\n" +
8429 " *\n" +
8530 " * @version <%= pkg.version %>\n" +
@@ -93,9 +38,9 @@ module.exports = function (grunt) {
9338 concat : filesToBuild . concat ,
9439
9540 cssmin : {
96- target : {
97- files : filesToBuild . cssFiles
98- }
41+ target : {
42+ files : filesToBuild . cssFiles
43+ }
9944 } ,
10045 // Lint definitions
10146 jshint : {
@@ -115,7 +60,7 @@ module.exports = function (grunt) {
11560 watch : {
11661 files : [ SRC_DIR + '/**' ] ,
11762 tasks : [ 'test' ] ,
118- options : { nospawn : true }
63+ options : { nospawn : true }
11964 } ,
12065
12166 // Unit tests
@@ -132,10 +77,77 @@ module.exports = function (grunt) {
13277 keepalive : true
13378 }
13479 }
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 + '/' ;
135102 }
136103
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 ) ;
122+ }
123+ } ) ;
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'
137132 } ) ;
138133
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 ] = {
144+ src : MAIN_PLUGIN_FILE ,
145+ expand : true ,
146+ extDot : 'last' ,
147+ ext : '.min.js'
148+ } ;
149+
150+ initializeGruntConfig ( grunt , filesToBuild ) ;
139151 /*
140152 * Change to new version or the next version number. The project must be built again after this task
141153 * in order for the version change to take effect.
@@ -163,7 +175,7 @@ module.exports = function (grunt) {
163175 grunt . config . set ( 'pkg' , pkg ) ;
164176 } ) ;
165177
166-
178+ grunt . loadNpmTasks ( 'grunt-contrib-clean' ) ;
167179 grunt . loadNpmTasks ( "grunt-contrib-concat" ) ;
168180 grunt . loadNpmTasks ( "grunt-contrib-jshint" ) ;
169181 grunt . loadNpmTasks ( "grunt-contrib-uglify" ) ;
@@ -174,6 +186,4 @@ module.exports = function (grunt) {
174186 grunt . registerTask ( "build-production" , [ "version" , "cssmin" , "test" , "uglify" ] ) ;
175187 grunt . registerTask ( 'test' , [ 'concat' , 'cssmin' , 'jshint' , 'qunit' ] ) ;
176188 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
179189} ;
0 commit comments