Skip to content

Commit c8fe761

Browse files
committed
add help
1 parent 21536c8 commit c8fe761

File tree

4 files changed

+257
-3
lines changed

4 files changed

+257
-3
lines changed

internal/execute/outputs.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,26 @@ func printEasyHelp(sys System, simpleOptions []*tsoptions.CommandLineOption) {
203203
sys.EndWrite()
204204
}
205205

206+
func printBuildHelp(sys System, buildOptions []*tsoptions.CommandLineOption) {
207+
var output []string
208+
output = append(output, getHeader(sys, diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Format()+" - "+diagnostics.Version_0.Format(core.Version()))...)
209+
output = append(output, generateSectionOptionsOutput(
210+
sys,
211+
diagnostics.BUILD_OPTIONS.Format(),
212+
core.Filter(buildOptions, func(option *tsoptions.CommandLineOption) bool {
213+
return option != &tsoptions.TscBuildOption
214+
}),
215+
false,
216+
nil, // !!! locale formatMessage(Diagnostics.Using_build_b_will_make_tsc_behave_more_like_a_build_orchestrator_than_a_compiler_This_is_used_to_trigger_building_composite_projects_which_you_can_learn_more_about_at_0, "https://aka.ms/tsc-composite-builds")),
217+
nil,
218+
)...)
219+
220+
for _, chunk := range output {
221+
fmt.Fprint(sys.Writer(), chunk)
222+
}
223+
sys.EndWrite()
224+
}
225+
206226
func generateSectionOptionsOutput(
207227
sys System,
208228
sectionName string,

internal/execute/tsc.go

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ func CommandLine(sys System, commandLineArgs []string, testing bool) CommandLine
5252
// !!! build mode
5353
switch strings.ToLower(commandLineArgs[0]) {
5454
case "-b", "--b", "-build", "--build":
55-
fmt.Fprintln(sys.Writer(), "Build mode is currently unsupported.")
56-
sys.EndWrite()
57-
return CommandLineResult{Status: ExitStatusNotImplemented}
55+
return tscBuildCompilation(sys, tsoptions.ParseBuildCommandLine(commandLineArgs, sys), testing)
5856
// case "-f":
5957
// return fmtMain(sys, commandLineArgs[1], commandLineArgs[1])
6058
}
@@ -89,6 +87,79 @@ func fmtMain(sys System, input, output string) ExitStatus {
8987
return ExitStatusSuccess
9088
}
9189

90+
func tscBuildCompilation(sys System, buildCommand *tsoptions.ParsedBuildCommandLine, testing bool) CommandLineResult {
91+
reportDiagnostic := createDiagnosticReporter(sys, buildCommand.CompilerOptions)
92+
93+
// if (buildOptions.locale) {
94+
// validateLocaleAndSetLanguage(buildOptions.locale, sys, errors);
95+
// }
96+
97+
if len(buildCommand.Errors) > 0 {
98+
for _, err := range buildCommand.Errors {
99+
reportDiagnostic(err)
100+
}
101+
return CommandLineResult{Status: ExitStatusDiagnosticsPresent_OutputsSkipped}
102+
}
103+
104+
if buildCommand.CompilerOptions.Help.IsTrue() {
105+
printVersion(sys)
106+
printBuildHelp(sys, tsoptions.BuildOpts)
107+
return CommandLineResult{Status: ExitStatusSuccess}
108+
}
109+
110+
// if (buildOptions.watch) {
111+
// if (reportWatchModeWithoutSysSupport(sys, reportDiagnostic)) return;
112+
// const buildHost = createSolutionBuilderWithWatchHost(
113+
// sys,
114+
// /*createProgram*/ undefined,
115+
// reportDiagnostic,
116+
// createBuilderStatusReporter(sys, shouldBePretty(sys, buildOptions)),
117+
// createWatchStatusReporter(sys, buildOptions),
118+
// );
119+
// buildHost.jsDocParsingMode = defaultJSDocParsingMode;
120+
// const solutionPerformance = enableSolutionPerformance(sys, buildOptions);
121+
// updateSolutionBuilderHost(sys, cb, buildHost, solutionPerformance);
122+
// const onWatchStatusChange = buildHost.onWatchStatusChange;
123+
// let reportBuildStatistics = false;
124+
// buildHost.onWatchStatusChange = (d, newLine, options, errorCount) => {
125+
// onWatchStatusChange?.(d, newLine, options, errorCount);
126+
// if (
127+
// reportBuildStatistics && (
128+
// d.code === Diagnostics.Found_0_errors_Watching_for_file_changes.code ||
129+
// d.code === Diagnostics.Found_1_error_Watching_for_file_changes.code
130+
// )
131+
// ) {
132+
// reportSolutionBuilderTimes(builder, solutionPerformance);
133+
// }
134+
// };
135+
// const builder = createSolutionBuilderWithWatch(buildHost, projects, buildOptions, watchOptions);
136+
// builder.build();
137+
// reportSolutionBuilderTimes(builder, solutionPerformance);
138+
// reportBuildStatistics = true;
139+
// return builder;
140+
// }
141+
142+
// const buildHost = createSolutionBuilderHost(
143+
// sys,
144+
// /*createProgram*/ undefined,
145+
// reportDiagnostic,
146+
// createBuilderStatusReporter(sys, shouldBePretty(sys, buildOptions)),
147+
// createReportErrorSummary(sys, buildOptions),
148+
// );
149+
// buildHost.jsDocParsingMode = defaultJSDocParsingMode;
150+
// const solutionPerformance = enableSolutionPerformance(sys, buildOptions);
151+
// updateSolutionBuilderHost(sys, cb, buildHost, solutionPerformance);
152+
// const builder = createSolutionBuilder(buildHost, projects, buildOptions);
153+
// const exitStatus = buildOptions.clean ? builder.clean() : builder.build();
154+
// reportSolutionBuilderTimes(builder, solutionPerformance);
155+
// dumpTracingLegend(); // Will no-op if there hasn't been any tracing
156+
// return sys.exit(exitStatus);
157+
158+
fmt.Fprintln(sys.Writer(), "Build mode is currently unsupported.")
159+
sys.EndWrite()
160+
return CommandLineResult{Status: ExitStatusNotImplemented}
161+
}
162+
92163
func tscCompilation(sys System, commandLine *tsoptions.ParsedCommandLine, testing bool) CommandLineResult {
93164
configFileName := ""
94165
reportDiagnostic := createDiagnosticReporter(sys, commandLine.CompilerOptions())

internal/execute/tscbuild_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package execute_test
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestBuildCommandLine(t *testing.T) {
8+
t.Parallel()
9+
testCases := []*tscInput{
10+
{
11+
subScenario: "help",
12+
files: FileMap{},
13+
commandLineArgs: []string{"--build", "--help"},
14+
},
15+
}
16+
17+
for _, test := range testCases {
18+
test.run(t, "commandLine")
19+
}
20+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
currentDirectory::/home/src/workspaces/project
2+
useCaseSensitiveFileNames::true
3+
Input::
4+
5+
tsgo --build --help
6+
ExitStatus:: Success
7+
Output::
8+
Version FakeTSVersion
9+
10+
tsc: The TypeScript Compiler - Version FakeTSVersion
11+
12+
BUILD OPTIONS
13+
14+
--help, -h
15+
Print this message.
16+
17+
--help, -?
18+
19+
20+
--watch, -w
21+
Watch input files.
22+
23+
--preserveWatchOutput
24+
Disable wiping the console in watch mode.
25+
type: boolean
26+
default: false
27+
28+
--listFiles
29+
Print all of the files read during the compilation.
30+
type: boolean
31+
default: false
32+
33+
--explainFiles
34+
Print files read during the compilation including why it was included.
35+
type: boolean
36+
default: false
37+
38+
--listEmittedFiles
39+
Print the names of emitted files after a compilation.
40+
type: boolean
41+
default: false
42+
43+
--pretty
44+
Enable color and formatting in TypeScript's output to make compiler errors easier to read.
45+
type: boolean
46+
default: true
47+
48+
--traceResolution
49+
Log paths used during the 'moduleResolution' process.
50+
type: boolean
51+
default: false
52+
53+
--diagnostics
54+
Output compiler performance information after building.
55+
type: boolean
56+
default: false
57+
58+
--extendedDiagnostics
59+
Output more detailed compiler performance information after building.
60+
type: boolean
61+
default: false
62+
63+
--generateCpuProfile
64+
Emit a v8 CPU profile of the compiler run for debugging.
65+
type: string
66+
default: profile.cpuprofile
67+
68+
--generateTrace
69+
Generates an event trace and a list of types.
70+
71+
--incremental, -i
72+
Save .tsbuildinfo files to allow for incremental compilation of projects.
73+
type: boolean
74+
default: `false`, unless `composite` is set
75+
76+
--declaration, -d
77+
Generate .d.ts files from TypeScript and JavaScript files in your project.
78+
type: boolean
79+
default: `false`, unless `composite` is set
80+
81+
--declarationMap
82+
Create sourcemaps for d.ts files.
83+
type: boolean
84+
default: false
85+
86+
--emitDeclarationOnly
87+
Only output d.ts files and not JavaScript files.
88+
type: boolean
89+
default: false
90+
91+
--sourceMap
92+
Create source map files for emitted JavaScript files.
93+
type: boolean
94+
default: false
95+
96+
--inlineSourceMap
97+
Include sourcemap files inside the emitted JavaScript.
98+
type: boolean
99+
default: false
100+
101+
--noCheck
102+
Disable full type checking (only critical parse and emit errors will be reported).
103+
type: boolean
104+
default: false
105+
106+
--noEmit
107+
Disable emitting files from a compilation.
108+
type: boolean
109+
default: false
110+
111+
--assumeChangesOnlyAffectDirectDependencies
112+
Have recompiles in projects that use 'incremental' and 'watch' mode assume that changes within a file will only affect files directly depending on it.
113+
type: boolean
114+
default: false
115+
116+
--locale
117+
Set the language of the messaging from TypeScript. This does not affect emit.
118+
119+
--quiet, -q
120+
Do not print diagnostics.
121+
122+
--singleThreaded
123+
Run in single threaded mode.
124+
125+
--pprofDir
126+
Generate pprof CPU/memory profiles to the given directory.
127+
128+
--verbose, -v
129+
Enable verbose logging.
130+
131+
--dry, -d
132+
Show what would be built (or deleted, if specified with '--clean')
133+
134+
--force, -f
135+
Build all projects, including those that appear to be up to date.
136+
137+
--clean
138+
Delete the outputs of all projects.
139+
140+
--stopBuildOnErrors
141+
Skip building downstream projects on error in upstream project.
142+
143+

0 commit comments

Comments
 (0)