@@ -3,37 +3,48 @@ module.exports = function (grunt) {
3
3
4
4
grunt . initConfig ( {
5
5
6
+ pkg : grunt . file . readJSON ( 'package.json' ) ,
7
+
6
8
path : {
7
9
// Source folders
8
10
app : 'app' ,
9
- app_js : 'app/app-js' ,
10
- less : 'app/less' ,
11
+ app_appjs : 'app/app-js' ,
12
+ app_style : 'app/less' ,
13
+ app_vendor : 'app/vendor' ,
11
14
12
15
// Intermediate folders (transient)
13
16
temp : 'temp' ,
17
+ bower : 'bower_components' ,
14
18
15
19
// Output folders (transient)
16
20
dist : 'dist' ,
21
+ dist_appjs : 'dist/app-js' ,
17
22
dist_style : 'dist/style' ,
18
23
dist_vendor : 'dist/vendor'
19
24
} ,
20
25
21
26
clean : {
22
- dist : [ '<%- path.dist %>' , '<%- path.temp %>' ]
27
+ all : [
28
+ '<%- path.app_vendor %>' ,
29
+ '<%- path.dist %>' ,
30
+ '<%- path.temp %>' ,
31
+ '<%- path.bower %>'
32
+ ]
23
33
} ,
24
34
25
35
less : {
26
36
options : {
27
37
paths : [
28
- '<%- path.dist_vendor %>' ,
38
+ '<%- path.app_vendor %>' ,
29
39
'<%- path.temp %>'
30
- ]
40
+ ] ,
41
+ cleancss : false
31
42
} ,
32
43
33
44
precompile : {
34
45
files : {
35
46
'<%- path.temp %>/engine-ui-grid-precompile.less' :
36
- '<%- path.less %>/engine-ui-grid.less'
47
+ '<%- path.app_style %>/engine-ui-grid.less'
37
48
}
38
49
} ,
39
50
@@ -45,16 +56,15 @@ module.exports = function (grunt) {
45
56
} ,
46
57
files : {
47
58
'<%- path.dist_style %>/hosted-apis.css' :
48
- '<%- path.less %>/hosted-apis.less'
59
+ '<%- path.app_style %>/hosted-apis.less'
49
60
}
50
61
}
51
62
} ,
52
63
53
64
bower : {
54
65
install : {
55
66
options : {
56
- targetDir : '<%- path.dist_vendor %>' ,
57
- verbose : true ,
67
+ targetDir : '<%- path.app_vendor %>' ,
58
68
layout : 'byComponent' ,
59
69
bowerOptions : {
60
70
production : true
@@ -63,20 +73,47 @@ module.exports = function (grunt) {
63
73
}
64
74
} ,
65
75
76
+ copy : {
77
+ prod : {
78
+ expand : true ,
79
+ cwd : '<%- path.app %>' ,
80
+ src : [
81
+ 'img/**/*' ,
82
+ '**/font/**/*'
83
+ ] ,
84
+ dest : '<%- path.dist %>'
85
+ } ,
86
+
87
+ prod_versioned : {
88
+ expand : true ,
89
+ cwd : '<%- path.app %>' ,
90
+ src : [ 'index.html' ] ,
91
+ dest : '<%- path.dist %>' ,
92
+ options : {
93
+ process : function ( content ) {
94
+ return content
95
+ . replace ( / \{ v e r s i o n \} / g, grunt . config . data . pkg . version )
96
+ . replace ( 'src="vendor/requirejs/require.js" data-main="app-js/app-require.js"' ,
97
+ 'src="app.js?v=' + grunt . config . data . pkg . version + '"' ) ;
98
+ }
99
+ }
100
+ }
101
+ } ,
102
+
66
103
shell : {
67
104
options : {
68
105
stdout : true ,
69
106
stderr : true ,
70
107
failOnError : true
71
108
} ,
72
109
73
- sync_app : {
110
+ sync_dev : {
74
111
command : [
75
112
'cwd=$(pwd)' ,
76
113
'cd <%- path.app %>' ,
77
114
'rsync . $cwd/<%- path.dist %> ' +
78
115
'--update --delete --verbose --recursive ' +
79
- '--exclude less --exclude style --exclude vendor '
116
+ '--exclude ./ less --exclude ./ style'
80
117
] . join ( '&&' )
81
118
} ,
82
119
@@ -90,20 +127,40 @@ module.exports = function (grunt) {
90
127
}
91
128
} ,
92
129
130
+ requirejs : {
131
+ prod : {
132
+ options : {
133
+ baseUrl : '<%- path.app_appjs %>' ,
134
+ out : '<%- path.dist %>/app.js' ,
135
+ mainConfigFile : '<%- path.app_appjs %>/app-require.js' ,
136
+ name : '../vendor/almond/almond' ,
137
+ include : [ 'app-start' ] ,
138
+ stubModules : [ 'text' , 'hgn' ] ,
139
+ optimize : 'uglify2' ,
140
+ preserveLicenseComments : false ,
141
+ insertRequire : [ 'app-start' ] ,
142
+ paths : {
143
+ 'lib/logger' : 'lib/logger-prod' ,
144
+ 'lib/eventDebugger' : 'lib/eventDebugger-prod'
145
+ }
146
+ }
147
+ }
148
+ } ,
149
+
93
150
jshint : {
94
151
options : {
95
152
jshintrc : true
96
153
} ,
97
154
98
- app : [ 'Gruntfile.js' , '<%- path.app_js %>/**/*.js' ]
155
+ app : [ 'Gruntfile.js' , '<%- path.app_appjs %>/**/*.js' ]
99
156
} ,
100
157
101
158
jscs : {
102
159
options : {
103
- config : '<%- path.app_js %>/.jscsrc'
160
+ config : '<%- path.app_appjs %>/.jscsrc'
104
161
} ,
105
162
106
- app : [ 'Gruntfile.js' , '<%- path.app_js %>/**/*.js' ]
163
+ app : [ 'Gruntfile.js' , '<%- path.app_appjs %>/**/*.js' ]
107
164
} ,
108
165
109
166
watch : {
@@ -114,14 +171,14 @@ module.exports = function (grunt) {
114
171
app : {
115
172
files : [
116
173
'<%- path.app %>/**/*' ,
117
- '!<%- path.less %>/**/*'
174
+ '!<%- path.app_style %>/**/*'
118
175
] ,
119
- tasks : [ 'shell:sync_app ' ]
176
+ tasks : [ 'shell:sync_dev ' ]
120
177
} ,
121
178
122
179
less : {
123
180
files : [
124
- '<%- path.less %>/**/*' ,
181
+ '<%- path.app_style %>/**/*' ,
125
182
'<%- path.dist_vendor %>/engine-ui/less/**/*'
126
183
] ,
127
184
tasks : [ 'less:app' ]
@@ -146,12 +203,26 @@ module.exports = function (grunt) {
146
203
// bring in all grunt plugins from package.json
147
204
require ( 'load-grunt-tasks' ) ( grunt ) ;
148
205
149
- grunt . registerTask ( 'dist-dev' , [
150
- 'shell:sync_app' ,
206
+ grunt . registerTask ( 'set-prod' , function ( ) {
207
+ grunt . config . data . less . options . cleancss = true ;
208
+ grunt . config . data . less . app . options . sourceMap = false ;
209
+ } ) ;
210
+
211
+ grunt . registerTask ( 'build-dev' , [
151
212
'bower' ,
213
+ 'shell:sync_dev' ,
152
214
'less' ,
153
215
'shell:sourcemap_links'
154
216
] ) ;
155
217
156
- grunt . registerTask ( 'default' , [ 'dist-dev' ] ) ;
218
+ grunt . registerTask ( 'build-prod' , [
219
+ 'set-prod' ,
220
+ 'clean' ,
221
+ 'bower' ,
222
+ 'copy' ,
223
+ 'less' ,
224
+ 'requirejs'
225
+ ] ) ;
226
+
227
+ grunt . registerTask ( 'default' , [ 'build-dev' ] ) ;
157
228
} ;
0 commit comments