@@ -20,14 +20,18 @@ include __DIR__ . '/../scss.inc.php';
2020
2121use Leafo \ScssPhp \Compiler ;
2222use Leafo \ScssPhp \Parser ;
23+ use Leafo \ScssPhp \SourceMap ;
2324use Leafo \ScssPhp \Version ;
2425
25- $ style = null ;
26- $ loadPaths = null ;
2726$ precision = null ;
27+ $ style = null ;
2828$ dumpTree = false ;
29- $ inputFile = null ;
29+ $ loadPaths = null ;
3030$ changeDir = false ;
31+ $ inputFile = null ;
32+ $ outputFile = null ;
33+ $ sourceMapFile = null ;
34+ $ sourceMap = SourceMap::NONE ;
3135$ debugInfo = false ;
3236$ lineNumbers = false ;
3337
@@ -63,18 +67,20 @@ for ($i = 1; $i < $argc; $i++) {
6367 $ exe = $ argv [0 ];
6468
6569 $ HELP = <<<EOT
66- Usage: $ exe [options] [input-file]
70+ Usage: $ exe [options] [input-file [output-file.css [sourcemap-file.map]] ]
6771
6872Options include:
6973
70- --debug-info Annotate selectors with CSS referring to the source file and line number
71- -h, --help Show this message
72- -f=format Set the output format (compact, compressed, crunched, expanded, or nested)
73- -i=path Set import path
74- --line-numbers Annotate selectors with comments referring to the source file and line number
75- -p=precision Set decimal number precision (default 5)
76- -T Dump formatted parse tree
77- -v, --version Print the version
74+ --debug-info Annotate selectors with CSS referring to the source file and line number
75+ -h, --help Show this message
76+ -f=format Set the output format (compact, compressed, crunched, expanded, or nested)
77+ -i=path Set import path
78+ --line-numbers Annotate selectors with comments referring to the source file and line number
79+ -p=precision Set decimal number precision (default 5)
80+ --sourcemap Generate sourcemap (default: auto)
81+ --sourcemap=option Set the sourcmap option (auto, file, inline, or none)
82+ -T Dump formatted parse tree
83+ -v, --version Print the version
7884
7985EOT ;
8086 exit ($ HELP );
99105 continue ;
100106 }
101107
108+ if ($ argv [$ i ] === '--sourcemap ' ) {
109+ $ sourceMap = SourceMap::AUTO ;
110+ continue ;
111+ }
112+
113+ $ value = parseArgument ($ i , array ('--sourcemap ' ));
114+
115+ if (isset ($ value )) {
116+ $ sourceMap = $ value ;
117+ continue ;
118+ }
119+
102120 $ value = parseArgument ($ i , array ('-f ' , '--style ' ));
103121
104122 if (isset ($ value )) {
@@ -120,12 +138,35 @@ EOT;
120138 continue ;
121139 }
122140
123- if (file_exists ( $ argv [ $ i ]) ) {
141+ if ($ inputFile === null ) {
124142 $ inputFile = $ argv [$ i ];
125143 continue ;
126144 }
145+
146+ if ($ outputFile === null ) {
147+ $ outputFile = $ argv [$ i ];
148+ continue ;
149+ }
150+
151+ if ($ sourceMapFile === null ) {
152+ $ sourceMapFile = $ argv [$ i ];
153+ continue ;
154+ }
155+
156+ exit ("{$ argv [0 ]}: Unrecognized parameter: {$ argv [$ i ]}\n" );
157+ }
158+
159+ if (! in_array ($ sourceMap , array (SourceMap::NONE , SourceMap::AUTO , SourceMap::FILE , SourceMap::INLINE ))) {
160+ exit ("{$ argv [0 ]}: Unrecognized sourcemap option: $ sourceMap \n" );
127161}
128162
163+ if ($ inputFile ) {
164+ if ($ inputFile === '- ' ) {
165+ $ inputFile = null ;
166+ } elseif (! file_exists ($ inputFile )) {
167+ exit ("{$ argv [0 ]}: Input file: $ inputFile doesn't exist \n" );
168+ }
169+ }
129170
130171if ($ inputFile ) {
131172 $ data = file_get_contents ($ inputFile );
@@ -154,6 +195,7 @@ if ($dumpTree) {
154195}
155196
156197$ scss = new Compiler ();
198+ $ scss ->setSourceMap ($ sourceMap );
157199
158200if ($ debugInfo && $ inputFile ) {
159201 $ scss ->setLineNumberStyle (Compiler::DEBUG_INFO );
0 commit comments