@@ -17,6 +17,7 @@ var pkg = require("../package")
1717program
1818 . version ( pkg . version )
1919 . usage ( "[options] [<input> [<output>]]" )
20+ . option ( "-C, --config <file>" , "use the config file" )
2021 . option ( "-I, --no-import" , "do not inline @import" )
2122 . option ( "-U, --no-url" , "do not adjust url()" )
2223 . option ( "-c, --compress" , "compress output" )
@@ -54,6 +55,27 @@ program.on("--help", function() {
5455
5556program . parse ( process . argv )
5657
58+ var config = program . config ? require ( path . resolve ( program . config ) ) : { }
59+ if ( ! config . features ) {
60+ config . features = { }
61+ }
62+ // command line flags override config file
63+ Object . keys ( cssnext . features ) . forEach ( function ( feature ) {
64+ if ( typeof config . features [ feature ] === "object" ) {
65+ if ( program [ feature ] === false ) {
66+ config . features [ feature ] = false
67+ }
68+ }
69+ else {
70+ config . features [ feature ] = program [ feature ]
71+ }
72+ } )
73+ if ( "import" in program ) { config . import = program . import }
74+ if ( "url" in program ) { config . url = program . url }
75+ if ( "sourcemap" in program ) { config . sourcemap = program . sourcemap }
76+ if ( "compress" in program ) { config . compress = program . compress }
77+ if ( "watch" in program ) { config . watch = program . watch }
78+
5779var input = program . args [ 0 ] ? path . resolve ( program . args [ 0 ] ) : null
5880var output = program . args [ 1 ] ? path . resolve ( program . args [ 1 ] ) : null
5981var verbose = program . verbose
@@ -63,21 +85,16 @@ if (input && !fs.existsSync(input)) {
6385 exit ( 1 )
6486}
6587
88+ config . from = input
89+
6690function transform ( ) {
6791 require ( "read-file-stdin" ) ( input , function ( err , buffer ) {
6892 if ( err ) {
6993 throw err
7094 }
7195
7296 try {
73- var css = cssnext ( buffer . toString ( ) , {
74- features : program ,
75- from : input ,
76- import : program . import ,
77- url : program . url ,
78- sourcemap : program . sourcemap ,
79- compress : program . compress
80- } )
97+ var css = cssnext ( buffer . toString ( ) , config )
8198
8299 require ( "write-file-stdout" ) ( output , css )
83100 if ( verbose && output ) {
@@ -96,7 +113,7 @@ function transform() {
96113 console . error ( "If this error looks like a bug, please report it here:" )
97114 console . error ( colors . grey ( "❯ " ) + pkg . bugs . url . cyan )
98115 console . error ( )
99- if ( ! program . watch ) {
116+ if ( ! config . watch ) {
100117 exit ( 2 )
101118 }
102119 }
@@ -105,7 +122,7 @@ function transform() {
105122
106123transform ( )
107124
108- if ( program . watch ) {
125+ if ( config . watch ) {
109126 if ( ! input || ! output ) {
110127 console . error ( colors . red ( "--watch option need both <input> & <output> files to work" ) )
111128 exit ( 3 )
0 commit comments