@@ -6,7 +6,6 @@ use clap::Arg;
6
6
use clap:: ArgMatches ;
7
7
use clap:: Shell ;
8
8
use clap:: SubCommand ;
9
- use deno:: ModuleSpecifier ;
10
9
use log:: Level ;
11
10
use std;
12
11
use std:: str;
@@ -259,11 +258,16 @@ compiler.",
259
258
SubCommand :: with_name ( "bundle" )
260
259
. about ( "Bundle module and dependencies into single file" )
261
260
. long_about (
262
- "Output a single JavaScript file with all dependencies
261
+ "Output a single JavaScript file with all dependencies.
262
+
263
+ If a out_file argument is omitted, the output of the bundle will be sent to
264
+ standard out.
263
265
264
266
Example:
265
267
266
- deno bundle https://deno.land/std/examples/colors.ts"
268
+ deno bundle https://deno.land/std/examples/colors.ts
269
+
270
+ deno bundle https://deno.land/std/examples/colors.ts colors.bundle.js"
267
271
)
268
272
. arg ( Arg :: with_name ( "source_file" ) . takes_value ( true ) . required ( true ) )
269
273
. arg ( Arg :: with_name ( "out_file" ) . takes_value ( true ) . required ( false ) ) ,
@@ -335,12 +339,111 @@ This command has implicit access to all permissions (equivalent to deno run --al
335
339
Automatically downloads Prettier dependencies on first run.
336
340
337
341
deno fmt myfile1.ts myfile2.ts" ,
338
- ) . arg (
342
+ )
343
+ . arg (
339
344
Arg :: with_name ( "stdout" )
340
345
. long ( "stdout" )
341
346
. help ( "Output formated code to stdout" )
342
347
. takes_value ( false ) ,
343
- ) . arg (
348
+ )
349
+ . arg (
350
+ Arg :: with_name ( "print-width" )
351
+ . long ( "print-width" )
352
+ . value_name ( "int" )
353
+ . help ( "Specify the line length that the printer will wrap on." )
354
+ . takes_value ( true )
355
+ . require_equals ( true )
356
+ )
357
+ . arg (
358
+ Arg :: with_name ( "tab-width" )
359
+ . long ( "tab-width" )
360
+ . value_name ( "int" )
361
+ . help ( "Specify the number of spaces per indentation-level." )
362
+ . takes_value ( true )
363
+ . require_equals ( true )
364
+ )
365
+ . arg (
366
+ Arg :: with_name ( "use-tabs" )
367
+ . long ( "use-tabs" )
368
+ . help ( "Indent lines with tabs instead of spaces." )
369
+ . takes_value ( false )
370
+ )
371
+ . arg (
372
+ Arg :: with_name ( "no-semi" )
373
+ . long ( "no-semi" )
374
+ . help ( "Print semicolons at the ends of statements." )
375
+ . takes_value ( false )
376
+ )
377
+ . arg (
378
+ Arg :: with_name ( "single-quote" )
379
+ . long ( "single-quote" )
380
+ . help ( "Use single quotes instead of double quotes." )
381
+ . takes_value ( false )
382
+ )
383
+ . arg (
384
+ Arg :: with_name ( "quote-props" )
385
+ . long ( "quote-props" )
386
+ . value_name ( "as-needed|consistent|preserve" )
387
+ . help ( "Change when properties in objects are quoted." )
388
+ . takes_value ( true )
389
+ . possible_values ( & [ "as-needed" , "consistent" , "preserve" ] )
390
+ . require_equals ( true )
391
+ )
392
+ . arg (
393
+ Arg :: with_name ( "jsx-single-quote" )
394
+ . long ( "jsx-single-quote" )
395
+ . help ( "Use single quotes instead of double quotes in JSX." )
396
+ . takes_value ( false )
397
+ )
398
+ . arg (
399
+ Arg :: with_name ( "jsx-bracket-same-line" )
400
+ . long ( "jsx-bracket-same-line" )
401
+ . help (
402
+ "Put the > of a multi-line JSX element at the end of the last line
403
+ instead of being alone on the next line (does not apply to self closing elements)."
404
+ )
405
+ . takes_value ( false )
406
+ )
407
+ . arg (
408
+ Arg :: with_name ( "trailing-comma" )
409
+ . long ( "trailing-comma" )
410
+ . help ( "Print trailing commas wherever possible when multi-line." )
411
+ . takes_value ( false )
412
+ )
413
+ . arg (
414
+ Arg :: with_name ( "no-bracket-spacing" )
415
+ . long ( "no-bracket-spacing" )
416
+ . help ( "Print spaces between brackets in object literals." )
417
+ . takes_value ( false )
418
+ )
419
+ . arg (
420
+ Arg :: with_name ( "arrow-parens" )
421
+ . long ( "arrow-parens" )
422
+ . value_name ( "avoid|always" )
423
+ . help ( "Include parentheses around a sole arrow function parameter." )
424
+ . takes_value ( true )
425
+ . possible_values ( & [ "avoid" , "always" ] )
426
+ . require_equals ( true )
427
+ )
428
+ . arg (
429
+ Arg :: with_name ( "prose-wrap" )
430
+ . long ( "prose-wrap" )
431
+ . value_name ( "always|never|preserve" )
432
+ . help ( "How to wrap prose." )
433
+ . takes_value ( true )
434
+ . possible_values ( & [ "always" , "never" , "preserve" ] )
435
+ . require_equals ( true )
436
+ )
437
+ . arg (
438
+ Arg :: with_name ( "end-of-line" )
439
+ . long ( "end-of-line" )
440
+ . value_name ( "auto|lf|crlf|cr" )
441
+ . help ( "Which end of line characters to apply." )
442
+ . takes_value ( true )
443
+ . possible_values ( & [ "auto" , "lf" , "crlf" , "cr" ] )
444
+ . require_equals ( true )
445
+ )
446
+ . arg (
344
447
Arg :: with_name ( "files" )
345
448
. takes_value ( true )
346
449
. multiple ( true )
@@ -793,32 +896,6 @@ pub enum DenoSubcommand {
793
896
Version ,
794
897
}
795
898
796
- fn get_default_bundle_filename ( source_file : & str ) -> String {
797
- let specifier = ModuleSpecifier :: resolve_url_or_path ( source_file) . unwrap ( ) ;
798
- let path_segments = specifier. as_url ( ) . path_segments ( ) . unwrap ( ) ;
799
- let file_name = path_segments. filter ( |s| !s. is_empty ( ) ) . last ( ) . unwrap ( ) ;
800
- let file_stem = file_name. trim_end_matches ( ".ts" ) . trim_end_matches ( ".js" ) ;
801
- format ! ( "{}.bundle.js" , file_stem)
802
- }
803
-
804
- #[ test]
805
- fn test_get_default_bundle_filename ( ) {
806
- assert_eq ! ( get_default_bundle_filename( "blah.ts" ) , "blah.bundle.js" ) ;
807
- assert_eq ! (
808
- get_default_bundle_filename( "http://example.com/blah.ts" ) ,
809
- "blah.bundle.js"
810
- ) ;
811
- assert_eq ! ( get_default_bundle_filename( "blah.js" ) , "blah.bundle.js" ) ;
812
- assert_eq ! (
813
- get_default_bundle_filename( "http://example.com/blah.js" ) ,
814
- "blah.bundle.js"
815
- ) ;
816
- assert_eq ! (
817
- get_default_bundle_filename( "http://zombo.com/stuff/" ) ,
818
- "stuff.bundle.js"
819
- ) ;
820
- }
821
-
822
899
pub fn flags_from_vec (
823
900
args : Vec < String > ,
824
901
) -> ( DenoFlags , DenoSubcommand , Vec < String > ) {
@@ -835,11 +912,13 @@ pub fn flags_from_vec(
835
912
( "bundle" , Some ( bundle_match) ) => {
836
913
flags. allow_write = true ;
837
914
let source_file: & str = bundle_match. value_of ( "source_file" ) . unwrap ( ) ;
838
- let out_file = bundle_match
839
- . value_of ( "out_file" )
840
- . map ( String :: from)
841
- . unwrap_or_else ( || get_default_bundle_filename ( source_file) ) ;
842
- argv. extend ( vec ! [ source_file. to_string( ) , out_file. to_string( ) ] ) ;
915
+ let out_file = bundle_match. value_of ( "out_file" ) . map ( String :: from) ;
916
+ match out_file {
917
+ Some ( out_file) => {
918
+ argv. extend ( vec ! [ source_file. to_string( ) , out_file. to_string( ) ] )
919
+ }
920
+ _ => argv. extend ( vec ! [ source_file. to_string( ) ] ) ,
921
+ }
843
922
DenoSubcommand :: Bundle
844
923
}
845
924
( "completions" , Some ( completions_match) ) => {
@@ -886,6 +965,36 @@ pub fn flags_from_vec(
886
965
argv. push ( "--write" . to_string ( ) ) ;
887
966
}
888
967
968
+ let prettier_flags = [
969
+ [ "1" , "print-width" ] ,
970
+ [ "1" , "tab-width" ] ,
971
+ [ "0" , "use-tabs" ] ,
972
+ [ "0" , "no-semi" ] ,
973
+ [ "0" , "single-quote" ] ,
974
+ [ "1" , "quote-props" ] ,
975
+ [ "0" , "jsx-single-quote" ] ,
976
+ [ "0" , "jsx-bracket-same-line" ] ,
977
+ [ "0" , "trailing-comma" ] ,
978
+ [ "0" , "no-bracket-spacing" ] ,
979
+ [ "1" , "arrow-parens" ] ,
980
+ [ "1" , "prose-wrap" ] ,
981
+ [ "1" , "end-of-line" ] ,
982
+ ] ;
983
+
984
+ for opt in & prettier_flags {
985
+ let t = opt[ 0 ] ;
986
+ let keyword = opt[ 1 ] ;
987
+
988
+ if fmt_match. is_present ( & keyword) {
989
+ if t == "0" {
990
+ argv. push ( format ! ( "--{}" , keyword) ) ;
991
+ } else {
992
+ argv. push ( format ! ( "--{}" , keyword) ) ;
993
+ argv. push ( fmt_match. value_of ( keyword) . unwrap ( ) . to_string ( ) ) ;
994
+ }
995
+ }
996
+ }
997
+
889
998
DenoSubcommand :: Run
890
999
}
891
1000
( "info" , Some ( info_match) ) => {
@@ -1928,4 +2037,59 @@ mod tests {
1928
2037
assert_eq ! ( subcommand, DenoSubcommand :: Run ) ;
1929
2038
assert_eq ! ( argv, svec![ "deno" , "script.ts" ] )
1930
2039
}
2040
+
2041
+ #[ test]
2042
+ fn test_flags_from_vec_39 ( ) {
2043
+ let ( flags, subcommand, argv) = flags_from_vec ( svec ! [
2044
+ "deno" ,
2045
+ "fmt" ,
2046
+ "--print-width=100" ,
2047
+ "--tab-width=4" ,
2048
+ "--use-tabs" ,
2049
+ "--no-semi" ,
2050
+ "--single-quote" ,
2051
+ "--arrow-parens=always" ,
2052
+ "--prose-wrap=preserve" ,
2053
+ "--end-of-line=crlf" ,
2054
+ "--quote-props=preserve" ,
2055
+ "--jsx-single-quote" ,
2056
+ "--jsx-bracket-same-line" ,
2057
+ "script.ts"
2058
+ ] ) ;
2059
+ assert_eq ! (
2060
+ flags,
2061
+ DenoFlags {
2062
+ allow_write: true ,
2063
+ allow_read: true ,
2064
+ ..DenoFlags :: default ( )
2065
+ }
2066
+ ) ;
2067
+ assert_eq ! ( subcommand, DenoSubcommand :: Run ) ;
2068
+ assert_eq ! (
2069
+ argv,
2070
+ svec![
2071
+ "deno" ,
2072
+ PRETTIER_URL ,
2073
+ "script.ts" ,
2074
+ "--write" ,
2075
+ "--print-width" ,
2076
+ "100" ,
2077
+ "--tab-width" ,
2078
+ "4" ,
2079
+ "--use-tabs" ,
2080
+ "--no-semi" ,
2081
+ "--single-quote" ,
2082
+ "--quote-props" ,
2083
+ "preserve" ,
2084
+ "--jsx-single-quote" ,
2085
+ "--jsx-bracket-same-line" ,
2086
+ "--arrow-parens" ,
2087
+ "always" ,
2088
+ "--prose-wrap" ,
2089
+ "preserve" ,
2090
+ "--end-of-line" ,
2091
+ "crlf"
2092
+ ]
2093
+ ) ;
2094
+ }
1931
2095
}
0 commit comments