53
53
version bool
54
54
watch bool
55
55
sync bool
56
+ bundle bool
56
57
)
57
58
58
59
type Task struct {
@@ -120,6 +121,7 @@ func run() int {
120
121
flag .BoolVarP (& verbose , "verbose" , "v" , false , "Verbose" )
121
122
flag .BoolVarP (& watch , "watch" , "w" , false , "Watch files and minify upon changes" )
122
123
flag .BoolVarP (& sync , "sync" , "s" , false , "Copy all files to destination directory and minify when filetype matches" )
124
+ flag .BoolVarP (& bundle , "bundle" , "b" , false , "Bundle files by concatenation into a single file" )
123
125
flag .BoolVarP (& version , "version" , "" , false , "Version" )
124
126
125
127
flag .StringVar (& siteurl , "url" , "" , "URL of file to enable URL minification" )
@@ -144,14 +146,14 @@ func run() int {
144
146
fmt .Printf ("Try 'minify --help' for more information\n " )
145
147
return 1
146
148
}
147
- rawInputs := flag .Args ()
148
- useStdin := len (rawInputs ) == 0
149
+ inputs := flag .Args ()
150
+ useStdin := len (inputs ) == 0
149
151
150
152
Error = log .New (os .Stderr , "ERROR: " , 0 )
151
153
if verbose {
152
- Info = log .New (os .Stderr , "INFO: " , 0 )
154
+ Info = log .New (os .Stderr , "" , 0 )
153
155
} else {
154
- Info = log .New (ioutil .Discard , "INFO: " , 0 )
156
+ Info = log .New (ioutil .Discard , "" , 0 )
155
157
}
156
158
157
159
if help {
@@ -259,13 +261,14 @@ func run() int {
259
261
// set output, empty means stdout, ending in slash means a directory, otherwise a file
260
262
dirDst := false
261
263
if output != "" {
264
+ if ! bundle && 1 < len (inputs ) && output [len (output )- 1 ] != '/' {
265
+ output += "/"
266
+ }
262
267
output = sanitizePath (output )
263
- if output [len (output )- 1 ] == '/' {
264
- dirDst = true
265
- if err := os .MkdirAll (output , 0777 ); err != nil {
266
- Error .Println (err )
267
- return 1
268
- }
268
+ dirDst = output [len (output )- 1 ] == '/'
269
+ if dirDst && bundle {
270
+ Error .Println ("--bundle requires destination to be stdout or a file" )
271
+ return 1
269
272
}
270
273
}
271
274
if ! dirDst && (sync || watch ) {
@@ -291,6 +294,12 @@ func run() int {
291
294
Info .Println ("minify from stdin" )
292
295
}
293
296
}
297
+ if dirDst {
298
+ if err := os .MkdirAll (output , 0777 ); err != nil {
299
+ Error .Println (err )
300
+ return 1
301
+ }
302
+ }
294
303
295
304
var tasks []Task
296
305
var roots []string
@@ -303,7 +312,7 @@ func run() int {
303
312
tasks = append (tasks , task )
304
313
roots = append (roots , "" )
305
314
} else {
306
- tasks , roots , err = createTasks (rawInputs , output )
315
+ tasks , roots , err = createTasks (inputs , output )
307
316
if err != nil {
308
317
Error .Println (err )
309
318
return 1
0 commit comments