@@ -4,15 +4,17 @@ var path = require('path');
4
4
var CleanCSS = require ( 'clean-css' ) ;
5
5
var commands = require ( 'commander' ) ;
6
6
7
- function cli ( process ) {
8
- var packageConfig = fs . readFileSync ( path . join ( path . dirname ( fs . realpathSync ( process . argv [ 1 ] ) ) , '../ package.json' ) ) ;
7
+ function cli ( process , beforeMinifyCallback ) {
8
+ var packageConfig = fs . readFileSync ( path . join ( __dirname , 'package.json' ) ) ;
9
9
var buildVersion = JSON . parse ( packageConfig ) . version ;
10
10
var fromStdin ;
11
11
var debugMode ;
12
12
var options ;
13
13
var stdin ;
14
14
var data ;
15
15
16
+ beforeMinifyCallback = beforeMinifyCallback || Function . prototype ;
17
+
16
18
// Specify commander options to parse command line params correctly
17
19
commands
18
20
. version ( buildVersion , '-v, --version' )
@@ -153,7 +155,7 @@ function cli(process) {
153
155
154
156
// ... and do the magic!
155
157
if ( commands . args . length > 0 ) {
156
- minify ( process , options , debugMode , commands . args ) ;
158
+ minify ( process , beforeMinifyCallback , options , debugMode , commands . args ) ;
157
159
} else {
158
160
stdin = process . openStdin ( ) ;
159
161
stdin . setEncoding ( 'utf-8' ) ;
@@ -162,7 +164,7 @@ function cli(process) {
162
164
data += chunk ;
163
165
} ) ;
164
166
stdin . on ( 'end' , function ( ) {
165
- minify ( process , options , debugMode , data ) ;
167
+ minify ( process , beforeMinifyCallback , options , debugMode , data ) ;
166
168
} ) ;
167
169
}
168
170
}
@@ -195,8 +197,11 @@ function findArgumentTo(option, rawArgs, args) {
195
197
return value ;
196
198
}
197
199
198
- function minify ( process , options , debugMode , data ) {
199
- new CleanCSS ( options ) . minify ( data , function ( errors , minified ) {
200
+ function minify ( process , beforeMinifyCallback , options , debugMode , data ) {
201
+ var cleanCss = new CleanCSS ( options ) ;
202
+
203
+ beforeMinifyCallback ( cleanCss ) ;
204
+ cleanCss . minify ( data , function ( errors , minified ) {
200
205
var mapFilename ;
201
206
202
207
if ( debugMode ) {
0 commit comments