@@ -88,7 +88,30 @@ int output(int error_status, const char* error_message, const char* output_strin
88
88
}
89
89
}
90
90
91
- int compile_stdin (struct Sass_Options * options , char * outfile ) {
91
+ int write_depsfile (struct Sass_Context * ctx_out , char * deps_outfile ) {
92
+ size_t i ;
93
+
94
+ FILE * fp = fopen (deps_outfile , "wb" );
95
+ if (!fp ) {
96
+ perror ("Error opening deps output file" );
97
+ return 1 ;
98
+ }
99
+
100
+ char * * included_files = sass_context_get_included_files (ctx_out );
101
+ size_t num_included_files = sass_context_get_included_files_size (ctx_out );
102
+ for (i = 0 ; i < num_included_files ; ++ i ) {
103
+ if (fprintf (fp , "%s\n" , included_files [i ]) < 0 ) {
104
+ perror ("Error writing to deps output file" );
105
+ fclose (fp );
106
+ return 1 ;
107
+ }
108
+ }
109
+
110
+ fclose (fp );
111
+ return 0 ;
112
+ }
113
+
114
+ int compile_stdin (struct Sass_Options * options , char * outfile , char * deps_outfile ) {
92
115
int ret ;
93
116
struct Sass_Data_Context * ctx ;
94
117
char buffer [BUFSIZE ];
@@ -142,11 +165,16 @@ int compile_stdin(struct Sass_Options* options, char* outfile) {
142
165
sass_context_get_output_string (ctx_out ),
143
166
outfile
144
167
);
168
+
169
+ if (ret == 0 && deps_outfile ) {
170
+ ret = write_depsfile (ctx_out , deps_outfile );
171
+ }
172
+
145
173
sass_delete_data_context (ctx );
146
174
return ret ;
147
175
}
148
176
149
- int compile_file (struct Sass_Options * options , char * input_path , char * outfile ) {
177
+ int compile_file (struct Sass_Options * options , char * input_path , char * outfile , char * deps_outfile ) {
150
178
int ret ;
151
179
struct Sass_File_Context * ctx = sass_make_file_context (input_path );
152
180
struct Sass_Context * ctx_out = sass_file_context_get_context (ctx );
@@ -173,6 +201,10 @@ int compile_file(struct Sass_Options* options, char* input_path, char* outfile)
173
201
);
174
202
}
175
203
204
+ if (ret == 0 && deps_outfile ) {
205
+ ret = write_depsfile (ctx_out , deps_outfile );
206
+ }
207
+
176
208
sass_delete_file_context (ctx );
177
209
return ret ;
178
210
}
@@ -208,16 +240,17 @@ void print_usage(char* argv0) {
208
240
printf (" %s" , style_option_strings [i ].style_string );
209
241
printf (i == 0 ? ".\n" : "," );
210
242
}
211
- printf (" -l, --line-numbers Emit comments showing original line numbers.\n" );
243
+ printf (" -l, --line-numbers Emit comments showing original line numbers.\n" );
212
244
printf (" --line-comments\n" );
213
- printf (" -I, --load-path PATH Set Sass import path.\n" );
214
- printf (" -P, --plugin-path PATH Set path to autoload plugins.\n" );
215
- printf (" -m, --sourcemap[=TYPE] Emit source map (auto or inline).\n" );
216
- printf (" -M, --omit-map-comment Omits the source map url comment.\n" );
217
- printf (" -p, --precision Set the precision for numbers.\n" );
218
- printf (" -a, --sass Treat input as indented syntax.\n" );
219
- printf (" -v, --version Display compiled versions.\n" );
220
- printf (" -h, --help Display this help message.\n" );
245
+ printf (" -I, --load-path PATH Set Sass import path.\n" );
246
+ printf (" -D, --write-includes FILE Write a file containing the dependencies that were imported.\n" );
247
+ printf (" -P, --plugin-path PATH Set path to autoload plugins.\n" );
248
+ printf (" -m, --sourcemap[=TYPE] Emit source map (auto or inline).\n" );
249
+ printf (" -M, --omit-map-comment Omits the source map url comment.\n" );
250
+ printf (" -p, --precision Set the precision for numbers.\n" );
251
+ printf (" -a, --sass Treat input as indented syntax.\n" );
252
+ printf (" -v, --version Display compiled versions.\n" );
253
+ printf (" -h, --help Display this help message.\n" );
221
254
printf ("\n" );
222
255
}
223
256
@@ -245,6 +278,7 @@ int main(int argc, char** argv) {
245
278
}
246
279
247
280
char * outfile = 0 ;
281
+ char * deps_outfile = 0 ;
248
282
int from_stdin = 0 ;
249
283
bool auto_source_map = false;
250
284
bool generate_source_map = false;
@@ -259,6 +293,7 @@ int main(int argc, char** argv) {
259
293
{
260
294
{ "stdin" , no_argument , 0 , 's' },
261
295
{ "load-path" , required_argument , 0 , 'I' },
296
+ { "write-includes" , required_argument , 0 , 'D' },
262
297
{ "plugin-path" , required_argument , 0 , 'P' },
263
298
{ "style" , required_argument , 0 , 't' },
264
299
{ "line-numbers" , no_argument , 0 , 'l' },
@@ -271,14 +306,17 @@ int main(int argc, char** argv) {
271
306
{ "help" , no_argument , 0 , 'h' },
272
307
{ NULL , 0 , NULL , 0 }
273
308
};
274
- while ((c = getopt_long (argc , argv , "vhslm::Map:t:I:P:" , long_options , & long_index )) != -1 ) {
309
+ while ((c = getopt_long (argc , argv , "vhslm::Map:t:I:D: P:" , long_options , & long_index )) != -1 ) {
275
310
switch (c ) {
276
311
case 's' :
277
312
from_stdin = 1 ;
278
313
break ;
279
314
case 'I' :
280
315
sass_option_push_include_path (options , optarg );
281
316
break ;
317
+ case 'D' :
318
+ deps_outfile = optarg ;
319
+ break ;
282
320
case 'P' :
283
321
sass_option_push_plugin_path (options , optarg );
284
322
break ;
@@ -367,12 +405,12 @@ int main(int argc, char** argv) {
367
405
} else if (auto_source_map ) {
368
406
sass_option_set_source_map_embed (options , true);
369
407
}
370
- result = compile_file (options , argv [optind ], outfile );
408
+ result = compile_file (options , argv [optind ], outfile , deps_outfile );
371
409
} else {
372
410
if (optind < argc ) {
373
411
outfile = argv [optind ];
374
412
}
375
- result = compile_stdin (options , outfile );
413
+ result = compile_stdin (options , outfile , deps_outfile );
376
414
}
377
415
378
416
sass_delete_options (options );
0 commit comments