@@ -62,9 +62,7 @@ namespace ts {
62
62
/* @internal */
63
63
export const libMap = createMapFromEntries ( libEntries ) ;
64
64
65
- /* @internal */
66
- export const optionDeclarations : CommandLineOption [ ] = [
67
- // CommandLine only options
65
+ const commonOptionsWithBuild : CommandLineOption [ ] = [
68
66
{
69
67
name : "help" ,
70
68
shortName : "h" ,
@@ -78,6 +76,27 @@ namespace ts {
78
76
shortName : "?" ,
79
77
type : "boolean"
80
78
} ,
79
+ {
80
+ name : "preserveWatchOutput" ,
81
+ type : "boolean" ,
82
+ showInSimplifiedHelpView : false ,
83
+ category : Diagnostics . Command_line_Options ,
84
+ description : Diagnostics . Whether_to_keep_outdated_console_output_in_watch_mode_instead_of_clearing_the_screen ,
85
+ } ,
86
+ {
87
+ name : "watch" ,
88
+ shortName : "w" ,
89
+ type : "boolean" ,
90
+ showInSimplifiedHelpView : true ,
91
+ category : Diagnostics . Command_line_Options ,
92
+ description : Diagnostics . Watch_input_files ,
93
+ } ,
94
+ ] ;
95
+
96
+ /* @internal */
97
+ export const optionDeclarations : CommandLineOption [ ] = [
98
+ // CommandLine only options
99
+ ...commonOptionsWithBuild ,
81
100
{
82
101
name : "all" ,
83
102
type : "boolean" ,
@@ -125,21 +144,6 @@ namespace ts {
125
144
category : Diagnostics . Command_line_Options ,
126
145
description : Diagnostics . Stylize_errors_and_messages_using_color_and_context_experimental
127
146
} ,
128
- {
129
- name : "preserveWatchOutput" ,
130
- type : "boolean" ,
131
- showInSimplifiedHelpView : false ,
132
- category : Diagnostics . Command_line_Options ,
133
- description : Diagnostics . Whether_to_keep_outdated_console_output_in_watch_mode_instead_of_clearing_the_screen ,
134
- } ,
135
- {
136
- name : "watch" ,
137
- shortName : "w" ,
138
- type : "boolean" ,
139
- showInSimplifiedHelpView : true ,
140
- category : Diagnostics . Command_line_Options ,
141
- description : Diagnostics . Watch_input_files ,
142
- } ,
143
147
144
148
// Basic
145
149
{
@@ -754,6 +758,38 @@ namespace ts {
754
758
}
755
759
] ;
756
760
761
+ /* @internal */
762
+ export const buildOpts : CommandLineOption [ ] = [
763
+ ...commonOptionsWithBuild ,
764
+ {
765
+ name : "verbose" ,
766
+ shortName : "v" ,
767
+ category : Diagnostics . Command_line_Options ,
768
+ description : Diagnostics . Enable_verbose_logging ,
769
+ type : "boolean"
770
+ } ,
771
+ {
772
+ name : "dry" ,
773
+ shortName : "d" ,
774
+ category : Diagnostics . Command_line_Options ,
775
+ description : Diagnostics . Show_what_would_be_built_or_deleted_if_specified_with_clean ,
776
+ type : "boolean"
777
+ } ,
778
+ {
779
+ name : "force" ,
780
+ shortName : "f" ,
781
+ category : Diagnostics . Command_line_Options ,
782
+ description : Diagnostics . Build_all_projects_including_those_that_appear_to_be_up_to_date ,
783
+ type : "boolean"
784
+ } ,
785
+ {
786
+ name : "clean" ,
787
+ category : Diagnostics . Command_line_Options ,
788
+ description : Diagnostics . Delete_the_outputs_of_all_projects ,
789
+ type : "boolean"
790
+ }
791
+ ] ;
792
+
757
793
/* @internal */
758
794
export const typeAcquisitionDeclarations : CommandLineOption [ ] = [
759
795
{
@@ -997,6 +1033,58 @@ namespace ts {
997
1033
return optionNameMap . get ( optionName ) ;
998
1034
}
999
1035
1036
+ /*@internal */
1037
+ export interface ParsedBuildCommand {
1038
+ buildOptions : BuildOptions ;
1039
+ projects : string [ ] ;
1040
+ errors : ReadonlyArray < Diagnostic > ;
1041
+ }
1042
+
1043
+ /*@internal */
1044
+ export function parseBuildCommand ( args : string [ ] ) : ParsedBuildCommand {
1045
+ let buildOptionNameMap : OptionNameMap | undefined ;
1046
+ const returnBuildOptionNameMap = ( ) => ( buildOptionNameMap || ( buildOptionNameMap = createOptionNameMap ( buildOpts ) ) ) ;
1047
+
1048
+ const buildOptions : BuildOptions = { } ;
1049
+ const projects : string [ ] = [ ] ;
1050
+ let errors : Diagnostic [ ] | undefined ;
1051
+ for ( const arg of args ) {
1052
+ if ( arg . charCodeAt ( 0 ) === CharacterCodes . minus ) {
1053
+ const opt = getOptionDeclarationFromName ( returnBuildOptionNameMap , arg . slice ( arg . charCodeAt ( 1 ) === CharacterCodes . minus ? 2 : 1 ) , /*allowShort*/ true ) ;
1054
+ if ( opt ) {
1055
+ buildOptions [ opt . name as keyof BuildOptions ] = true ;
1056
+ }
1057
+ else {
1058
+ ( errors || ( errors = [ ] ) ) . push ( createCompilerDiagnostic ( Diagnostics . Unknown_build_option_0 , arg ) ) ;
1059
+ }
1060
+ }
1061
+ else {
1062
+ // Not a flag, parse as filename
1063
+ projects . push ( arg ) ;
1064
+ }
1065
+ }
1066
+
1067
+ if ( projects . length === 0 ) {
1068
+ // tsc -b invoked with no extra arguments; act as if invoked with "tsc -b ."
1069
+ projects . push ( "." ) ;
1070
+ }
1071
+
1072
+ // Nonsensical combinations
1073
+ if ( buildOptions . clean && buildOptions . force ) {
1074
+ ( errors || ( errors = [ ] ) ) . push ( createCompilerDiagnostic ( Diagnostics . Options_0_and_1_cannot_be_combined , "clean" , "force" ) ) ;
1075
+ }
1076
+ if ( buildOptions . clean && buildOptions . verbose ) {
1077
+ ( errors || ( errors = [ ] ) ) . push ( createCompilerDiagnostic ( Diagnostics . Options_0_and_1_cannot_be_combined , "clean" , "verbose" ) ) ;
1078
+ }
1079
+ if ( buildOptions . clean && buildOptions . watch ) {
1080
+ ( errors || ( errors = [ ] ) ) . push ( createCompilerDiagnostic ( Diagnostics . Options_0_and_1_cannot_be_combined , "clean" , "watch" ) ) ;
1081
+ }
1082
+ if ( buildOptions . watch && buildOptions . dry ) {
1083
+ ( errors || ( errors = [ ] ) ) . push ( createCompilerDiagnostic ( Diagnostics . Options_0_and_1_cannot_be_combined , "watch" , "dry" ) ) ;
1084
+ }
1085
+
1086
+ return { buildOptions, projects, errors : errors || emptyArray } ;
1087
+ }
1000
1088
1001
1089
function getDiagnosticText ( _message : DiagnosticMessage , ..._args : any [ ] ) : string {
1002
1090
const diagnostic = createCompilerDiagnostic . apply ( undefined , arguments ) ;
0 commit comments