@@ -5,8 +5,9 @@ var fs = require('fs'),
55
66module . exports = function ( grunt ) {
77
8- var BUILD_DIR = 'public/js' ;
9- var DIST_DIR = 'dist' ;
8+ var WEB_ROOT = 'public' ,
9+ BUILD_DIR = path . join ( WEB_ROOT , 'js' ) ,
10+ DIST_DIR = 'dist' ;
1011
1112 // Project configuration.
1213 grunt . initConfig ( {
@@ -15,8 +16,10 @@ module.exports = function(grunt) {
1516 options : {
1617 force : true
1718 } ,
19+ data : [ path . join ( WEB_ROOT , 'data' ) ] ,
1820 build : [ path . join ( DIST_DIR , '**' ) ] ,
19- test : [ path . join ( BUILD_DIR , '**' ) ]
21+ js : [ path . join ( BUILD_DIR , '**' ) ] ,
22+ test : [ path . join ( BUILD_DIR , 'jasmine-bundle.js' ) ]
2023 } ,
2124 "jasmine" :{
2225 browser : {
@@ -29,31 +32,34 @@ module.exports = function(grunt) {
2932 options :{
3033 debug : false
3134 } ,
32- src : [ path . join ( " src" , "** .js" ) ] ,
33- dest : path . join ( DIST_DIR , "LW-lib .js" )
35+ src : [ path . join ( ' src' , 'index .js' ) ] ,
36+ dest : path . join ( DIST_DIR , 'LW .js' )
3437 } ,
3538 debug : {
3639 options : {
3740 debug : true
3841 } ,
39- src : [ path . join ( " src" , "** .js" ) ] ,
40- dest : path . join ( DIST_DIR , " LW-lib- debug.js" )
42+ src : [ path . join ( ' src' , 'index .js' ) ] ,
43+ dest : path . join ( DIST_DIR , ' LW-debug.js' )
4144 }
4245 } ,
4346 watch :{
4447 options : {
4548 livereload : true
4649 } ,
4750 test : {
48- files : [ 'src/**/*.js' , 'spec/**/*.js' ] ,
49- tasks : [ 'test' ]
51+ files : [ path . join ( 'src' , '**' , '*.js' ) , path . join ( 'spec' , '**' , '*.js' ) ] ,
52+ tasks : [ 'build' , 'test' ]
53+ } ,
54+ html : {
55+ files : [ path . join ( WEB_ROOT , '**' , '*.html' ) ]
5056 }
5157 } ,
5258 connect :{
53- dev : {
59+ test : {
5460 options : {
5561 base : {
56- path : 'public' ,
62+ path : WEB_ROOT ,
5763 options : {
5864 index : 'SpecRunner.html'
5965 }
@@ -63,13 +69,41 @@ module.exports = function(grunt) {
6369 open : true ,
6470 useAvailablePort : true ,
6571 }
72+ } ,
73+ demo : {
74+ options : {
75+ base : {
76+ path : WEB_ROOT ,
77+ options : {
78+ index : 'demo.html'
79+ }
80+ } ,
81+ hostname : '*' ,
82+ livereload : true ,
83+ open : true ,
84+ useAvailablePort : true ,
85+ }
86+ }
87+ } ,
88+ copy : {
89+ data : {
90+ expand : true ,
91+ src : path . join ( 'data' , "*" ) ,
92+ dest : WEB_ROOT
93+ } ,
94+ js : {
95+ expand : true ,
96+ flatten : true ,
97+ src : path . join ( DIST_DIR , "*" ) ,
98+ dest : path . join ( WEB_ROOT , 'js' )
6699 }
67100 }
68101 } ) ;
69102
70103 // Load grunt tasks
71104 grunt . loadNpmTasks ( 'grunt-contrib-clean' ) ;
72105 grunt . loadNpmTasks ( 'grunt-contrib-connect' ) ;
106+ grunt . loadNpmTasks ( 'grunt-contrib-copy' ) ;
73107 grunt . loadNpmTasks ( 'grunt-contrib-watch' ) ;
74108
75109 // Custom tasks
@@ -79,8 +113,8 @@ module.exports = function(grunt) {
79113 if ( i < dir . length ) {
80114 var cwd = dir . slice ( 0 , i + 1 ) ;
81115 var dirPath = cwd . join ( path . sep ) ;
82- if ( / v 0 \. 1 0 \. \d + / . test ( process . version ) ) {
83- // node version is 0.10 .x
116+ if ( / v 0 \. 1 \d \. \d + / . test ( process . version ) ) {
117+ // node version is 0.1x .x
84118 if ( ! fs . existsSync ( dirPath ) ) {
85119 fs . mkdirSync ( dirPath ) ;
86120 } else {
@@ -110,7 +144,6 @@ module.exports = function(grunt) {
110144
111145 console . log ( "debug: " + opts . debug ) ;
112146
113- //var output = path.join(DIST_DIR,'app-bundle'+ (opts.debug ? '-debug' : '')+'.js');
114147 var output = this . files [ 0 ] . dest ;
115148
116149 mkDirs ( DIST_DIR ) ;
@@ -122,11 +155,12 @@ module.exports = function(grunt) {
122155 entries : this . filesSrc ,
123156 noParse : [ ] ,
124157 browserField : false ,
125- debug : opts . debug
158+ debug : opts . debug ,
159+ standalone : 'LW'
126160 } ) ;
127161
128162 // prevents file from being loaded into bundle
129- b . external ( "node-localstorage" ) ;
163+ b . exclude ( "node-localstorage" ) ;
130164
131165 var done = this . async ( ) ;
132166 var outputFile = fs . createWriteStream ( output ) ;
@@ -163,7 +197,7 @@ module.exports = function(grunt) {
163197 } ) ;
164198
165199 // prevents file from being loaded into bundle
166- b . external ( "node-localstorage" ) ;
200+ b . exclude ( "node-localstorage" ) ;
167201
168202 var done = this . async ( ) ;
169203 var outputFile = fs . createWriteStream ( output ) ;
@@ -176,9 +210,10 @@ module.exports = function(grunt) {
176210 } ) ;
177211
178212 grunt . registerTask ( 'build' , [ 'clean:build' , 'js' ] ) ;
213+ grunt . registerTask ( 'demo' , [ 'build' , 'copy' ] ) ;
179214 grunt . registerTask ( 'test' , [ 'clean:test' , 'jasmine' ] ) ;
180215
181216 // Default task(s).
182- grunt . registerTask ( 'default' , [ 'build ' , 'test' , 'connect' , 'watch' ] ) ;
217+ grunt . registerTask ( 'default' , [ 'demo ' , 'test' , 'connect' , 'watch' ] ) ;
183218
184219} ;
0 commit comments