@@ -27,19 +27,23 @@ else if (minifier === 'uglifyjs') {
27
27
mininfierCmd = 'uglifyjs --output dist/all.min.js dist/all.js' ;
28
28
}
29
29
30
- var includeAllModules = modulesToInclude . length === 1 && modulesToInclude [ 0 ] === 'ALL' ;
31
30
var noStrict = 'no-strict' in buildArgsAsObject ;
32
31
var noSVGExport = 'no-svg-export' in buildArgsAsObject ;
33
32
var noES5Compat = 'no-es5-compat' in buildArgsAsObject ;
34
33
34
+ var buildSh = 'build-sh' in buildArgsAsObject ;
35
+ var buildMinified = 'build-minified' in buildArgsAsObject ;
36
+
37
+ var includeAllModules = ( modulesToInclude . length === 1 && modulesToInclude [ 0 ] === 'ALL' ) || buildMinified ;
38
+
35
39
var distFileContents =
36
40
'/* build: `node build.js modules=' +
37
41
modulesToInclude . join ( ',' ) +
38
42
( modulesToExclude . length ? ( ' exclude=' + modulesToExclude . join ( ',' ) ) : '' ) +
39
43
( noStrict ? ' no-strict' : '' ) +
40
44
( noSVGExport ? ' no-svg-export' : '' ) +
41
45
( noES5Compat ? ' no-es5-compat' : '' ) +
42
- '` */\n ' ;
46
+ '` */' ;
43
47
44
48
function appendFileContents ( fileNames , callback ) {
45
49
@@ -67,7 +71,7 @@ function appendFileContents(fileNames, callback) {
67
71
if ( noES5Compat ) {
68
72
strData = strData . replace ( / \/ \* _ E S 5 _ C O M P A T _ S T A R T _ \* \/ [ \s \S ] * \/ \* _ E S 5 _ C O M P A T _ E N D _ \* \/ / , '' ) ;
69
73
}
70
- distFileContents += ( strData + '\n' ) ;
74
+ distFileContents += ( '\n' + strData + '\n' ) ;
71
75
readNextFile ( ) ;
72
76
} ) ;
73
77
@@ -93,7 +97,6 @@ function ifSpecifiedDependencyInclude(included, excluded, fileName) {
93
97
}
94
98
95
99
var filesToInclude = [
96
-
97
100
'HEADER.js' ,
98
101
99
102
ifSpecifiedDependencyInclude ( 'text' , 'cufon' , 'lib/cufon.js' ) ,
@@ -183,26 +186,58 @@ var filesToInclude = [
183
186
ifSpecifiedInclude ( 'node' , 'src/node.js' )
184
187
] ;
185
188
186
- appendFileContents ( filesToInclude , function ( ) {
187
- fs . writeFile ( 'dist/all.js' , distFileContents , function ( err ) {
188
- if ( err ) {
189
- console . log ( err ) ;
190
- throw err ;
191
- }
189
+ if ( buildMinified ) {
190
+ for ( var i = 0 ; i < filesToInclude . length ; i ++ ) {
191
+ var fileNameWithoutSlashes = filesToInclude [ i ] . replace ( / \/ / g, '^' ) ;
192
192
193
- console . log ( 'Built distribution to dist/all.js' ) ;
193
+ if ( ! filesToInclude [ i ] ) continue ;
194
194
195
- exec ( mininfierCmd , function ( error , output ) {
196
- if ( ! error ) {
197
- console . log ( 'Minified using' , minifier , 'to dist/all.min.js' ) ;
195
+ exec ( 'uglifyjs -nc ' + filesToInclude [ i ] + ' > tmp/' + fileNameWithoutSlashes ) ;
196
+ }
197
+ }
198
+ else if ( buildSh ) {
199
+
200
+ var filesStr = filesToInclude . join ( ' ' ) ;
201
+ var isBasicBuild = modulesToInclude . length === 0 ;
202
+
203
+ var minFilesStr = filesToInclude
204
+ . filter ( function ( f ) { return f !== '' } )
205
+ . map ( function ( fileName ) {
206
+ return 'tmp/' + fileName . replace ( / \/ / g, '^' ) ;
207
+ } )
208
+ . join ( ' ' ) ;
209
+
210
+ var fileName = isBasicBuild ? 'fabric' : modulesToInclude . join ( ',' ) ;
211
+
212
+ var escapedHeader = distFileContents . replace ( / ` / g, '\\`' ) ;
213
+ var path = '../fabricjs.com/build/files/' + fileName + '.js' ;
214
+ fs . appendFile ( 'build.sh' ,
215
+ 'echo "' + escapedHeader + '" > ' + path + ' && cat ' +
216
+ filesStr + ' >> ' + path + '\n' ) ;
217
+
218
+ path = '../fabricjs.com/build/files/' + fileName + '.min.js' ;
219
+ fs . appendFile ( 'build.sh' ,
220
+ 'echo "' + escapedHeader + '" > ' + path + ' && cat ' +
221
+ minFilesStr + ' >> ' + path + '\n' )
222
+ }
223
+ else {
224
+ appendFileContents ( filesToInclude , function ( ) {
225
+ fs . writeFile ( 'dist/all.js' , distFileContents , function ( err ) {
226
+ if ( err ) {
227
+ console . log ( err ) ;
228
+ throw err ;
198
229
}
199
- exec ( 'gzip -c dist/all.min.js > dist/all.min.js.gz' , function ( error , output ) {
200
- console . log ( 'Gzipped to dist/all.min.js.gz' ) ;
201
230
202
- exec ( 'ls -l dist' , function ( error , output ) {
203
- console . log ( output . replace ( / ^ .* / , '' ) ) ;
231
+ console . log ( 'Built distribution to dist/all.js' ) ;
232
+
233
+ exec ( mininfierCmd , function ( error , output ) {
234
+ if ( ! error ) {
235
+ console . log ( 'Minified using' , minifier , 'to dist/all.min.js' ) ;
236
+ }
237
+ exec ( 'gzip -c dist/all.min.js > dist/all.min.js.gz' , function ( error , output ) {
238
+ console . log ( 'Gzipped to dist/all.min.js.gz' ) ;
204
239
} ) ;
205
240
} ) ;
206
241
} ) ;
207
242
} ) ;
208
- } ) ;
243
+ }
0 commit comments