@@ -4,15 +4,17 @@ var path = require('path');
44var CleanCSS = require ( 'clean-css' ) ;
55var commands = require ( 'commander' ) ;
66
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' ) ) ;
99 var buildVersion = JSON . parse ( packageConfig ) . version ;
1010 var fromStdin ;
1111 var debugMode ;
1212 var options ;
1313 var stdin ;
1414 var data ;
1515
16+ beforeMinifyCallback = beforeMinifyCallback || Function . prototype
17+
1618 // Specify commander options to parse command line params correctly
1719 commands
1820 . version ( buildVersion , '-v, --version' )
@@ -153,7 +155,7 @@ function cli(process) {
153155
154156 // ... and do the magic!
155157 if ( commands . args . length > 0 ) {
156- minify ( process , options , debugMode , commands . args ) ;
158+ minify ( process , beforeMinifyCallback , options , debugMode , commands . args ) ;
157159 } else {
158160 stdin = process . openStdin ( ) ;
159161 stdin . setEncoding ( 'utf-8' ) ;
@@ -162,7 +164,7 @@ function cli(process) {
162164 data += chunk ;
163165 } ) ;
164166 stdin . on ( 'end' , function ( ) {
165- minify ( process , options , debugMode , data ) ;
167+ minify ( process , beforeMinifyCallback , options , debugMode , data ) ;
166168 } ) ;
167169 }
168170}
@@ -195,8 +197,11 @@ function findArgumentTo(option, rawArgs, args) {
195197 return value ;
196198}
197199
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 ) {
200205 var mapFilename ;
201206
202207 if ( debugMode ) {
0 commit comments